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,113 @@ jobs:
98100 COMMIT_MESSAGE : ${{ github.event.head_commit.message }}
99101 COMMIT_AUTHOR : ${{ github.event.head_commit.author.username }}
100102
103+ build-base :
104+ name : ${{ matrix.image }} (${{ matrix.sub }})
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+ # always use the main branch, since we need it for the base image
158+ - name : Build Docker image
159+ id : build-docker-image
160+ timeout-minutes : 60
161+ run : cargo xtask build-docker-image -v --tag main "${IMAGE}.${SUB}"
162+ env :
163+ IMAGE : ${{ matrix.image }}
164+ SUB : ${{ matrix.sub }}
165+ LABELS : ${{ steps.docker-meta.outputs.labels }}
166+ LATEST : ${{ needs.check.outputs.is-latest || 'false' }}
167+ shell : bash
168+
169+ - name : Save Docker Image
170+ id : save-docker-image
171+ # TODO(ahuszagh) Remove the multiline
172+ run : |
173+ docker save "ghcr.io/cross-rs/${IMAGE}:main-${SUB}" -o "${IMAGE}-main-${SUB}.tar"
174+ file "${IMAGE}-main-${SUB}.tar"
175+ ls -la .
176+ env :
177+ IMAGE : ${{ matrix.image }}
178+ SUB : ${{ matrix.sub }}
179+
180+ - uses : actions/upload-artifact@v2
181+ with :
182+ name : ${{ matrix.image }}-${{ matrix.sub }}-image-tarball
183+ path : ${{ matrix.image }}-main-${{ matrix.sub }}.tar
184+
185+ - name : Login to GitHub Container Registry
186+ uses : docker/login-action@v1
187+ with :
188+ registry : ghcr.io
189+ username : ${{ github.actor }}
190+ password : ${{ secrets.GITHUB_TOKEN }}
191+
192+ - name : Push image to GitHub Container Registry
193+ if : >
194+ (
195+ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ||
196+ startsWith(github.ref, 'refs/tags/v')
197+ )
198+ run : cargo xtask build-docker-image -v "${IMAGE}.${SUB}"
199+ env :
200+ IMAGE : ${{ matrix.image }}
201+ SUB : ${{ matrix.sub }}
202+ LABELS : ${{ steps.docker-meta.outputs.labels }}
203+ LATEST : ${{ needs.check.outputs.is-latest || 'false' }}
204+ shell : bash
205+
101206 build :
102207 name : target (${{ matrix.pretty }},${{ matrix.os }})
103208 runs-on : ${{ matrix.os }}
104- needs : [shellcheck, test, generate-matrix, check]
209+ needs : [shellcheck, test, generate-matrix, check, build-base ]
105210 if : github.event_name == 'push'
106211 strategy :
107212 fail-fast : false
@@ -113,7 +218,6 @@ jobs:
113218 coverage-artifact : ${{ steps.cov.outputs.artifact-name }}
114219 steps :
115220 - uses : actions/checkout@v3
116-
117221 - uses : ./.github/actions/setup-rust
118222
119223 - name : Set up Docker Buildx
@@ -152,6 +256,38 @@ jobs:
152256 name=${{ steps.prepare-meta.outputs.image }}
153257 labels : |
154258 ${{ fromJSON(steps.prepare-meta.outputs.labels) }}
259+
260+ - name : Set env Base Image
261+ if : steps.prepare-meta.outputs.has-image
262+ run : |
263+ if [[ "${SUB}" == "centos" ]]; then
264+ echo "BASE=centos" >> "${GITHUB_ENV}"
265+ elif [[ "${TARGET}" == *emscripten ]]; then
266+ echo "BASE=emscripten" >> "${GITHUB_ENV}"
267+ else
268+ echo "BASE=ubuntu" >> "${GITHUB_ENV}"
269+ fi
270+ env :
271+ TARGET : ${{ matrix.target }}
272+ SUB : ${{ matrix.sub }}
273+
274+ - uses : actions/download-artifact@v3
275+ if : steps.prepare-meta.outputs.has-image
276+ with :
277+ name : base-${{ env.BASE }}-image-tarball
278+ path : base.tar
279+
280+ - name : Load Base Image
281+ id : load-docker-image
282+ if : steps.prepare-meta.outputs.has-image
283+ # TODO(ahuszagh) Remove the multiline
284+ run : |
285+ pwd
286+ file "base.tar"
287+ ls -la .
288+ ls -la base.tar/
289+ docker load --input "base.tar"
290+
155291 - name : Build Docker image
156292 id : build-docker-image
157293 if : steps.prepare-meta.outputs.has-image
@@ -163,6 +299,7 @@ jobs:
163299 LABELS : ${{ steps.docker-meta.outputs.labels }}
164300 LATEST : ${{ needs.check.outputs.is-latest || 'false' }}
165301 shell : bash
302+
166303 - name : Set Docker image for test
167304 if : steps.prepare-meta.outputs.has-image
168305 run : |
@@ -172,6 +309,7 @@ jobs:
172309 TARGET : ${{ matrix.target }}
173310 IMAGE : ${{ steps.build-docker-image.outputs.image }}
174311 shell : bash
312+
175313 - name : Test Image
176314 if : steps.prepare-meta.outputs.has-image && steps.prepare-meta.outputs.test-variant == 'default'
177315 run : ./ci/test.sh
@@ -184,6 +322,7 @@ jobs:
184322 RUN : ${{ matrix.run }}
185323 RUNNERS : ${{ matrix.runners }}
186324 shell : bash
325+
187326 - uses : ./.github/actions/cargo-install-upload-artifacts
188327 if : matrix.deploy
189328 with :
@@ -209,6 +348,7 @@ jobs:
209348 registry : ghcr.io
210349 username : ${{ github.actor }}
211350 password : ${{ secrets.GITHUB_TOKEN }}
351+
212352 - name : Push image to GitHub Container Registry
213353 if : >
214354 steps.prepare-meta.outputs.has-image && (
@@ -274,15 +414,18 @@ jobs:
274414 uses : ./.github/actions/cargo-llvm-cov
275415 with :
276416 name : integration-bisect
417+
277418 - name : Set up QEMU
278419 uses : docker/setup-qemu-action@v2
279420 with :
280421 platforms : arm64
422+
281423 - name : Set up docker buildx
282424 uses : docker/setup-buildx-action@v2
283425 id : buildx
284426 with :
285427 install : true
428+
286429 - name : Run Foreign toolchain test
287430 run : ./ci/test-foreign-toolchain.sh
288431 shell : bash
@@ -320,7 +463,6 @@ jobs:
320463 coverage-artifact : ${{ steps.cov.outputs.artifact-name }}
321464 steps :
322465 - uses : actions/checkout@v3
323-
324466 - uses : ./.github/actions/setup-rust
325467
326468 - name : Install Podman
@@ -347,7 +489,7 @@ jobs:
347489 shell : bash
348490
349491 publish :
350- needs : [build, check, fmt, clippy, cargo-deny]
492+ needs : [build-base, build , check, fmt, clippy, cargo-deny]
351493 runs-on : ubuntu-latest
352494 steps :
353495 - uses : actions/checkout@v3
@@ -358,7 +500,7 @@ jobs:
358500 github-token : ${{ secrets.GITHUB_TOKEN }}
359501
360502 conclusion :
361- needs : [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker, foreign, podman]
503+ needs : [shellcheck, fmt, clippy, test, generate-matrix, build-base, build , publish, check, remote, bisect, docker-in-docker, foreign, podman]
362504 if : always()
363505 runs-on : ubuntu-latest
364506 steps :
0 commit comments