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 :
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