Skip to content

Commit 01c4ff8

Browse files
authored
Merge pull request #53 from satackey/use-matrix-for-testing-readme
Update CI
2 parents 8c2255c + 2f147f2 commit 01c4ff8

File tree

2 files changed

+105
-23
lines changed

2 files changed

+105
-23
lines changed

.github/workflows/test_readme.yml

Lines changed: 88 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,114 @@ on:
77
schedule:
88
- cron: 0 0 */3 * *
99

10+
defaults:
11+
run:
12+
shell: bash
13+
1014
jobs:
11-
no_cache_build:
15+
build:
1216
runs-on: ubuntu-latest
1317

1418
steps:
15-
- run: docker image ls -q | xargs docker rmi
19+
- name: Output matrix
20+
id: set_matrix
21+
uses: actions/github-script@v2
22+
with:
23+
script: |
24+
return {
25+
inspect_image: [
26+
'test_project_scratch',
27+
'hello-world',
28+
'nothing'
29+
],
30+
os: [
31+
'ubuntu-latest',
32+
'windows-latest',
33+
],
34+
include: [
35+
{
36+
inspect_image: 'test_project_scratch',
37+
prepare_command: 'docker-compose -f test_project/docker-compose.yml -p test_project pull',
38+
build_command: 'docker-compose -f test_project/docker-compose.yml -p test_project build',
39+
}, {
40+
inspect_image: 'hello-world',
41+
prepare_command: ':',
42+
build_command: 'docker pull hello-world',
43+
}, {
44+
inspect_image: 'nothing',
45+
os: 'ubuntu-latest',
46+
prepare_command: 'docker tag node:12 nothing',
47+
build_command: ':',
48+
}, {
49+
inspect_image: 'nothing',
50+
os: 'windows-latest',
51+
prepare_command: 'docker tag mcr.microsoft.com/windows/nanoserver:1809 nothing',
52+
build_command: ':',
53+
}, {
54+
branch: process.env.GITHUB_REF.replace('refs/heads/', '')
55+
}
56+
],
57+
exclude: [
58+
{
59+
inspect_image: 'test_project_scratch',
60+
os: 'windows-latest',
61+
},
62+
],
63+
}
64+
65+
outputs:
66+
matrix: ${{ steps.set_matrix.outputs.result }}
67+
68+
test_saving:
69+
if: github.event_name != 'delete'
70+
needs: build
71+
strategy:
72+
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
73+
runs-on: ${{ matrix.os }}
74+
75+
steps:
1676
- uses: actions/checkout@v2
17-
- run: docker-compose -f test_project/docker-compose.yml -p test_project pull
1877

19-
- uses: satackey/action-docker-layer-caching@v0.0.8
78+
- run: ${{ matrix.prepare_command }}
79+
80+
- uses: satackey/action-docker-layer-caching@master-release
2081
with:
21-
key: docker-layer-caching-${{ github.workflow }}-${{ github.event_name }}-{hash}
22-
restore-keys: docker-layer-caching-${{ github.workflow }}-${{ github.event_name }}-
82+
key: docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
83+
restore-keys: ''
2384

24-
- run: docker image ls -q | xargs docker rmi
25-
- run: docker-compose -f test_project/docker-compose.yml -p test_project build --no-cache
85+
- run: ${{ matrix.build_command }}
2686

27-
cached_build:
28-
runs-on: ubuntu-latest
29-
needs:
30-
- no_cache_build
87+
test_restoring:
88+
needs: [build, test_saving]
89+
strategy:
90+
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
91+
runs-on: ${{ matrix.os }}
3192

3293
steps:
33-
- run: docker image ls -q | xargs docker rmi
3494
- uses: actions/checkout@v2
35-
- run: docker-compose -f test_project/docker-compose.yml -p test_project pull
3695

37-
- uses: satackey/action-docker-layer-caching@v0.0.8
96+
- run: ${{ matrix.prepare_command }}
97+
98+
- uses: satackey/action-docker-layer-caching@master-release
3899
with:
39-
key: docker-layer-caching-${{ github.workflow }}-${{ github.event_name }}-{hash}
40-
restore-keys: docker-layer-caching-${{ github.workflow }}-${{ github.event_name }}-
100+
key: never-restored-docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
101+
restore-keys: docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-
102+
skip-save: 'true'
103+
104+
- name: Show cached image info
105+
run: docker inspect ${{ matrix.inspect_image }}
41106

42107
- name: Get cached image ID
43-
run: echo ::set-output name=id::$(docker image ls -q test_project_node)
108+
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
44109
id: cached
45110

46-
- run: docker-compose -f test_project/docker-compose.yml -p test_project build
111+
- run: ${{ matrix.build_command }}
112+
113+
- name: Show built image info
114+
run: docker inspect ${{ matrix.inspect_image }}
47115

48116
- name: Show built image ID
49-
run: echo ::set-output name=id::$(docker image ls -q test_project_node)
117+
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
50118
id: latest
51119

52120
- name: Compare cached ID and after build ID
@@ -55,4 +123,3 @@ jobs:
55123
echo cached != latest
56124
exit 1
57125
fi
58-

test_project/Dockerfile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
FROM alpine AS data
2-
RUN date > /now.txt
2+
RUN date > /now1.txt
3+
RUN date > /now2.txt
4+
RUN date > /now3.txt
5+
RUN date > /now4.txt
6+
RUN date > /now5.txt
7+
RUN date > /now6.txt
8+
RUN date > /now7.txt
9+
RUN date > /now8.txt
10+
RUN date > /now9.txt
11+
RUN date > /now10.txt
12+
RUN date > /now11.txt
13+
RUN date > /now12.txt
14+
RUN date > /now13.txt
15+
RUN date > /now14.txt
16+
RUN date > /now15.txt
17+
RUN date > /now16.txt
318

419
FROM scratch
5-
COPY --from=data /now.txt /data_stage_built_at.txt
20+
COPY --from=data /now16.txt /data_stage_built_at.txt

0 commit comments

Comments
 (0)