stages:
- test
- build
- release
variables:
CARGO_HOME: "${CI_PROJECT_DIR}/.cargo"
test:
stage: test
image: rust:latest
cache:
key: rust-cache
paths:
- .cargo/bin/
- .cargo/registry/index/
- .cargo/registry/cache/
- .cargo/git/db/
- target/
script:
- rustup component add rustfmt clippy
- cargo fmt --check
- cargo clippy -- -D warnings
- cargo test
.build-common:
stage: build
image: rust:latest
rules:
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/'
cache:
key: rust-cache-${TARGET}
paths:
- .cargo/bin/
- .cargo/registry/index/
- .cargo/registry/cache/
- .cargo/git/db/
- target/
variables:
TARGET: ""
artifacts:
paths:
- artifacts/
build-linux-x86_64:
extends: .build-common
variables:
TARGET: x86_64-unknown-linux-musl
script:
- apt-get update && apt-get install -y musl-tools
- rustup target add x86_64-unknown-linux-musl
- cargo build --release --target x86_64-unknown-linux-musl
- mkdir -p artifacts
- cp target/x86_64-unknown-linux-musl/release/glitchtip-cli artifacts/glitchtip-cli-linux-x86_64
build-linux-arm64:
extends: .build-common
variables:
TARGET: aarch64-unknown-linux-musl
script:
- apt-get update && apt-get install -y gcc-aarch64-linux-gnu
- rustup target add aarch64-unknown-linux-musl
- cargo build --release --target aarch64-unknown-linux-musl
- mkdir -p artifacts
- cp target/aarch64-unknown-linux-musl/release/glitchtip-cli artifacts/glitchtip-cli-linux-arm64
build-windows-x86_64:
extends: .build-common
variables:
TARGET: x86_64-pc-windows-gnu
script:
- apt-get update && apt-get install -y gcc-mingw-w64-x86-64
- rustup target add x86_64-pc-windows-gnu
- cargo build --release --target x86_64-pc-windows-gnu
- mkdir -p artifacts
- cp target/x86_64-pc-windows-gnu/release/glitchtip-cli.exe artifacts/glitchtip-cli-windows-x86_64.exe
build-macos-arm64:
extends: .build-common
variables:
TARGET: aarch64-apple-darwin
script:
- test -f "${CARGO_HOME}/bin/cargo-zigbuild" || cargo install cargo-zigbuild
- export PATH="${CARGO_HOME}/bin:${PATH}"
- test -f /usr/local/bin/zig || (curl -sSf https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz | tar -xJ -C /usr/local && ln -s /usr/local/zig-linux-x86_64-0.13.0/zig /usr/local/bin/zig)
- rustup target add aarch64-apple-darwin
- cargo zigbuild --release --target aarch64-apple-darwin
- mkdir -p artifacts
- cp target/aarch64-apple-darwin/release/glitchtip-cli artifacts/glitchtip-cli-macos-arm64
publish-crates-io:
stage: release
image: rust:latest
rules:
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/'
environment:
name: crates-io
id_tokens:
CRATES_IO_ID_TOKEN:
aud: crates.io
script:
- apt-get update && apt-get install -y jq
- |
CARGO_REGISTRY_TOKEN=$(curl -s -X POST https://crates.io/api/v1/trusted_publishing/tokens \
-H "Content-Type: application/json" \
-d "{\"jwt\": \"$CRATES_IO_ID_TOKEN\"}" | jq -r '.token')
if [ "$CARGO_REGISTRY_TOKEN" = "null" ] || [ -z "$CARGO_REGISTRY_TOKEN" ]; then
echo "Failed to obtain crates.io token"
exit 1
fi
- cargo publish --token "$CARGO_REGISTRY_TOKEN"
release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/'
needs:
- job: build-linux-x86_64
artifacts: true
- job: build-linux-arm64
artifacts: true
- job: build-windows-x86_64
artifacts: true
- job: build-macos-arm64
artifacts: true
script:
- echo "Creating release for ${CI_COMMIT_TAG}"
release:
tag_name: ${CI_COMMIT_TAG}
name: "GlitchTip CLI ${CI_COMMIT_TAG}"
description: "Release ${CI_COMMIT_TAG}"
assets:
links:
- name: glitchtip-cli-linux-x86_64
url: "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_TAG}/raw/artifacts/glitchtip-cli-linux-x86_64?job=build-linux-x86_64"
- name: glitchtip-cli-linux-arm64
url: "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_TAG}/raw/artifacts/glitchtip-cli-linux-arm64?job=build-linux-arm64"
- name: glitchtip-cli-windows-x86_64.exe
url: "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_TAG}/raw/artifacts/glitchtip-cli-windows-x86_64.exe?job=build-windows-x86_64"
- name: glitchtip-cli-macos-arm64
url: "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_TAG}/raw/artifacts/glitchtip-cli-macos-arm64?job=build-macos-arm64"