7575 - name : Run unit tests
7676 run : cargo test --locked --all-targets --workspace --all-features
7777 timeout-minutes : 10
78+
7879 check :
7980 runs-on : ubuntu-latest
8081 outputs :
8485 - uses : ./.github/actions/setup-rust
8586 - run : cargo xtask ci-job check
8687 id : check
88+
8789 generate-matrix :
8890 runs-on : ubuntu-latest
8991 outputs :
@@ -98,10 +100,109 @@ jobs:
98100 COMMIT_MESSAGE : ${{ github.event.head_commit.message }}
99101 COMMIT_AUTHOR : ${{ github.event.head_commit.author.username }}
100102
103+ build-base :
104+ name : base (${{ matrix.image }})
105+ runs-on : ubuntu-latest
106+ needs : [shellcheck, test, check]
107+ if : github.event_name == 'push'
108+ strategy :
109+ fail-fast : false
110+ matrix :
111+ image :
112+ - base
113+ sub :
114+ - ubuntu
115+ - centos
116+ - emscripten
117+ outputs :
118+ coverage-artifact : ${{ steps.cov.outputs.artifact-name }}
119+ steps :
120+ - uses : actions/checkout@v3
121+ - uses : ./.github/actions/setup-rust
122+
123+ - name : Set up Docker Buildx
124+ if : runner.os == 'Linux'
125+ uses : docker/setup-buildx-action@v1
126+
127+ - name : Build xtask
128+ run : cargo build -p xtask
129+
130+ - name : Prepare Meta
131+ id : prepare-meta
132+ timeout-minutes : 60
133+ run : cargo xtask ci-job prepare-meta "${IMAGE}.${SUB}"
134+ env :
135+ IMAGE : ${{ matrix.image }}
136+ SUB : ${{ matrix.sub }}
137+ shell : bash
138+
139+ - name : LLVM instrument coverage
140+ uses : ./.github/actions/cargo-llvm-cov
141+ with :
142+ name : cross-${{matrix.image}}-${{matrix.sub}}
143+
144+ - name : Install cross
145+ if : matrix.deploy
146+ run : cargo install --path . --force --debug
147+
148+ - name : Docker Meta
149+ id : docker-meta
150+ uses : docker/metadata-action@v4
151+ with :
152+ images : |
153+ name=${{ steps.prepare-meta.outputs.image }}
154+ labels : |
155+ ${{ fromJSON(steps.prepare-meta.outputs.labels) }}
156+
157+ - name : Build Docker image
158+ id : build-docker-image
159+ timeout-minutes : 60
160+ run : cargo xtask build-docker-image -v "${IMAGE}.${SUB}"
161+ env :
162+ IMAGE : ${{ matrix.image }}
163+ SUB : ${{ matrix.sub }}
164+ LABELS : ${{ steps.docker-meta.outputs.labels }}
165+ LATEST : ${{ needs.check.outputs.is-latest || 'false' }}
166+ shell : bash
167+
168+ - name : Save Docker Image
169+ id : save-docker-image
170+ run : docker save "${IMAGE}:${TAG}" -o "${IMAGE}-${TAG}-${SUB}.tar"
171+ env :
172+ IMAGE : ${{ matrix.image }}
173+ SUB : ${{ matrix.sub }}
174+ TAG : ${{ env.GITHUB_REF_NAME }}
175+
176+ - uses : actions/upload-artifact@v2
177+ with :
178+ name : ${{ matrix.image }}-${{ matrix.sub }}-image-tarball
179+ path : ${{ matrix.image }}-${{ matrix.sub }}-${{ env.GITHUB_REF_NAME }}.tar
180+
181+ - name : Login to GitHub Container Registry
182+ uses : docker/login-action@v1
183+ with :
184+ registry : ghcr.io
185+ username : ${{ github.actor }}
186+ password : ${{ secrets.GITHUB_TOKEN }}
187+
188+ - name : Push image to GitHub Container Registry
189+ if : >
190+ (
191+ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ||
192+ startsWith(github.ref, 'refs/tags/v')
193+ )
194+ run : cargo xtask build-docker-image -v "${IMAGE}.${SUB}"
195+ env :
196+ IMAGE : ${{ matrix.image }}
197+ SUB : ${{ matrix.sub }}
198+ LABELS : ${{ steps.docker-meta.outputs.labels }}
199+ LATEST : ${{ needs.check.outputs.is-latest || 'false' }}
200+ shell : bash
201+
101202 build :
102203 name : target (${{ matrix.pretty }},${{ matrix.os }})
103204 runs-on : ${{ matrix.os }}
104- needs : [shellcheck, test, generate-matrix, check]
205+ needs : [shellcheck, test, generate-matrix, check, build-base ]
105206 if : github.event_name == 'push'
106207 strategy :
107208 fail-fast : false
@@ -113,7 +214,6 @@ jobs:
113214 coverage-artifact : ${{ steps.cov.outputs.artifact-name }}
114215 steps :
115216 - uses : actions/checkout@v3
116-
117217 - uses : ./.github/actions/setup-rust
118218
119219 - name : Set up Docker Buildx
@@ -152,6 +252,32 @@ jobs:
152252 name=${{ steps.prepare-meta.outputs.image }}
153253 labels : |
154254 ${{ fromJSON(steps.prepare-meta.outputs.labels) }}
255+
256+ - name : Set env Base Image
257+ if : steps.prepare-meta.outputs.has-image
258+ run : |
259+ if [[ "${SUB}" == "centos" ]]; then
260+ echo "BASE=centos" >> "${GITHUB_ENV}"
261+ elif [[ "${TARGET}" == *emscripten ]]; then
262+ echo "BASE=emscripten" >> "${GITHUB_ENV}"
263+ else
264+ echo "BASE=ubuntu" >> "${GITHUB_ENV}"
265+ fi
266+ env :
267+ TARGET : ${{ matrix.target }}
268+ SUB : ${{ matrix.sub }}
269+
270+ - uses : actions/download-artifact@v3
271+ if : steps.prepare-meta.outputs.has-image
272+ with :
273+ name : base-${{ env.BASE }}-image-tarball
274+ path : base.tar
275+
276+ - name : Load Base Image
277+ id : load-docker-image
278+ if : steps.prepare-meta.outputs.has-image
279+ run : docker load "base.tar"
280+
155281 - name : Build Docker image
156282 id : build-docker-image
157283 if : steps.prepare-meta.outputs.has-image
@@ -163,6 +289,7 @@ jobs:
163289 LABELS : ${{ steps.docker-meta.outputs.labels }}
164290 LATEST : ${{ needs.check.outputs.is-latest || 'false' }}
165291 shell : bash
292+
166293 - name : Set Docker image for test
167294 if : steps.prepare-meta.outputs.has-image
168295 run : |
@@ -172,6 +299,7 @@ jobs:
172299 TARGET : ${{ matrix.target }}
173300 IMAGE : ${{ steps.build-docker-image.outputs.image }}
174301 shell : bash
302+
175303 - name : Test Image
176304 if : steps.prepare-meta.outputs.has-image && steps.prepare-meta.outputs.test-variant == 'default'
177305 run : ./ci/test.sh
@@ -184,6 +312,7 @@ jobs:
184312 RUN : ${{ matrix.run }}
185313 RUNNERS : ${{ matrix.runners }}
186314 shell : bash
315+
187316 - uses : ./.github/actions/cargo-install-upload-artifacts
188317 if : matrix.deploy
189318 with :
@@ -209,6 +338,7 @@ jobs:
209338 registry : ghcr.io
210339 username : ${{ github.actor }}
211340 password : ${{ secrets.GITHUB_TOKEN }}
341+
212342 - name : Push image to GitHub Container Registry
213343 if : >
214344 steps.prepare-meta.outputs.has-image && (
@@ -274,15 +404,18 @@ jobs:
274404 uses : ./.github/actions/cargo-llvm-cov
275405 with :
276406 name : integration-bisect
407+
277408 - name : Set up QEMU
278409 uses : docker/setup-qemu-action@v2
279410 with :
280411 platforms : arm64
412+
281413 - name : Set up docker buildx
282414 uses : docker/setup-buildx-action@v2
283415 id : buildx
284416 with :
285417 install : true
418+
286419 - name : Run Foreign toolchain test
287420 run : ./ci/test-foreign-toolchain.sh
288421 shell : bash
@@ -320,7 +453,6 @@ jobs:
320453 coverage-artifact : ${{ steps.cov.outputs.artifact-name }}
321454 steps :
322455 - uses : actions/checkout@v3
323-
324456 - uses : ./.github/actions/setup-rust
325457
326458 - name : Install Podman
@@ -347,7 +479,7 @@ jobs:
347479 shell : bash
348480
349481 publish :
350- needs : [build, check, fmt, clippy, cargo-deny]
482+ needs : [build-base, build , check, fmt, clippy, cargo-deny]
351483 runs-on : ubuntu-latest
352484 steps :
353485 - uses : actions/checkout@v3
@@ -358,7 +490,7 @@ jobs:
358490 github-token : ${{ secrets.GITHUB_TOKEN }}
359491
360492 conclusion :
361- needs : [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker, foreign, podman]
493+ needs : [shellcheck, fmt, clippy, test, generate-matrix, build-base, build , publish, check, remote, bisect, docker-in-docker, foreign, podman]
362494 if : always()
363495 runs-on : ubuntu-latest
364496 steps :
0 commit comments