name: release-5-verify-github-release

on:
  workflow_dispatch:
    inputs:
      ref:
        description: "The ref (branch or SHA) to obtain the tag"
        required: false
        type: string
  workflow_run:
    workflows:
      - release-2-cargo-publish
    types:
      - completed

defaults:
  run:
    shell: bash -xe {0}

jobs:
  verify-assets:
    name: ${{ matrix.runner }}-${{ matrix.file }}
    runs-on: ${{ matrix.runner }}
    if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - runner: ubuntu-22.04
            file: obelisk-x86_64-unknown-linux-gnu.tar.gz
          - runner: ubuntu-22.04
            file: obelisk-x86_64-unknown-linux-musl.tar.gz
          - runner: macos-14
            file: obelisk-x86_64-apple-darwin.tar.gz
          - runner: macos-14
            file: obelisk-aarch64-apple-darwin.tar.gz
    steps:
      - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
        with:
          # Use the ref if provided, otherwise obtain the parent workflow branch, defaults to main.
          ref: ${{ github.event.inputs.ref || github.event.workflow_run.head_branch }}

      - id: git-info
        run: |
          VERSION="$(grep -m1 '^version = "' Cargo.toml | cut -d'"' -f2)"
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "tag=v$VERSION" >> $GITHUB_OUTPUT
          echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

      - run: |
          mkdir temp
          cd temp
          # download the binary from GitHub Releases
          FILE="${{ matrix.file }}"
          curl --fail -L -o "$FILE" \
            https://github.com/obeli-sk/obelisk/releases/download/$TAG/$FILE
          tar xzfv "$FILE"
          ./obelisk --version | grep $VERSION
          ./obelisk server generate-config
          ./obelisk server verify
        env:
          TAG: ${{ steps.git-info.outputs.tag }}
          VERSION: ${{ steps.git-info.outputs.version }}
