Skip to content

Commit

Permalink
Add support for GHCR.io
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanTAllen committed Aug 29, 2023
1 parent 7e894db commit 83cff7e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .release-notes/add-ghcr-io-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Add support for GHCR.io

We've added support for an additional registry to our two commands that were registry specific.

`update-action-to-use-docker-image-to-run-action` now takes an environment variable `REGISTRY` to indicate which registry to use.

`update-version-in-README` now support changing docker urls for both the default (none) and for urls targeting `ghcr.io`.

See the README for updated usage instructions for `update-action-to-use-docker-image-to-run-action`. You don't need to make any changes for related to the `update-version-in-README` change.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,20 @@ An example step config:
GIT_USER_EMAIL: "[email protected]"
```

N.B. currently limited to supporting images that are uploaded to Docker Hub.
To use a registry other than DockerHub, add the registry in the REGISTRY environment variable. For example to use GitHub Container Registry:

```yml
- name: Set action to run using prebuilt image
uses: ponylang/[email protected]
with:
entrypoint: update-action-to-use-docker-image-to-run-action
env:
GIT_USER_NAME: "Ponylang Main Bot"
GIT_USER_EMAIL: "[email protected]"
REGISTRY: "ghcr.io"
```

Current valid entries for `REGISTRY` are '', 'docker.io', and 'ghcr.io'.

### update-action-to-use-dockerfile-to-run-action

Expand Down Expand Up @@ -604,6 +617,7 @@ Can update the following version patterns:
- corral add github.com/REPO.git --version \d+\.\d+\.\d+
- REPO@\d+\.\d+\.\d+ <== standard action url
- docker://REPO:\d+\.\d+\.\d+ <== docker hub url
- docker://ghcr.io/REPO:\d+\.\d+\.\d+ <== github container registry url

- **Must** be triggered by an `announce-X.Y.Z` tag push.
- **Must** be run in a job after `actions/checkout`
Expand Down
20 changes: 18 additions & 2 deletions scripts/update-action-to-use-docker-image-to-run-action
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,27 @@ git.config('--global', 'user.email', os.environ['GIT_USER_EMAIL'])
git.config('--global', 'branch.autosetuprebase', 'always')
git.config('--global', '--add', 'safe.directory', os.environ['GITHUB_WORKSPACE'])

# open README and update with new version
# open action.yml and update with new version. using the denoted registry if
# one is given
registry = ''

if 'REGISTRY' in os.environ:
registry = os.environ['REGISTRY']
match registry:
case '':
registry = registry
case 'docker.io':
registry = registry + '/'
case 'ghcr.io':
registry = registry + '/'
case _:
print(ERROR + registry + " isn't a supported REGISTRY. Exiting." + ENDC)
sys.exit(1)

print(INFO + "Switching to prebuilt image as runner in action.yml" + ENDC)
with open('action.yml', 'r+') as action_yml:
text = yaml.safe_load(action_yml)
text['runs']['image'] = f'docker://{repository}:{version}'
text['runs']['image'] = f'docker://{registry}{repository}:{version}'
action_yml.seek(0)
yaml.dump(text, action_yml)
action_yml.truncate()
Expand Down
2 changes: 2 additions & 0 deletions scripts/update-version-in-README
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ git.config('--global', '--add', 'safe.directory', os.environ['GITHUB_WORKSPACE']
subs = [
(fr'docker://{repository}:\d+\.\d+\.\d+',
f'docker://{repository}:{version}'),
(fr'docker://ghcr.io/{repository}:\d+\.\d+\.\d+',
f'docker://ghcr.io/{repository}:{version}'),
(fr'{repository}@\d+\.\d+\.\d+',
f'{repository}@{version}'),
(fr'corral add github.com/{repository}.git -(-version|v) \d+\.\d+\.\d+',
Expand Down

0 comments on commit 83cff7e

Please sign in to comment.