-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest-twostep-container-build.yml
More file actions
130 lines (112 loc) · 4.06 KB
/
test-twostep-container-build.yml
File metadata and controls
130 lines (112 loc) · 4.06 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Test twostep-container-build
on:
pull_request:
branches: [main]
paths:
- '.github/workflows/test-twostep-container-build.yml'
- 'twostep-container-build/action.yml'
push:
branches: [main]
paths:
- '.github/workflows/test-twostep-container-build.yml'
- 'twostep-container-build/action.yml'
workflow_dispatch:
jobs:
# This job is used to build and push the image.
test-no-args:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: Checkout code
- name: Two-step build
uses: ./twostep-container-build
id: twostep-1
with:
registry: ghcr.io/
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
container-file-1: twostep-container-build/examples/Containerfile.dependencies
container-file-2: twostep-container-build/examples/Containerfile
first-step-cache-key: no-args-${{ hashFiles('twostep-container-build/examples/Containerfile.dependencies') }}
image: cdcgov/cfa-actions
# This job is used to rerun the first step of the build
# to ensure that caching is working as expected.
test-no-args-rerun:
runs-on: ubuntu-latest
needs: test-no-args
permissions:
contents: read
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: Checkout code
- name: Two-step build
uses: ./twostep-container-build
id: twostep-1
with:
registry: ghcr.io/
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
container-file-1: twostep-container-build/examples/Containerfile.dependencies
container-file-2: twostep-container-build/examples/Containerfile
first-step-cache-key: no-args-${{ hashFiles('twostep-container-build/examples/Containerfile.dependencies') }}
image: cdcgov/cfa-actions
push-image-1: false
push-image-2: false
- name: Check the output
run: |
if [ "${{ steps.twostep-1.outputs.summary }}" == "cached" ]; then
echo "Using the cached version (OK)"
else
echo "This was supposed to use the cache version"
exit 1
fi
# This job is used to test the action with arguments.
# Caching should also be triggered here.
test-with-args:
runs-on: ubuntu-latest
needs: test-no-args
permissions:
contents: read
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: Checkout code
# Testing passing arguments
- name: Two-step build with args
id: twostep-2
uses: ./twostep-container-build
with:
registry: ghcr.io/
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
container-file-1: twostep-container-build/examples/Containerfile.dependencies
container-file-2: twostep-container-build/examples/Containerfile
first-step-cache-key: with-args-${{ hashFiles('twostep-container-build/examples/Containerfile.dependencies') }}
image: cdcgov/cfa-actions
build-args-2: |
GH_SHA=${{ github.sha }}
push-image-1: false
push-image-2: false
- name: Listing the labels from the image
run: |
docker inspect ghcr.io/cdcgov/cfa-actions:${{ steps.twostep-2.outputs.tag }} \
--format='{{ index .Config.Labels "GH_SHA" }}' > _${{ github.sha }}_labels.json
if [ "$(cat _${{ github.sha }}_labels.json)" != "${{ github.sha }}" ]; then
echo "The argument GH_SHA does not match the expected value."
exit 1
fi
- name: Check the output
run: |
if [ "${{ steps.twostep-2.outputs.summary }}" == "rebuilt" ]; then
echo "Using a re-built version (OK)"
else
echo "This was supposed to use the cache version"
exit 1
fi