From 5fd2ace5e718a02243f8a10f12d863027241e69e Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Sep 2023 00:15:47 -0400 Subject: [PATCH] CI: combine cross with docker builds --- .github/workflows/ci.yml | 79 ++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4cbda2289..3a5628b67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,42 +99,6 @@ jobs: name: build-${{ matrix.target }} path: target_releases/* - cross-build: - name: Cross-build for other platforms - runs-on: ubuntu-latest - env: - TARGETS: "aarch64-unknown-linux-musl x86_64-unknown-linux-musl" - # TODO: aarch64-unknown-linux-gnu - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@v2 - - name: Install cross - run: | - cargo install cross - # Install latest cross version from git (disabled as it is probably less stable) - # cargo install cross --git https://github.com/cross-rs/cross - cross --version - - name: Build targets - run: | - for target in $TARGETS; do - echo -e "\n----------------------------------------------" - echo "Building $target" - - export "CARGO_TARGET_$(echo $target | tr 'a-z-' 'A-Z_')_RUSTFLAGS"='-C strip=debuginfo' - cross build --release --target $target --package martin-mbtiles - cross build --release --target $target --package martin --features=vendored-openssl - - mkdir -p target_releases/$target - mv target/$target/release/mbtiles target_releases/$target - mv target/$target/release/martin target_releases/$target - done - - name: Save build artifacts to build-${{ matrix.target }} - uses: actions/upload-artifact@v3 - with: - name: cross-build - path: target_releases/* - test: name: Test ${{ matrix.target }} runs-on: ${{ matrix.os }} @@ -336,15 +300,16 @@ jobs: retention-days: 5 docker: - name: Build docker images + name: Build and test docker images runs-on: ubuntu-latest - needs: [ cross-build ] env: # PG_* variables are used by psql PGDATABASE: test PGHOST: localhost PGUSER: postgres PGPASSWORD: postgres + TARGETS: "aarch64-unknown-linux-musl x86_64-unknown-linux-musl" + # TODO: aarch64-unknown-linux-gnu services: postgres: image: postgis/postgis:15-3.3 @@ -371,6 +336,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 + - name: Install cross + run: | + cargo install cross + # Install latest cross version from git (disabled as it is probably less stable) + # cargo install cross --git https://github.com/cross-rs/cross + cross --version - name: Setup database run: tests/fixtures/initdb.sh env: @@ -388,20 +359,32 @@ jobs: install: true platforms: linux/amd64,linux/arm64 - - run: rm -rf target_releases2 - - name: Download cross-build artifacts - uses: actions/download-artifact@v3 + - name: Build targets + run: | + for target in $TARGETS; do + echo -e "\n----------------------------------------------" + echo "Building $target" + + export "CARGO_TARGET_$(echo $target | tr 'a-z-' 'A-Z_')_RUSTFLAGS"='-C strip=debuginfo' + cross build --release --target $target --package martin-mbtiles + cross build --release --target $target --package martin --features=vendored-openssl + + mkdir -p target_releases/$target + mv target/$target/release/mbtiles target_releases/$target + mv target/$target/release/martin target_releases/$target + done + + - name: Save build artifacts to build-${{ matrix.target }} + uses: actions/upload-artifact@v3 with: name: cross-build - path: target_releases_tmp - - name: Reorganize build artifacts + path: target_releases/* + - name: Reorganize artifacts for docker build run: | - chmod -R +x target_releases_tmp/ mkdir -p target_releases/linux/arm64 - mv target_releases_tmp/aarch64-unknown-linux-musl/* target_releases/linux/arm64/ + mv target_releases/aarch64-unknown-linux-musl/* target_releases/linux/arm64/ mkdir -p target_releases/linux/amd64 - mv target_releases_tmp/x86_64-unknown-linux-musl/* target_releases/linux/amd64/ - rm -rf target_releases_tmp + mv target_releases/x86_64-unknown-linux-musl/* target_releases/linux/amd64/ - name: Build linux/arm64 Docker image uses: docker/build-push-action@v5 @@ -474,7 +457,7 @@ jobs: package: name: Package ${{ matrix.target }} runs-on: ${{ matrix.os }} - needs: [ test, test-legacy, docker, cross-build ] + needs: [ test, test-legacy, docker ] strategy: fail-fast: true matrix: