Skip to content

Commit ed0bef2

Browse files
authored
Merge pull request #53 from mithro/fix/use-github-token-for-ghcr
fix: use GITHUB_TOKEN instead of GHA_CR_TOKEN for GHCR authentication
2 parents b8eee7e + 29480f3 commit ed0bef2

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

.github/workflows/publish-docker-image.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
name: Push Docker image to GitHub Packages
2727
runs-on: ubuntu-latest
2828

29+
permissions:
30+
contents: read
31+
packages: write
32+
2933
# Run a local registry
3034
services:
3135
registry:
@@ -51,8 +55,6 @@ jobs:
5155
- name: Push To
5256
id: push_to
5357
shell: python
54-
env:
55-
HAS_GHA_CR_TOKEN: ${{ secrets.GHA_CR_TOKEN != '' }}
5658
run: |
5759
import os
5860
@@ -63,22 +65,25 @@ jobs:
6365
6466
gh_repo = g('GITHUB_REPOSITORY')
6567
gh_event = g('GITHUB_EVENT_NAME')
66-
has_cr_token = g('HAS_GHA_CR_TOKEN')
6768
6869
i = []
6970
7071
print("Adding local service.")
7172
i.append("localhost:5000/"+gh_repo)
7273
73-
if gh_event == 'push' and has_cr_token == 'true':
74+
# Use GITHUB_TOKEN for authentication (always available)
75+
if gh_event == 'push':
7476
print("Adding GitHub Container Repository (ghcr.io)")
7577
i.append("ghcr.io/{}/image".format(gh_repo))
7678
else:
77-
print("Skipping GitHub Container Repository (ghcr.io)")
79+
print("Skipping GitHub Container Repository (ghcr.io) for non-push events")
7880
7981
l = ",".join(i)
8082
print("Final locations:", repr(l))
81-
print("::set-output name=images::{}".format(l))
83+
84+
# Use environment file instead of deprecated set-output
85+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
86+
f.write("images={}\n".format(l))
8287
8388
- name: Docker meta
8489
id: docker_meta
@@ -97,11 +102,11 @@ jobs:
97102

98103
- name: Login to GHCR
99104
if: ${{ contains(steps.push_to.outputs.images, 'ghcr.io') }}
100-
uses: docker/login-action@v1
105+
uses: docker/login-action@v3
101106
with:
102-
username: ${{ github.actor }}
103-
password: ${{ secrets.GHA_CR_TOKEN }}
104107
registry: ghcr.io
108+
username: ${{ github.actor }}
109+
password: ${{ secrets.GITHUB_TOKEN }}
105110

106111
# - name: Login to local registry
107112
# uses: docker/login-action@v1

0 commit comments

Comments
 (0)