-
Notifications
You must be signed in to change notification settings - Fork 8
62 lines (57 loc) · 1.72 KB
/
test_dockerfiles.yaml
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
name: Dockerfile tests
on:
push:
branches:
- main
pull_request:
paths:
- '**/Dockerfile'
schedule:
- cron: '23 2 * * 0'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
define_changed_dockerfile_matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed-dockerfiles.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v4
-
name: Get Changed Dockerfiles
id: changed-dockerfiles
uses: tj-actions/changed-files@v44
with:
matrix: true
files: '**Dockerfile'
define_all_dockerfile_matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.all-dockerfiles.outputs.files}}
steps:
- uses: actions/checkout@v4
-
name: Get all Dockerfiles
id: all-dockerfiles
run: |
find . -name "Dockerfile" | jq -Rs '{"files": split("\n") | map(select(. != ""))}' >> "$GITHUB_OUTPUT"
test_builds:
runs-on: ubuntu-latest
needs: [define_changed_dockerfile_matrix, define_all_dockerfile_matrix]
strategy:
matrix:
dockerfile: ${{ github.ref != 'refs/heads/main' && fromJSON(needs.define_changed_dockerfile_matrix.outputs.matrix) || fromJSON(needs.define_all_dockerfile_matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
-
name: Get context
id: get-context
run: |
echo "context=$(dirname ${{ matrix.dockerfile }})" >> $GITHUB_OUTPUT
-
name: Build
uses: docker/build-push-action@v6
with:
context: ${{ get-context.outputs.context }}
file: ${{ matrix.dockerfile }}