-
-
Notifications
You must be signed in to change notification settings - Fork 102
73 lines (64 loc) · 2.73 KB
/
build_test_containers.yml
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
name: Docker
on:
pull_request:
paths:
- .github/workflows/build_test_containers.yml
- ansible/docker/test/Dockerfile*
branches:
- master
push:
paths:
- .github/workflows/build_test_containers.yml
- ansible/docker/test/Dockerfile*
branches:
- master
permissions:
contents: read
packages: write
jobs:
generate-matrix:
name: Generate Matrix
runs-on: ubuntu-latest
if: github.repository_owner == 'adoptium'
outputs:
matrix: ${{ steps.generate_matrix.outputs.matrix }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
# Get list of changed files in ansible/docker/test/Dockerfile*
- name: Get list of changed Dockerfiles
id: get_changed_files
run: |
if [ ${{ github.event_name }} == "push" ]; then
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep ansible/docker/test/Dockerfile)
else
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep ansible/docker/test/Dockerfile)
fi
echo "changed_files=$changed_files" >> "$GITHUB_ENV"
# Generate matrix
- name: Generate matrix
id: generate_matrix
run: |
matrix=$(jq -n --arg files "${changed_files}" '{
"include": ($files | split("\n") | map(select(length > 0) | {dockerfile: .}))
}')
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
build-dockerfiles:
name: Build Dockerfiles
runs-on: ubuntu-latest
needs: generate-matrix
strategy:
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
# Generate tag name based on the Dockerfile name
- name: Set tag name
run: echo "TAG_NAME=$(basename ${{ matrix.dockerfile }} | cut -d'.' -f2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build Dockerfile
run: docker build -t ghcr.io/${{ github.repository_owner }}/test-containers:$TAG_NAME -f ${{ matrix.dockerfile }} .
- name: Push Dockerfile to ghcr.io
if: github.event_name == 'push'
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
docker push ghcr.io/${{ github.repository_owner }}/test-containers:$TAG_NAME