midenup 1.1.0

The Miden toolchain manager
name: CI

permissions:
  contents: read

on:
  push:
    branches: [main, next]
    paths-ignore:
      - "**.md"
      - "**.txt"
      - "manifest/**"
      - "docs/**"
  pull_request:
    types: [opened, reopened, synchronize, labeled, unlabeled]
    paths-ignore:
      - "**.md"
      - "**.txt"
      - "docs/**"
env:
  # Set the new value when the cache grows too much and we hit the runner's disk space limit
  # via https://github.com/rust-lang/docs.rs/pull/2433
  RUST_CACHE_KEY: rust-cache-20260312

jobs:
  lint:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: ./.github/actions/cleanup-runner
      - &install-rust
        name: Install Rust
        run: |
          rustup update --no-self-update stable nightly
          rustup component add --toolchain nightly rustfmt
          rustc --version
      - &install-cargo-make
        name: Install cargo-make
        run: |
          if ! cargo make --version 2>/dev/null; then
            cargo install cargo-make --force
          fi
      - name: Cache Cargo
        uses: Swatinem/rust-cache@v2
        with:
          # Use a common cache for the basic compilation/formatter/clippy checks
          shared-key: ${{ github.workflow }}-shared
          prefix-key: ${{ env.RUST_CACHE_KEY }}
          save-if: ${{ github.ref == 'refs/heads/main' }}
      - name: Clippy
        run: |
          cargo make clippy

  rustfmt:
    name: rustfmt
    runs-on: ubuntu-latest
    # Run this job after the linter, so the cache is hot
    needs: [lint]
    # But run this check even if the lint check failed
    if: ${{ always() }}
    steps:
      - uses: actions/checkout@v5
      - uses: ./.github/actions/cleanup-runner
      - *install-rust
      - *install-cargo-make
      - name: Cache Cargo
        uses: Swatinem/rust-cache@v2
        with:
          # Use a common cache for the basic compilation/formatter/clippy checks
          shared-key: ${{ github.workflow }}-shared
          prefix-key: ${{ env.RUST_CACHE_KEY }}
          # But do not save this cache, just use it
          save-if: false
      - name: Formatting
        run: |
          cargo make check-format

  unit_tests:
    name: unit tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: ./.github/actions/cleanup-runner
      - *install-rust
      - *install-cargo-make
      - name: Cache Cargo
        uses: Swatinem/rust-cache@v2
        with:
          # NOTE: We use a different cache for the tests, so they can be run in parallel, but we
          # also share the cache for the tests for efficiency
          shared-key: ${{ github.workflow }}-shared-tests
          prefix-key: ${{ env.RUST_CACHE_KEY }}
          save-if: ${{ github.ref == 'refs/heads/main' }}
      - uses: taiki-e/install-action@nextest
      - name: Check
        # We run `cargo check` to verify that the workspace compiles correctly before attempting
        # to execute the tests from each crate. This produces easier to read output if a compilation
        # error occurs
        run: cargo make test-build
      - name: Test
        run: cargo make unit-test

  integration_test:
    name: integration tests
    # We only want to run the integration tests if the unit tests pass, and that has the added
    # benefit that we can re-use the cache from the unit test job for all integration tests
    needs: [unit_tests]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: ./.github/actions/cleanup-runner
      - *install-rust
      - *install-cargo-make
      - name: Install all rustup toolchains present in the manifest
        run: |
          ./.github/auxiliary_scripts/install-toolchains.sh
      - name: Cache Cargo
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: ${{ github.workflow }}-shared-tests
          prefix-key: ${{ env.RUST_CACHE_KEY }}
          # Do not persist the cache, leave that to the unit tests, we just use the cache here
          save-if: false
      - uses: taiki-e/install-action@nextest
      - name: Check
        # We run `cargo check` to verify that the workspace compiles correctly before attempting
        # to execute the tests from each crate. This produces easier to read output if a compilation
        # error occurs
        run: cargo make test-build
      - name: Test
        run: cargo make integration-test
      - name: Pre-release checks
        # These install real components from this repo's copy of the manifest and run them, so it
        # takes many minutes. Run them on main or on explicitly labelled PRs
        if: ${{ github.ref_name == 'main' || contains(github.event.pull_request.labels.*.name, 'check:install') }}
        run: cargo make prerelease-test