name: Non-routine release validation

on:
  workflow_dispatch:
  push:
    tags:
      - "v*"

concurrency:
  group: release-${{ github.ref }}
  cancel-in-progress: true

jobs:
  release:
    runs-on: ubuntu-latest
    timeout-minutes: 120
    env:
      CARGO_BUILD_JOBS: "2"
      CARGO_INCREMENTAL: "0"
      RUSTDOCFLAGS: "-D warnings"
      OPENJPEG_PREFIX: ${{ runner.tool_cache }}/metacrate/native/openjpeg-2.5.4-${{ runner.arch }}
      PKG_CONFIG_PATH: ${{ runner.tool_cache }}/metacrate/native/openjpeg-2.5.4-${{ runner.arch }}/lib/pkgconfig
      LD_LIBRARY_PATH: ${{ runner.tool_cache }}/metacrate/native/openjpeg-2.5.4-${{ runner.arch }}/lib
      METACRATE_RUST_COMMIT: ${{ github.sha }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            ${{ runner.tool_cache }}/metacrate/native
            target/release-gate
          key: release-rust-1.97.1-${{ runner.arch }}-${{ hashFiles('.gitea/workflows/release.yml', 'Cargo.lock', 'ci/ci-coverage.json', 'ci/release-matrix.json', 'ci/artifact-policy.json', 'tools/install_openjpeg_2_5_4.sh') }}
      - name: Install the release prerequisite set once
        run: |
          sudo apt-get update
          sudo apt-get install --yes build-essential clang cmake curl git mingw-w64 ninja-build pkg-config python3 libfontconfig1-dev libfreetype6-dev libopus-dev libasound2-dev
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: 1.97.1
          components: clippy,rustfmt
          targets: x86_64-pc-windows-gnu,x86_64-apple-darwin
      - name: Validate the native release dependency
        run: tools/install_openjpeg_2_5_4.sh "$OPENJPEG_PREFIX"
      - name: Run the Rust-owned non-routine release graph
        run: cargo run --locked -p metacrate-ci-matrix -- release-gate --evidence artifacts/release/release-gate.json
      - name: Upload release evidence and packages
        if: always()
        uses: actions/upload-artifact@v3
        with:
          name: non-routine-release-evidence
          path: |
            artifacts/release/
            target/release-gate/package/*.crate
          if-no-files-found: error
