1+ name : Merge into master - Build Workflow
2+
3+ # if statements modified to avoid: https://stackoverflow.com/questions/69354003/github-action-job-fire-when-previous-job-skipped
4+
5+ on :
6+ workflow_call :
7+ inputs :
8+ os :
9+ required : true
10+ type : string
11+ arch :
12+ required : true
13+ type : string
14+
15+ permissions :
16+ contents : read
17+
18+ env :
19+ REGISTRY : ghcr.io
20+ DOCKERIMAGE : ghcr.io/algebraic-programming/taskr/buildenv
21+
22+ defaults :
23+ run :
24+ shell : bash
25+
26+ jobs :
27+ check-dockerfile-modifications-with-last-commit :
28+ runs-on : ${{ inputs.os }}
29+ outputs :
30+ dockerfile-modified : ${{ steps.check-dockerfile.outputs.dockerfile-modified }}
31+ steps :
32+ - name : Checkout repository
33+ uses : actions/checkout@v4
34+ with :
35+ fetch-depth : 2
36+
37+ # Check the PR diff using the current branch and the base branch of the PR
38+ - name : Run git diff
39+ run : |
40+ git diff --name-only HEAD^..HEAD > ${{ runner.temp }}/diff.txt
41+
42+ - name : Check if Dockerfile was modified
43+ id : check-dockerfile
44+ env :
45+ MODIFIED_FILES_PATH : ${{ runner.temp }}/diff.txt
46+ run : |
47+ cat $MODIFIED_FILES_PATH
48+ if cat $MODIFIED_FILES_PATH | grep -q 'buildenv/Dockerfile' ; then
49+ echo "Dockerfile was modified"
50+ echo "dockerfile-modified=true" >> $GITHUB_OUTPUT
51+ else
52+ echo "Dockerfile was not modified"
53+ echo "dockerfile-modified=false" >> $GITHUB_OUTPUT
54+ fi
55+
56+ build-image :
57+ runs-on : ${{ inputs.os }}
58+ needs : [check-dockerfile-modifications-with-last-commit]
59+ if : ${{ needs.check-dockerfile-modifications-with-last-commit.outputs.dockerfile-modified == 'true' }}
60+ permissions :
61+ contents : read
62+ packages : write
63+ attestations : write
64+ id-token : write
65+
66+ steps :
67+ - name : Checkout repository
68+ uses : actions/checkout@v4
69+
70+ - name : Log in to the Container registry
71+ uses : docker/login-action@v3
72+ with :
73+ registry : ${{ env.REGISTRY }}
74+ username : ${{ github.repository_owner }}
75+ password : ${{ secrets.GITHUB_TOKEN }}
76+
77+ - name : Set up QEMU
78+ uses : docker/setup-qemu-action@v3
79+
80+ - name : Set up Docker Buildx
81+ uses : docker/setup-buildx-action@v3
82+
83+ - name : Docker metadata
84+ id : dockermeta
85+ uses : docker/metadata-action@v4
86+ with :
87+ images : ${{ env.DOCKERIMAGE }}
88+ tags : ${{ inputs.arch }}-latest
89+
90+ - name : Build and push docker image
91+ uses : docker/build-push-action@v6
92+ with :
93+ context : " {{defaultContext}}:.build-tools/containers/buildenv"
94+ push : true
95+ tags : ${{ steps.dockermeta.outputs.tags }}
96+ labels : ${{ steps.dockermeta.outputs.labels }}
97+ build-args : ARCH=${{ inputs.arch }}
98+ cache-from : type=gha
99+ cache-to : type=gha,mode=max
0 commit comments