name: Verahelm change gate

on:
  pull_request_target:

permissions:
  contents: read

jobs:
  verify:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Check out the proposed revision without credentials
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          persist-credentials: false
      - name: Bind expected pull-request subject
        id: subject
        env:
          SUBJECT_ID: ${{ github.repository }}
          SUBJECT_REVISION: ${{ github.event.pull_request.head.sha }}
        run: printf 'version=sha256:%s\n' "$(printf '%s' \"$SUBJECT_ID@$SUBJECT_REVISION\" | sha256sum | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
      - name: Verify Decision Envelope
        uses: Verahelm/verahelm-decision-envelope@63590721d2c518e42ced1edb34bde754cf126d0a
        with:
          envelope: decision-envelope.json
          public-key: decision-envelope-public-key.json
          public-key-sha256: ${{ vars.VERAHELM_PUBLIC_KEY_SHA256 }}
          subject-id: ${{ github.repository }}
          subject-version: ${{ steps.subject.outputs.version }}
          authority-id: ${{ vars.VERAHELM_AUTHORITY_ID }}
          scope-environment: ${{ vars.VERAHELM_SCOPE_ENVIRONMENT }}
          scope-change: pull-request-${{ github.event.pull_request.number }}
