1818 DESTDIR : ./bin
1919
2020jobs :
21+ prepare :
22+ runs-on : ubuntu-latest
23+ outputs :
24+ validate-targets : ${{ steps.validate-targets.outputs.matrix }}
25+ artifact-platforms : ${{ steps.artifact-platforms.outputs.matrix }}
26+ steps :
27+ -
28+ name : Checkout
29+ uses : actions/checkout@v3
30+ -
31+ name : Validate targets matrix
32+ id : validate-targets
33+ run : |
34+ echo "matrix=$(docker buildx bake validate --print | jq -cr '.group.default.targets')" >> $GITHUB_OUTPUT
35+ -
36+ name : Artifact platforms matrix
37+ id : artifact-platforms
38+ run : |
39+ echo "matrix=$(docker buildx bake artifact-all --print | jq -cr '.target."artifact-all".platforms')" >> $GITHUB_OUTPUT
40+
2141 validate :
2242 runs-on : ubuntu-latest
43+ needs :
44+ - prepare
45+ strategy :
46+ fail-fast : false
47+ matrix :
48+ target : ${{ fromJson(needs.prepare.outputs.validate-targets) }}
2349 steps :
2450 -
2551 name : Checkout
3157 name : Validate
3258 uses : docker/bake-action@v2
3359 with :
34- targets : validate
35- pull : true
60+ targets : ${{ matrix.target }}
3661
3762 test :
3863 runs-on : ubuntu-latest
@@ -57,17 +82,106 @@ jobs:
5782 with :
5883 directory : ${{ env.DESTDIR }}/coverage
5984
60- build :
85+ artifact :
6186 runs-on : ubuntu-latest
6287 needs :
88+ - prepare
6389 - validate
90+ strategy :
91+ fail-fast : false
92+ matrix :
93+ platform : ${{ fromJson(needs.prepare.outputs.artifact-platforms) }}
94+ steps :
95+ -
96+ name : Prepare
97+ run : |
98+ platform=${{ matrix.platform }}
99+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
100+ -
101+ name : Checkout
102+ uses : actions/checkout@v3
103+ with :
104+ fetch-depth : 0
105+ -
106+ name : Set up QEMU
107+ uses : docker/setup-qemu-action@v2
108+ -
109+ name : Set up Docker Buildx
110+ uses : docker/setup-buildx-action@v2
111+ -
112+ name : Build
113+ uses : docker/bake-action@v2
114+ with :
115+ targets : artifact
116+ pull : true
117+ set : |
118+ *.platform=${{ matrix.platform }}
119+ *.cache-from=type=gha,scope=artifact-${{ env.PLATFORM_PAIR }}
120+ *.cache-to=type=gha,scope=artifact-${{ env.PLATFORM_PAIR }},mode=max
121+ -
122+ name : Upload artifact
123+ uses : actions/upload-artifact@v3
124+ with :
125+ name : diun
126+ path : ${{ env.DESTDIR }}
127+ if-no-files-found : error
128+
129+ release :
130+ runs-on : ubuntu-latest
131+ needs :
132+ - artifact
133+ - test
134+ steps :
135+ -
136+ name : Checkout
137+ uses : actions/checkout@v3
138+ -
139+ name : Download artifacts
140+ uses : actions/download-artifact@v3
141+ with :
142+ name : diun
143+ path : ${{ env.DESTDIR }}
144+ -
145+ name : Set up Docker Buildx
146+ uses : docker/setup-buildx-action@v2
147+ -
148+ name : Build
149+ uses : docker/bake-action@v2
150+ with :
151+ targets : release
152+ -
153+ name : GitHub Release
154+ uses : softprops/action-gh-release@v1
155+ if : startsWith(github.ref, 'refs/tags/')
156+ with :
157+ draft : true
158+ files : |
159+ ${{ env.DESTDIR }}/release/*
160+ env :
161+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
162+
163+ image :
164+ runs-on : ubuntu-latest
165+ needs :
166+ - artifact
64167 - test
65168 steps :
66169 -
67170 name : Checkout
68171 uses : actions/checkout@v3
69172 with :
70173 fetch-depth : 0
174+ -
175+ name : Prepare
176+ run : |
177+ cfroms=
178+ while read -r platform; do
179+ if [ -n "$cfroms" ]; then cfroms="${cfroms}\n"; fi
180+ cfroms="${cfroms}*.cache-from=type=gha,scope=artifact-${platform//\//-}"
181+ done < <(docker buildx bake artifact-all --print | jq -r '.target."artifact-all".platforms[]')
182+ echo "CACHE_FROMS<<EOF" >> $GITHUB_ENV
183+ echo -e "$cfroms" >> $GITHUB_ENV
184+ echo "EOF" >> $GITHUB_ENV
71185 -
72186 name : Docker meta
73187 id : meta
@@ -108,25 +222,7 @@ jobs:
108222 username : ${{ github.repository_owner }}
109223 password : ${{ secrets.GITHUB_TOKEN }}
110224 -
111- name : Build artifacts
112- uses : docker/bake-action@v2
113- with :
114- targets : artifact-all
115- pull : true
116- -
117- name : Release
118- uses : docker/bake-action@v2
119- with :
120- targets : release
121- -
122- name : Upload artifacts
123- uses : actions/upload-artifact@v3
124- with :
125- name : diun
126- path : ${{ env.DESTDIR }}/release/*
127- if-no-files-found : error
128- -
129- name : Build image
225+ name : Build
130226 uses : docker/bake-action@v2
131227 with :
132228 files : |
@@ -135,16 +231,8 @@ jobs:
135231 targets : image-all
136232 pull : true
137233 push : ${{ github.event_name != 'pull_request' }}
138- -
139- name : GitHub Release
140- uses : softprops/action-gh-release@v1
141- if : startsWith(github.ref, 'refs/tags/')
142- with :
143- draft : true
144- files : |
145- ${{ env.DESTDIR }}/release/*
146- env :
147- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
234+ set : |
235+ ${{ env.CACHE_FROMS }}
148236 -
149237 name : Check manifest
150238 if : github.event_name != 'pull_request'
0 commit comments