name: Solana V3 no-value rehearsal

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: solana-v3-rehearsal-${{ github.ref }}
  cancel-in-progress: true

jobs:
  source-gates:
    name: Source, lifecycle, and release gates
    runs-on: ubuntu-24.04
    timeout-minutes: 10
    steps:
      - name: Checkout exact candidate
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Use pinned Node major
        uses: actions/setup-node@v4
        with:
          node-version: "20"

      - name: Run disposition, source, and rehearsal gates
        run: npm run test:rehearsal
        env:
          REQUIRE_COMMITTED_CANDIDATE: "1"
          EXPECTED_CANDIDATE_COMMIT: ${{ github.sha }}

      - name: Prove deployment remains blocked
        shell: bash
        run: |
          set +e
          node scripts/deploy-blocked.mjs
          status=$?
          set -e
          test "$status" -eq 1

  sbf-local-validator:
    name: Six-candidate SBF build and immutable local-validator preload
    needs: source-gates
    runs-on: ubuntu-24.04
    timeout-minutes: 45
    container:
      image: solanafoundation/anchor:v0.32.1
    steps:
      - name: Checkout exact candidate
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Execute the complete no-value rehearsal
        run: sh scripts/ci-rehearsal.sh
        env:
          LOCAL_RPC_URL: http://127.0.0.1:8899
          REQUIRE_COMMITTED_CANDIDATE: "1"
          EXPECTED_CANDIDATE_COMMIT: ${{ github.sha }}

      - name: Retain checksummed SBF evidence
        uses: actions/upload-artifact@v4
        with:
          name: solana-v3-sbf-${{ github.sha }}
          if-no-files-found: error
          retention-days: 14
          path: |
            artifacts/sbf/*.so
            artifacts/rehearsal/local-validator-evidence.json
            checksums/sbf-sha256.txt
            checksums/sbf-manifest.json
