forked from satackey/action-docker-layer-caching
-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (141 loc) · 4.56 KB
/
release.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: CI
on:
push:
branches:
- '**'
pull_request:
delete:
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v2
- name: Output info
id: info
run: |
if [ '${{ github.event_name }}' = 'pull_request' ]; then
echo '::set-output name=commit_message::'
exit 0
fi
echo '::set-output name=commit_message::[auto]'
- uses: satackey/[email protected]
with:
commit-message: ${{ steps.info.outputs.commit_message }}
push-branch: '{branch}-release'
- uses: actions/upload-artifact@v2
if: github.event_name != 'delete'
with:
name: built
path: ./
- name: Output matrix
id: set_matrix
uses: actions/github-script@v2
with:
script: |
return {
inspect_image: [
'test_project_scratch',
'hello-world',
'nothing'
],
os: [
'ubuntu-latest',
'windows-latest',
],
include: [
{
inspect_image: 'test_project_scratch',
prepare_command: 'docker-compose -f test_project/docker-compose.yml -p test_project pull',
build_command: 'docker-compose -f test_project/docker-compose.yml -p test_project build',
}, {
inspect_image: 'hello-world',
prepare_command: ':',
build_command: 'docker pull hello-world',
}, {
inspect_image: 'nothing',
os: 'ubuntu-latest',
prepare_command: 'docker tag node:12 nothing',
build_command: ':',
}, {
inspect_image: 'nothing',
os: 'windows-latest',
prepare_command: 'docker tag mcr.microsoft.com/windows/nanoserver:1809 nothing',
build_command: ':',
}, {
branch: process.env.GITHUB_REF.replace('refs/heads/', '')
}
],
exclude: [
{
inspect_image: 'test_project_scratch',
os: 'windows-latest',
},
],
}
outputs:
matrix: ${{ steps.set_matrix.outputs.result }}
test_saving:
if: github.event_name != 'delete'
needs: build
strategy:
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- run: ${{ matrix.prepare_command }}
- name: Download action
uses: actions/download-artifact@v2
with:
name: built
path: action-dlc
- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ matrix.branch }}
with:
key: docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
- run: ${{ matrix.build_command }}
test_restoring:
needs: [build, test_saving]
strategy:
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- run: ${{ matrix.prepare_command }}
- name: Extract
id: extract
run: |
echo "##[set-output name=branch;]${GITHUB_REF#refs/heads/}"
- name: Download action
uses: actions/download-artifact@v2
with:
name: built
path: action-dlc
- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ matrix.branch }}
with:
key: never-restored-docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-
skip-save: 'true'
- name: Show cached image info
run: docker inspect ${{ matrix.inspect_image }}
- name: Get cached image ID
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
id: cached
- run: ${{ matrix.build_command }}
- name: Show built image info
run: docker inspect ${{ matrix.inspect_image }}
- name: Show built image ID
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
id: latest
- name: Compare cached ID and after build ID
run: |
if [ ! '${{ steps.cached.outputs.id }}' = '${{ steps.latest.outputs.id }}' ];then
echo cached != latest
exit 1
fi