Build, test and release with cargo: CI, release workflow, cross-build and packaging scripts, Homebrew

This commit is contained in:
Andy Dixon
2026-10-08 19:54:56 +01:00
parent 507f635b49
commit ce8acf0ade
14 changed files with 335 additions and 118 deletions
+16
View File
@@ -0,0 +1,16 @@
name: cross-tools
description: Rust targets, zig, cargo-zigbuild and cross for scripts/build.sh
runs:
using: composite
steps:
- shell: bash
run: |
rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl i686-unknown-linux-musl \
armv7-unknown-linux-musleabihf riscv64gc-unknown-linux-musl x86_64-pc-windows-gnu \
aarch64-pc-windows-gnullvm x86_64-unknown-freebsd x86_64-unknown-netbsd
curl -sSLo zig.tar.xz https://ziglang.org/download/0.16.0/zig-x86_64-linux-0.16.0.tar.xz
echo "70e49664a74374b48b51e6f3fdfbf437f6395d42509050588bd49abe52ba3d00 zig.tar.xz" | sha256sum -c
mkdir -p "$HOME/zig" && tar -xJf zig.tar.xz -C "$HOME/zig" --strip-components=1 && rm zig.tar.xz
echo "$HOME/zig" >>"$GITHUB_PATH"
cargo install cargo-zigbuild --version 0.23.4 --locked
cargo install cross --version 0.2.5 --locked
+26 -17
View File
@@ -4,29 +4,38 @@ on:
pull_request:
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
lint:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- run: rustup component add rustfmt clippy
- run: cargo fmt --check
- run: cargo clippy --locked --all-targets -- -D warnings
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-15, macos-15-intel, windows-2025]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: format
if: runner.os == 'Linux'
run: test -z "$(gofmt -l .)"
- run: go vet ./...
- run: go test ./...
- name: race
if: runner.os != 'Windows'
run: go test -race ./...
- name: cross-build
if: runner.os == 'Linux'
- uses: actions/checkout@v5
- run: cargo test --release --locked --all-targets
- run: cargo run --release --locked -- --no-ui .
cross:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/cross-tools
- name: every target but macOS (built natively by the test job)
run: TARGETS="linux/amd64 linux/arm64 linux/386 linux/arm linux/riscv64 windows/amd64 windows/arm64 freebsd/amd64 netbsd/amd64" scripts/build.sh
- name: static binaries run under qemu
run: |
for t in linux/arm64 linux/386 darwin/arm64 windows/amd64 freebsd/amd64; do
GOOS=${t%/*} GOARCH=${t#*/} CGO_ENABLED=0 go build -o /dev/null ./cmd/mapsize
sudo apt-get update -q && sudo apt-get install -yq qemu-user
for t in "arm64 qemu-aarch64" "arm qemu-arm" "riscv64 qemu-riscv64"; do
${t#* } dist/mapsize-linux-${t%% *} --no-ui src >/dev/null
done
+46
View File
@@ -0,0 +1,46 @@
# On a version tag: build every target, package, and publish a GitHub
# release whose notes are the tag's CHANGELOG.md section.
name: release
on:
push:
tags: ["v*"]
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
build-cross:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/cross-tools
- run: TARGETS="linux/amd64 linux/arm64 linux/386 linux/arm linux/riscv64 windows/amd64 windows/arm64 freebsd/amd64 netbsd/amd64" scripts/build.sh
- uses: actions/upload-artifact@v4
with: {name: bin-cross, path: dist/mapsize-*}
build-macos:
runs-on: macos-15
steps:
- uses: actions/checkout@v5
- run: rustup target add x86_64-apple-darwin aarch64-apple-darwin
- run: TARGETS="darwin/amd64 darwin/arm64" scripts/build.sh
- uses: actions/upload-artifact@v4
with: {name: bin-macos, path: dist/mapsize-*}
publish:
needs: [build-cross, build-macos]
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v4
with: {path: dist, merge-multiple: true}
- run: scripts/release.sh "$GITHUB_REF_NAME" dist dist/release
- name: release
env:
GH_TOKEN: ${{ github.token }}
run: |
v=${GITHUB_REF_NAME#v}
awk -v h="## $v" 'index($0, h) == 1 {f=1; next} /^## /{f=0} f' CHANGELOG.md >notes.md
gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes-file notes.md dist/release/*