Skip to content

Commit adb7bb6

Browse files
committed
fix: skip Docker login and push steps for fork PRs
Add IS_FORK check to all Docker-related steps to prevent failures when running from fork PRs. GitHub doesn't provide GHCR_TOKEN secret to fork PRs for security reasons, causing login and push steps to fail. Changes: - Skip GHCR login when IS_FORK == 'true' - Skip all build-and-push steps when IS_FORK == 'true' This allows fork PRs to run successfully without attempting to push images to the upstream registry.
1 parent 6d42cec commit adb7bb6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

.github/workflows/github-docker-registry-push.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
-
9090
name: Login to GitHub Container Registry
9191
# This step logs in to GHCR
92-
if: contains(env.files, 'Dockerfile')
92+
if: contains(env.files, 'Dockerfile') && env.IS_FORK == 'false'
9393
uses: docker/login-action@v3
9494
with:
9595
registry: ghcr.io
@@ -119,7 +119,7 @@ jobs:
119119

120120
- name: Build and push a simple jenkins controller
121121
# This step builds and pushes a simple Jenkins controller
122-
if: contains(env.files, 'dockerfiles/Dockerfile') || contains(env.files, 'dockerfiles/')
122+
if: (contains(env.files, 'dockerfiles/Dockerfile') || contains(env.files, 'dockerfiles/')) && env.IS_FORK == 'false'
123123
uses: docker/build-push-action@v6
124124
with:
125125
context: ./dockerfiles
@@ -129,7 +129,7 @@ jobs:
129129

130130
- name: Build and push the jenkins agent for maven tutorial
131131
# This step builds and pushes the Jenkins agent for the Maven tutorial
132-
if: contains(env.files, 'dockerfiles/maven/Dockerfile')
132+
if: contains(env.files, 'dockerfiles/maven/Dockerfile') && env.IS_FORK == 'false'
133133
uses: docker/build-push-action@v6
134134
with:
135135
context: ./dockerfiles/maven
@@ -139,7 +139,7 @@ jobs:
139139

140140
- name: Build and push the jenkins agent for python tutorial
141141
# This step builds and pushes the Jenkins agent for the Python tutorial
142-
if: contains(env.files, 'dockerfiles/python/Dockerfile')
142+
if: contains(env.files, 'dockerfiles/python/Dockerfile') && env.IS_FORK == 'false'
143143
uses: docker/build-push-action@v6
144144
with:
145145
context: ./dockerfiles/python
@@ -149,7 +149,7 @@ jobs:
149149

150150
- name: Build and push the jenkins agent for node tutorial
151151
# This step builds and pushes the Jenkins agent for the Node.js tutorial
152-
if: contains(env.files, 'dockerfiles/node/Dockerfile')
152+
if: contains(env.files, 'dockerfiles/node/Dockerfile') && env.IS_FORK == 'false'
153153
uses: docker/build-push-action@v6
154154
with:
155155
context: ./dockerfiles/node
@@ -159,7 +159,7 @@ jobs:
159159

160160
- name: Build and push the jenkins agent for the sidekick container
161161
# This step builds and pushes the Jenkins agent for the sidekick container
162-
if: contains(env.files, 'dockerfiles/sidekick/Dockerfile')
162+
if: contains(env.files, 'dockerfiles/sidekick/Dockerfile') && env.IS_FORK == 'false'
163163
uses: docker/build-push-action@v6
164164
with:
165165
context: ./dockerfiles/sidekick
@@ -169,7 +169,7 @@ jobs:
169169

170170
- name: Build and push the jenkins agent for the agent-finding container
171171
# This step builds and pushes the Jenkins agent for the agent-finding container
172-
if: contains(env.files, 'dockerfiles/agent-discovery/Dockerfile')
172+
if: contains(env.files, 'dockerfiles/agent-discovery/Dockerfile') && env.IS_FORK == 'false'
173173
uses: docker/build-push-action@v6
174174
with:
175175
context: ./dockerfiles/agent-discovery/
@@ -179,7 +179,7 @@ jobs:
179179

180180
- name: Build and push the jenkins agent for multi-branch controller
181181
# This step builds and pushes the Jenkins agent for the multi-branch controller
182-
if: contains(env.files, 'dockerfiles/multi/Dockerfile')
182+
if: contains(env.files, 'dockerfiles/multi/Dockerfile') && env.IS_FORK == 'false'
183183
uses: docker/build-push-action@v6
184184
with:
185185
context: ./dockerfiles/multi
@@ -189,7 +189,7 @@ jobs:
189189

190190
- name: Build and push the jenkins agent for Android
191191
# This step builds and pushes the Jenkins agent for Android
192-
if: contains(env.files, 'dockerfiles/android/Dockerfile')
192+
if: contains(env.files, 'dockerfiles/android/Dockerfile') && env.IS_FORK == 'false'
193193
uses: docker/build-push-action@v6
194194
with:
195195
context: ./dockerfiles/android
@@ -199,7 +199,7 @@ jobs:
199199

200200
- name: Build and push the jenkins agent for golang tutorial
201201
# This step builds and pushes the Jenkins agent for the Golang tutorial
202-
if: contains(env.files, 'dockerfiles/golang/Dockerfile')
202+
if: contains(env.files, 'dockerfiles/golang/Dockerfile') && env.IS_FORK == 'false'
203203
uses: docker/build-push-action@v6
204204
with:
205205
context: ./dockerfiles/golang
@@ -209,7 +209,7 @@ jobs:
209209

210210
- name: Build and push the jenkins agent for cpp tutorial
211211
# This step builds and pushes the Jenkins agent for the C++ tutorial
212-
if: contains(env.files, 'dockerfiles/cpp/Dockerfile')
212+
if: contains(env.files, 'dockerfiles/cpp/Dockerfile') && env.IS_FORK == 'false'
213213
uses: docker/build-push-action@v6
214214
with:
215215
context: ./dockerfiles/cpp
@@ -219,7 +219,7 @@ jobs:
219219

220220
- name: Build and push the jenkins agent for dotnet tutorial
221221
# This step builds and pushes the Jenkins agent for the C++ tutorial
222-
if: contains(env.files, 'dockerfiles/dotnet/Dockerfile')
222+
if: contains(env.files, 'dockerfiles/dotnet/Dockerfile') && env.IS_FORK == 'false'
223223
uses: docker/build-push-action@v6
224224
with:
225225
context: ./dockerfiles/dotnet

0 commit comments

Comments
 (0)