Skip to content

Commit 877bb35

Browse files
committed
fix: update GitHub Actions to skip Docker builds for forked repositories
1 parent dcb9592 commit 877bb35

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ jobs:
8787
fi
8888
done
8989
90+
echo "HAS_DOCKER_CHANGES=$HAS_DOCKER_CHANGES" >> $GITHUB_ENV
91+
9092
if [[ "$HAS_DOCKER_CHANGES" == "false" ]]; then
9193
echo "No Dockerfile or context directory changes. Skipping Docker image build and push steps."
9294
echo "Changed files: ${{ env.files }}"
@@ -103,7 +105,7 @@ jobs:
103105
-
104106
name: Login to GitHub Container Registry
105107
# This step logs in to GHCR
106-
if: contains(env.files, 'Dockerfile')
108+
if: env.HAS_DOCKER_CHANGES == 'true' && env.IS_FORK != 'true'
107109
uses: docker/login-action@v3
108110
with:
109111
registry: ghcr.io
@@ -133,7 +135,7 @@ jobs:
133135

134136
- name: Build and push a simple jenkins controller
135137
# This step builds and pushes a simple Jenkins controller
136-
if: contains(env.files, 'dockerfiles/Dockerfile') || contains(env.files, 'dockerfiles/')
138+
if: (contains(env.files, 'dockerfiles/Dockerfile') || contains(env.files, 'dockerfiles/')) && env.IS_FORK != 'true'
137139
uses: docker/build-push-action@v6
138140
with:
139141
context: ./dockerfiles
@@ -143,7 +145,7 @@ jobs:
143145

144146
- name: Build and push the jenkins agent for maven tutorial
145147
# This step builds and pushes the Jenkins agent for the Maven tutorial
146-
if: contains(env.files, 'dockerfiles/maven/Dockerfile')
148+
if: contains(env.files, 'dockerfiles/maven/Dockerfile') && env.IS_FORK != 'true'
147149
uses: docker/build-push-action@v6
148150
with:
149151
context: ./dockerfiles/maven
@@ -153,7 +155,7 @@ jobs:
153155

154156
- name: Build and push the jenkins agent for python tutorial
155157
# This step builds and pushes the Jenkins agent for the Python tutorial
156-
if: contains(env.files, 'dockerfiles/python/Dockerfile')
158+
if: contains(env.files, 'dockerfiles/python/Dockerfile') && env.IS_FORK != 'true'
157159
uses: docker/build-push-action@v6
158160
with:
159161
context: ./dockerfiles/python
@@ -163,7 +165,7 @@ jobs:
163165

164166
- name: Build and push the jenkins agent for node tutorial
165167
# This step builds and pushes the Jenkins agent for the Node.js tutorial
166-
if: contains(env.files, 'dockerfiles/node/Dockerfile')
168+
if: contains(env.files, 'dockerfiles/node/Dockerfile') && env.IS_FORK != 'true'
167169
uses: docker/build-push-action@v6
168170
with:
169171
context: ./dockerfiles/node
@@ -173,7 +175,7 @@ jobs:
173175

174176
- name: Build and push the jenkins agent for the sidekick container
175177
# This step builds and pushes the Jenkins agent for the sidekick container
176-
if: contains(env.files, 'dockerfiles/sidekick/Dockerfile')
178+
if: contains(env.files, 'dockerfiles/sidekick/Dockerfile') && env.IS_FORK != 'true'
177179
uses: docker/build-push-action@v6
178180
with:
179181
context: ./dockerfiles/sidekick
@@ -183,7 +185,7 @@ jobs:
183185

184186
- name: Build and push the jenkins agent for the agent-finding container
185187
# This step builds and pushes the Jenkins agent for the agent-finding container
186-
if: contains(env.files, 'dockerfiles/agent-discovery/Dockerfile')
188+
if: contains(env.files, 'dockerfiles/agent-discovery/Dockerfile') && env.IS_FORK != 'true'
187189
uses: docker/build-push-action@v6
188190
with:
189191
context: ./dockerfiles/agent-discovery/
@@ -193,7 +195,7 @@ jobs:
193195

194196
- name: Build and push the jenkins agent for multi-branch controller
195197
# This step builds and pushes the Jenkins agent for the multi-branch controller
196-
if: contains(env.files, 'dockerfiles/multi/Dockerfile')
198+
if: contains(env.files, 'dockerfiles/multi/Dockerfile') && env.IS_FORK != 'true'
197199
uses: docker/build-push-action@v6
198200
with:
199201
context: ./dockerfiles/multi
@@ -203,7 +205,7 @@ jobs:
203205

204206
- name: Build and push the jenkins agent for Android
205207
# This step builds and pushes the Jenkins agent for Android
206-
if: contains(env.files, 'dockerfiles/android/Dockerfile')
208+
if: contains(env.files, 'dockerfiles/android/Dockerfile') && env.IS_FORK != 'true'
207209
uses: docker/build-push-action@v6
208210
with:
209211
context: ./dockerfiles/android
@@ -213,7 +215,7 @@ jobs:
213215

214216
- name: Build and push the jenkins agent for golang tutorial
215217
# This step builds and pushes the Jenkins agent for the Golang tutorial
216-
if: contains(env.files, 'dockerfiles/golang/Dockerfile')
218+
if: contains(env.files, 'dockerfiles/golang/Dockerfile') && env.IS_FORK != 'true'
217219
uses: docker/build-push-action@v6
218220
with:
219221
context: ./dockerfiles/golang
@@ -223,17 +225,17 @@ jobs:
223225

224226
- name: Build and push the jenkins agent for cpp tutorial
225227
# This step builds and pushes the Jenkins agent for the C++ tutorial
226-
if: contains(env.files, 'dockerfiles/cpp/Dockerfile')
228+
if: contains(env.files, 'dockerfiles/cpp/Dockerfile') && env.IS_FORK != 'true'
227229
uses: docker/build-push-action@v6
228230
with:
229231
context: ./dockerfiles/cpp
230232
platforms: linux/amd64, linux/aarch64
231233
push: true
232234
tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:cpp_${{ env.BRANCH }}
233-
235+
234236
- name: Build and push the jenkins agent for dotnet tutorial
235-
# This step builds and pushes the Jenkins agent for the C++ tutorial
236-
if: contains(env.files, 'dockerfiles/dotnet/Dockerfile')
237+
# This step builds and pushes the Jenkins agent for the .NET tutorial
238+
if: contains(env.files, 'dockerfiles/dotnet/Dockerfile') && env.IS_FORK != 'true'
237239
uses: docker/build-push-action@v6
238240
with:
239241
context: ./dockerfiles/dotnet

0 commit comments

Comments
 (0)