name: Rust CI and Release
on:
pull_request:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
jobs:
ci:
if: github.event_name == 'pull_request' || (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 - name: Format
run: cargo fmt --check
- name: Clippy
run: cargo clippy --all-targets --locked -- -D warnings
- name: Test
run: cargo test --all-targets --locked
- name: Rustdoc
run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --locked
- name: CLI help smoke
run: |
cargo run --locked -- --help
cargo run --locked -- run --help
cargo run --locked -- chat --help
cargo run --locked -- audit --help | tee /tmp/oy-audit-help.txt
grep -F -- "--max-chunks <N>" /tmp/oy-audit-help.txt
cargo run --locked -- model --help
cargo run --locked -- doctor --help
- name: Documentation drift checks
run: |
! grep -R -n -E 'src/(app|chat|config|model|session|ui)\.rs' README.md CONTRIBUTING.md docs
- name: Package crate
run: cargo package --locked
release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.repository_owner == 'wagov-dtt'
name: Release (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive: tar.gz
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
archive: tar.gz
- os: macos-14
target: aarch64-apple-darwin
archive: tar.gz
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 with:
targets: ${{ matrix.target }}
- name: Build size-optimized release binary
env:
RUSTFLAGS: -C debuginfo=0
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Strip binary
shell: bash
run: |
if [[ "${{ runner.os }}" == "macOS" ]]; then
strip target/${{ matrix.target }}/release/oy
else
strip --strip-all target/${{ matrix.target }}/release/oy
fi
- name: Package
shell: bash
env:
REF_NAME: ${{ github.ref_name }}
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/oy dist/oy
tar -C dist -czf "oy-${REF_NAME}-${{ matrix.target }}.tar.gz" oy
- name: Upload artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a with:
name: oy-${{ github.ref_name }}-${{ matrix.target }}
path: oy-${{ github.ref_name }}-${{ matrix.target }}.${{ matrix.archive }}
if-no-files-found: error
publish-release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.repository_owner == 'wagov-dtt'
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
attestations: write
steps:
- name: Download artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c with:
path: dist
merge-multiple: true
- name: Attest release assets
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 with:
subject-path: dist/*
- name: Create draft GitHub release with assets
env:
GH_TOKEN: ${{ github.token }}
REF_NAME: ${{ github.ref_name }}
REPOSITORY: ${{ github.repository }}
SHA: ${{ github.sha }}
run: |
gh release create "${REF_NAME}" dist/* \
--repo "${REPOSITORY}" \
--draft \
--target "${SHA}" \
--title "${REF_NAME}" \
--notes "Rust release ${REF_NAME}."
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
REF_NAME: ${{ github.ref_name }}
REPOSITORY: ${{ github.repository }}
run: gh release edit "${REF_NAME}" --repo "${REPOSITORY}" --draft=false
publish-crate:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.repository_owner == 'wagov-dtt'
needs: release
runs-on: ubuntu-latest
environment: crates-io
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 - name: Verify crate package
run: cargo package --locked
- name: Authenticate with crates.io
id: auth
uses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe - name: Publish crate to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --locked