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 :
@@ -99,10 +101,109 @@ jobs:
99101          COMMIT_MESSAGE : ${{ github.event.head_commit.message }} 
100102          COMMIT_AUTHOR : ${{ github.event.head_commit.author.username }} 
101103
104+   build-base :
105+     name : ${{ matrix.image }} (${{ matrix.sub }}) 
106+     runs-on : ubuntu-latest 
107+     needs : [shellcheck, test, check] 
108+     if : github.event_name == 'push' 
109+     strategy :
110+       fail-fast : false 
111+       matrix :
112+         image :
113+           - base 
114+         sub :
115+           - ubuntu 
116+           - centos 
117+           - emscripten 
118+     outputs :
119+       coverage-artifact : ${{ steps.cov.outputs.artifact-name }} 
120+     steps :
121+       - uses : actions/checkout@v3 
122+       - uses : ./.github/actions/setup-rust 
123+ 
124+       - name : Set up Docker Buildx 
125+         if : runner.os == 'Linux' 
126+         uses : docker/setup-buildx-action@v1 
127+ 
128+       - name : Build xtask 
129+         run : cargo build -p xtask 
130+ 
131+       - name : Prepare Meta 
132+         id : prepare-meta 
133+         timeout-minutes : 60 
134+         run : cargo xtask ci-job prepare-meta "${IMAGE}.${SUB}" 
135+         env :
136+           IMAGE : ${{ matrix.image }} 
137+           SUB : ${{ matrix.sub }} 
138+         shell : bash 
139+ 
140+       - name : LLVM instrument coverage 
141+         uses : ./.github/actions/cargo-llvm-cov 
142+         with :
143+           name : cross-${{matrix.image}}-${{matrix.sub}} 
144+ 
145+       - name : Install cross 
146+         if : matrix.deploy 
147+         run : cargo install --path . --force --debug 
148+ 
149+       - name : Docker Meta 
150+         id : docker-meta 
151+         uses : docker/metadata-action@v4 
152+         with :
153+           images : | 
154+             name=${{ steps.prepare-meta.outputs.image }} 
155+ labels : | 
156+             ${{ fromJSON(steps.prepare-meta.outputs.labels) }} 
157+ 
158+ #  always use the main branch, since we need it for the base image
159+       - name : Build Docker image 
160+         id : build-docker-image 
161+         timeout-minutes : 60 
162+         run : cargo xtask build-docker-image -v --tag main "${IMAGE}.${SUB}" 
163+         env :
164+           IMAGE : ${{ matrix.image }} 
165+           SUB : ${{ matrix.sub }} 
166+           LABELS : ${{ steps.docker-meta.outputs.labels }} 
167+           LATEST : ${{ needs.check.outputs.is-latest || 'false' }} 
168+         shell : bash 
169+ 
170+       - name : Save Docker Image 
171+         id : save-docker-image 
172+         run : docker save "ghcr.io/cross-rs/${IMAGE}:main-${SUB}" -o "${IMAGE}-main-${SUB}.tar" 
173+         env :
174+           IMAGE : ${{ matrix.image }} 
175+           SUB : ${{ matrix.sub }} 
176+ 
177+       - uses : actions/upload-artifact@v2 
178+         with :
179+           name : ${{ matrix.image }}-${{ matrix.sub }}-image-tarball 
180+           path : ${{ matrix.image }}-main-${{ matrix.sub }}.tar 
181+ 
182+       - name : Login to GitHub Container Registry 
183+         uses : docker/login-action@v1 
184+         with :
185+           registry : ghcr.io 
186+           username : ${{ github.actor }} 
187+           password : ${{ secrets.GITHUB_TOKEN }} 
188+ 
189+       - name : Push image to GitHub Container Registry 
190+         if : > 
191+           ( 
192+             github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || 
193+             startsWith(github.ref, 'refs/tags/v') 
194+           ) 
195+ run : cargo xtask build-docker-image -v "${IMAGE}.${SUB}" 
196+         env :
197+           IMAGE : ${{ matrix.image }} 
198+           SUB : ${{ matrix.sub }} 
199+           LABELS : ${{ steps.docker-meta.outputs.labels }} 
200+           LATEST : ${{ needs.check.outputs.is-latest || 'false' }} 
201+         shell : bash 
202+ 
102203  build :
103204    name : target (${{ matrix.pretty }},${{ matrix.os }}) 
104205    runs-on : ${{ matrix.os }} 
105-     needs : [shellcheck, test, generate-matrix, check] 
206+     needs : [shellcheck, test, generate-matrix, check, build-base ] 
106207    if : github.event_name == 'push' && needs.generate-matrix.outputs.matrix != '{}' && needs.generate-matrix.outputs.matrix != '[]' && needs.generate-matrix.outputs.matrix != '' 
107208    strategy :
108209      fail-fast : false 
@@ -114,7 +215,6 @@ jobs:
114215      coverage-artifact : ${{ steps.cov.outputs.artifact-name }} 
115216    steps :
116217      - uses : actions/checkout@v3 
117- 
118218      - uses : ./.github/actions/setup-rust 
119219
120220      - name : Set up Docker Buildx 
@@ -153,17 +253,48 @@ jobs:
153253            name=${{ steps.prepare-meta.outputs.image }} 
154254labels : | 
155255            ${{ fromJSON(steps.prepare-meta.outputs.labels) }} 
256+ 
257+ name : Set env Base Image 
258+         if : steps.prepare-meta.outputs.has-image 
259+         run : | 
260+           if [[ "${SUB}" == "centos" ]]; then 
261+               echo "BASE=centos" >> "${GITHUB_ENV}" 
262+           elif [[ "${TARGET}" == *emscripten ]]; then 
263+               echo "BASE=emscripten" >> "${GITHUB_ENV}" 
264+           else 
265+               echo "BASE=ubuntu" >> "${GITHUB_ENV}" 
266+           fi 
267+ env :
268+           TARGET : ${{ matrix.target }} 
269+           SUB : ${{ matrix.sub }} 
270+ 
271+       - uses : actions/download-artifact@v3 
272+         if : steps.prepare-meta.outputs.has-image 
273+         with :
274+           name : base-${{ env.BASE }}-image-tarball 
275+ 
276+       - name : Load Base Image 
277+         id : load-docker-image 
278+         if : steps.prepare-meta.outputs.has-image 
279+         run : docker load --input "base-main-${BASE}.tar" 
280+         env :
281+           SUB : ${{ matrix.sub }} 
282+ 
156283      - name : Build Docker image 
157284        id : build-docker-image 
158285        if : steps.prepare-meta.outputs.has-image 
159286        timeout-minutes : 120 
160-         run : cargo xtask build-docker-image -v "${TARGET}${SUB:+.$SUB}" 
287+         #  TODO(ahuszagh) Remove this multiline and docker images
288+         run : | 
289+           docker images 
290+           cargo xtask build-docker-image -v "${TARGET}${SUB:+.$SUB}" 
161291env :
162292          TARGET : ${{ matrix.target }} 
163293          SUB : ${{ matrix.sub }} 
164294          LABELS : ${{ steps.docker-meta.outputs.labels }} 
165295          LATEST : ${{ needs.check.outputs.is-latest || 'false' }} 
166296        shell : bash 
297+ 
167298      - name : Set Docker image for test 
168299        if : steps.prepare-meta.outputs.has-image 
169300        run : | 
@@ -173,6 +304,7 @@ jobs:
173304          TARGET : ${{ matrix.target }} 
174305          IMAGE : ${{ steps.build-docker-image.outputs.image }} 
175306        shell : bash 
307+ 
176308      - name : Test Image 
177309        if : steps.prepare-meta.outputs.has-image && steps.prepare-meta.outputs.test-variant == 'default' 
178310        run : ./ci/test.sh 
@@ -185,6 +317,7 @@ jobs:
185317          RUN : ${{ matrix.run }} 
186318          RUNNERS : ${{ matrix.runners }} 
187319        shell : bash 
320+ 
188321      - uses : ./.github/actions/cargo-install-upload-artifacts 
189322        if : matrix.deploy 
190323        with :
@@ -210,6 +343,7 @@ jobs:
210343          registry : ghcr.io 
211344          username : ${{ github.actor }} 
212345          password : ${{ secrets.GITHUB_TOKEN }} 
346+ 
213347      - name : Push image to GitHub Container Registry 
214348        if : > 
215349          steps.prepare-meta.outputs.has-image && ( 
@@ -275,15 +409,18 @@ jobs:
275409        uses : ./.github/actions/cargo-llvm-cov 
276410        with :
277411          name : integration-bisect 
412+ 
278413      - name : Set up QEMU 
279414        uses : docker/setup-qemu-action@v2 
280415        with :
281416          platforms : arm64 
417+ 
282418      - name : Set up docker buildx 
283419        uses : docker/setup-buildx-action@v2 
284420        id : buildx 
285421        with :
286422          install : true 
423+ 
287424      - name : Run Foreign toolchain test 
288425        run : ./ci/test-foreign-toolchain.sh 
289426        shell : bash 
@@ -321,7 +458,6 @@ jobs:
321458      coverage-artifact : ${{ steps.cov.outputs.artifact-name }} 
322459    steps :
323460      - uses : actions/checkout@v3 
324- 
325461      - uses : ./.github/actions/setup-rust 
326462
327463      - name : Install Podman 
@@ -348,7 +484,7 @@ jobs:
348484        shell : bash 
349485
350486  publish :
351-     needs : [build, check, fmt, clippy, cargo-deny] 
487+     needs : [build-base, build , check, fmt, clippy, cargo-deny] 
352488    runs-on : ubuntu-latest 
353489    steps :
354490      - uses : actions/checkout@v3 
@@ -359,7 +495,7 @@ jobs:
359495          github-token : ${{ secrets.GITHUB_TOKEN }} 
360496
361497  conclusion :
362-     needs : [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker, foreign, podman] 
498+     needs : [shellcheck, fmt, clippy, test, generate-matrix, build-base, build , publish, check, remote, bisect, docker-in-docker, foreign, podman] 
363499    if : always() 
364500    runs-on : ubuntu-latest 
365501    steps :
0 commit comments