Experimenting with CI cross build2 #3160
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
paths-ignore: | |
- '**.md' | |
- 'demo/**' | |
- 'docs/**' | |
release: | |
types: [ published ] | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
lint-debug-test: | |
name: Lint and Unit test | |
runs-on: ubuntu-latest | |
env: | |
PGDATABASE: test | |
PGHOST: localhost | |
PGUSER: postgres | |
PGPASSWORD: postgres | |
services: | |
postgres: | |
image: postgis/postgis:16-3.4 | |
ports: | |
# will assign a random free host port | |
- 5432/tcp | |
# Sadly there is currently no way to pass arguments to the service image other than this hack | |
# See also https://stackoverflow.com/a/62720566/177275 | |
options: >- | |
-e POSTGRES_DB=test | |
-e POSTGRES_USER=postgres | |
-e POSTGRES_PASSWORD=postgres | |
-e PGDATABASE=test | |
-e PGUSER=postgres | |
-e PGPASSWORD=postgres | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
--entrypoint sh | |
postgis/postgis:16-3.4 | |
-c "exec docker-entrypoint.sh postgres -c ssl=on -c ssl_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem -c ssl_key_file=/etc/ssl/private/ssl-cert-snakeoil.key" | |
steps: | |
- uses: taiki-e/install-action@v2 | |
with: { tool: just } | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
- uses: Swatinem/rust-cache@v2 | |
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' | |
- run: just env-info | |
- run: just fmt | |
- run: just clippy | |
- run: just check | |
- run: just check-doc | |
- name: Check semver | |
uses: obi1kenobi/cargo-semver-checks-action@v2 | |
- name: Init database | |
run: tests/fixtures/initdb.sh | |
env: | |
PGPORT: ${{ job.services.postgres.ports[5432] }} | |
- name: Run cargo test | |
run: | | |
set -x | |
cargo test --package martin-tile-utils | |
cargo test --package mbtiles --no-default-features | |
cargo test --package mbtiles | |
cargo test --package martin | |
cargo test --doc | |
env: | |
DATABASE_URL: postgres://${{ env.PGUSER }}:${{ env.PGUSER }}@${{ env.PGHOST }}:${{ job.services.postgres.ports[5432] }}/${{ env.PGDATABASE }}?sslmode=require | |
docker-build-test: | |
name: Build and test docker images | |
runs-on: ubuntu-latest | |
env: | |
# PG_* variables are used by psql | |
PGDATABASE: test | |
PGHOST: localhost | |
PGUSER: postgres | |
PGPASSWORD: postgres | |
# TODO: aarch64-unknown-linux-gnu | |
services: | |
postgres: | |
image: postgis/postgis:15-3.3 | |
ports: | |
- 5432/tcp | |
options: >- | |
-e POSTGRES_DB=test | |
-e POSTGRES_USER=postgres | |
-e POSTGRES_PASSWORD=postgres | |
-e PGDATABASE=test | |
-e PGUSER=postgres | |
-e PGPASSWORD=postgres | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
--entrypoint sh | |
postgis/postgis:15-3.3 | |
-c "exec docker-entrypoint.sh postgres -c ssl=on -c ssl_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem -c ssl_key_file=/etc/ssl/private/ssl-cert-snakeoil.key" | |
steps: | |
- uses: taiki-e/install-action@v2 | |
with: { tool: cross } | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
with: | |
set-safe-directory: false | |
- uses: Swatinem/rust-cache@v2 | |
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' | |
- name: Init database | |
run: tests/fixtures/initdb.sh | |
env: | |
PGPORT: ${{ job.services.postgres.ports[5432] }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# https://github.com/docker/setup-qemu-action | |
with: | |
platforms: linux/amd64,linux/arm64 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# https://github.com/docker/setup-buildx-action | |
with: | |
install: true | |
platforms: linux/amd64,linux/arm64 | |
- name: Set up AWS SAM | |
uses: aws-actions/setup-sam@v2 | |
with: | |
use-installer: true | |
- name: Build targets | |
run: | | |
for target in "aarch64-unknown-linux-musl" "x86_64-unknown-linux-musl"; 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 --workspace | |
mkdir -p target_releases/$target | |
mv target/$target/release/martin target_releases/$target | |
mv target/$target/release/martin-cp target_releases/$target | |
mv target/$target/release/mbtiles target_releases/$target | |
done | |
- name: Save build artifacts to build-${{ matrix.target }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cross-build | |
path: target_releases/* | |
- name: Reorganize artifacts for docker build | |
run: | | |
mkdir -p target_releases/linux/arm64 | |
mv target_releases/aarch64-unknown-linux-musl/* target_releases/linux/arm64/ | |
mkdir -p target_releases/linux/amd64 | |
mv target_releases/x86_64-unknown-linux-musl/* target_releases/linux/amd64/ | |
- name: Start NGINX | |
uses: nyurik/[email protected] | |
id: nginx | |
with: { port: '5412', output-unix-paths: 'yes' } | |
- name: Copy static files | |
run: cp -r tests/fixtures/pmtiles2/* ${{ steps.nginx.outputs.html-dir }} | |
- name: Build linux/arm64 Docker image | |
uses: docker/build-push-action@v6 | |
# https://github.com/docker/build-push-action | |
with: | |
context: . | |
file: .github/files/multi-platform.Dockerfile | |
load: true | |
tags: ${{ github.repository }}:linux-arm64 | |
platforms: linux/arm64 | |
- name: Test linux/arm64 Docker image | |
run: | | |
PLATFORM=linux/arm64 | |
TAG=${{ github.repository }}:linux-arm64 | |
export MARTIN_BUILD_ALL=- | |
export MARTIN_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests $TAG" | |
export MARTIN_CP_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests --entrypoint /usr/local/bin/martin-cp $TAG" | |
export MBTILES_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests --entrypoint /usr/local/bin/mbtiles $TAG" | |
tests/test.sh | |
env: | |
DATABASE_URL: postgres://${{ env.PGUSER }}:${{ env.PGUSER }}@${{ env.PGHOST }}:${{ job.services.postgres.ports[5432] }}/${{ env.PGDATABASE }}?sslmode=require | |
- name: Build linux/amd64 Docker image | |
uses: docker/build-push-action@v6 | |
# https://github.com/docker/build-push-action | |
with: | |
context: . | |
file: .github/files/multi-platform.Dockerfile | |
load: true | |
tags: ${{ github.repository }}:linux-amd64 | |
platforms: linux/amd64 | |
- name: Test linux/amd64 Docker image | |
run: | | |
PLATFORM=linux/amd64 | |
TAG=${{ github.repository }}:linux-amd64 | |
export MARTIN_BUILD_ALL=- | |
export MARTIN_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests $TAG" | |
export MARTIN_CP_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests --entrypoint /usr/local/bin/martin-cp $TAG" | |
export MBTILES_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests --entrypoint /usr/local/bin/mbtiles $TAG" | |
tests/test.sh | |
env: | |
DATABASE_URL: postgres://${{ env.PGUSER }}:${{ env.PGUSER }}@${{ env.PGHOST }}:${{ job.services.postgres.ports[5432] }}/${{ env.PGDATABASE }}?sslmode=require | |
- name: Login to GitHub Docker registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
# https://github.com/docker/login-action | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker meta | |
id: docker_meta | |
uses: docker/metadata-action@v5 | |
# https://github.com/docker/metadata-action | |
with: | |
images: ghcr.io/${{ github.repository }} | |
- name: Push the Docker image | |
if: github.event_name != 'pull_request' | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: .github/files/multi-platform.Dockerfile | |
push: true | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 |