midenup 1.1.0

The Miden toolchain manager
name: Test installer

on:
  merge_group:
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
    paths:
      - bin/installer.sh
      - .github/workflows/installer.yml
      - .github/workflows/release.yml
  push:
    branches:
      - main
    paths:
      - bin/installer.sh
      - .github/workflows/installer.yml
      - .github/workflows/release.yml

concurrency:
  group: ${{ github.workflow }}-${{ github.ref || github.event.pull_request.number || github.sha }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

permissions:
  contents: read
  artifact-metadata: read

jobs:
  unix:
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, ubuntu-latest]
        set_cargo_home: [t, f]
        set_install_version: ['no', 'with-v', 'without-v']

    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1

      - name: Set `CARGO_HOME`
        if: matrix.set_cargo_home == 't'
        run: |
          CARGO_HOME="$(mktemp -d 2>/dev/null || mktemp -d -t 'cargo-home')"
          mkdir -p "${CARGO_HOME}/bin"
          echo "CARGO_HOME=$CARGO_HOME" >> "$GITHUB_ENV"

      - name: Pass `--version`
        if: matrix.set_install_version != 'no'
        env:
          STRIP_V: ${{ matrix.set_install_version }}
          GH_TOKEN: ${{ github.token }}
        run: |
          # fetch most recent release tag.
          INSTALL_VERSION="$(gh release list --json name --jq '[.[] | select(.name | startswith("v")) | .name] | first')"
          if [[ $STRIP_V == 'without-v' ]]; then INSTALL_VERSION="${INSTALL_VERSION#v*}"; fi
          echo "Setting INSTALL_VERSION=$INSTALL_VERSION"
          echo "INSTALL_VERSION=$INSTALL_VERSION" >> "$GITHUB_ENV"

      - name: Install `midenup` using scripts
        run: |
            if [[ -z "${INSTALL_VERSION:-}" ]]; then
                bin/installer.sh
            else
                bin/installer.sh --version "${INSTALL_VERSION}"
            fi
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Verify `midenup` installation
        run: |
          which midenup
          midenup --version

      # Exercise the opt-out flags: the binary must land in the requested directory, no
      # verification may run, and `midenup init` must not create MIDENUP_HOME.
      - name: Install with all opt-out flags
        run: |
          install_path="$(mktemp -d 2>/dev/null || mktemp -d -t 'install-path')"
          export MIDENUP_HOME="${RUNNER_TEMP}/no-init-home"
          bin/installer.sh --install-path "${install_path}" --no-init --no-verify --ignore-attestation --no-cargo-fallback 2>&1 | tee "${RUNNER_TEMP}/installer.log"
          test -x "${install_path}/midenup"
          if grep -q 'Verifying' "${RUNNER_TEMP}/installer.log"; then echo "verification ran despite opt-out flags"; exit 1; fi
          if [ -e "${MIDENUP_HOME}" ]; then echo "init ran despite --no-init"; exit 1; fi

  # Dummy job to have a stable name for the "all tests pass" requirement
  tests-pass:
    name: Install scripts test pass
    needs:
      - unix
    if: always() # always run even if dependencies fail
    runs-on: ubuntu-latest
    steps:
      # fail if ANY dependency has failed or cancelled
      - if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')"
        run: exit 1
      - run: exit 0