Skip to content

Commit 8a50721

Browse files
authored
Merge pull request #114 from pi-hole/fix/fork
Don't push images when build from forks
2 parents 7394f99 + c2234e1 commit 8a50721

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

.github/workflows/ftl-build.yml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,7 @@ on:
33
push:
44
branches:
55
- '**'
6-
paths:
7-
- 'ftl-build/**'
8-
- '.github/workflows/ftl-build.yml'
9-
tags:
10-
- '**'
11-
# Only run on push events to the main repository (not from forks)
126
pull_request:
13-
types: [opened, synchronize, reopened]
14-
paths:
15-
- 'ftl-build/**'
16-
- '.github/workflows/ftl-build.yml'
17-
# Only run on PRs from forks
18-
branches:
19-
- '**'
207
workflow_dispatch:
218
schedule:
229
# 1:30am UTC every Sunday, has no particular significance
@@ -27,10 +14,28 @@ env:
2714
GITHUB_REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/ftl-build
2815

2916
jobs:
30-
build-and-test:
17+
smoke-tests:
3118
if: |
32-
(github.event_name == 'push' && github.repository == 'pi-hole/docker-base-images') ||
33-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
19+
github.event_name == 'push'
20+
|| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
21+
|| github.event_name == 'workflow_dispatch'
22+
|| github.event_name == 'schedule'
23+
24+
outputs:
25+
DO_DEPLOY: ${{ steps.variables.outputs.DO_DEPLOY }}
26+
runs-on: ubuntu-latest
27+
steps:
28+
-
29+
name: "Calculate required variables"
30+
id: variables
31+
run: |
32+
echo "DO_DEPLOY=${{ github.event_name != 'pull_request' && secrets.DOCKERHUB_PASS != '' && github.actor != 'dependabot[bot]' }}" >> $GITHUB_OUTPUT
33+
34+
35+
build-and-test:
36+
needs: smoke-tests
37+
env:
38+
DO_DEPLOY: ${{ needs.smoke-tests.outputs.DO_DEPLOY }}
3439
strategy:
3540
fail-fast: false
3641
matrix:
@@ -71,6 +76,7 @@ jobs:
7176
type=ref,event=branch,enable=${{ github.event_name != 'schedule' }}
7277
-
7378
name: Login to Docker Hub
79+
if: env.DO_DEPLOY == 'true'
7480
uses: docker/login-action@v2
7581
with:
7682
registry: docker.io
@@ -79,6 +85,7 @@ jobs:
7985

8086
-
8187
name: Login to GitHub Container Registry
88+
if: env.DO_DEPLOY == 'true'
8289
uses: docker/login-action@v2
8390
with:
8491
registry: ghcr.io
@@ -106,7 +113,7 @@ jobs:
106113
labels: ${{ steps.meta.outputs.labels }}
107114
-
108115
name: Push builder target and push by digest
109-
if: github.event_name != 'pull_request'
116+
if: env.DO_DEPLOY == 'true'
110117
id: build_docker
111118
uses: docker/build-push-action@v6
112119
with:
@@ -120,14 +127,14 @@ jobs:
120127
type=image,name=${{ env.GITHUB_REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
121128
-
122129
name: Export digests
123-
if: github.event_name != 'pull_request'
130+
if: env.DO_DEPLOY == 'true'
124131
run: |
125132
mkdir -p /tmp/digests/
126133
digest_docker="${{ steps.build_docker.outputs.digest }}"
127134
touch "/tmp/digests/${digest_docker#sha256:}"
128135
-
129136
name: Upload digest
130-
if: github.event_name != 'pull_request'
137+
if: env.DO_DEPLOY == 'true'
131138
uses: actions/upload-artifact@v4
132139
with:
133140
name: digests-${{ env.PLATFORM_PAIR }}
@@ -139,10 +146,11 @@ jobs:
139146
# If we would push immediately above, the individual runners would overwrite each other's images
140147
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
141148
merge-and-deploy:
142-
if: github.event_name != 'pull_request'
149+
if: needs.smoke-tests.outputs.DO_DEPLOY == 'true'
143150
runs-on: ubuntu-latest
144151
needs:
145152
- build-and-test
153+
- smoke-tests
146154
steps:
147155
-
148156
name: Checkout Repo

0 commit comments

Comments
 (0)