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