name: enos-release-testing-oss

on:
  repository_dispatch:
    types:
      - enos-release-testing-oss
      - enos-release-testing-oss::*

jobs:
  product-metadata:
    if: ${{ startsWith(github.event.client_payload.payload.branch, 'release/') }}
    runs-on: ubuntu-latest
    outputs:
      matrix-test-group: ${{ steps.get-metadata.outputs.matrix-test-group }}
      vault-revision: ${{ steps.get-metadata.outputs.vault-revision }}
      vault-version: ${{ steps.get-metadata.outputs.vault-version }}
    steps:
      - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
        with:
          # Check out the repository at the same Git SHA that was used to create
          # the artifacts to get the correct metadata.
          ref: ${{ github.event.client_payload.payload.sha }}
      - id: get-metadata
        env:
          # MATRIX_MAX_TEST_GROUPS is required to determine the randomly selected
          # test group. It should be set to the highest test_group used in the
          # enos-run-matrices.
          MATRIX_MAX_TEST_GROUPS: 2
        run: |
          # shellcheck disable=SC2129
          echo "matrix-test-group=$(make ci-get-matrix-group-id)" >> "$GITHUB_OUTPUT"
          echo "vault-revision=$(make ci-get-revision)" >> "$GITHUB_OUTPUT"
          echo "vault-version=$(make ci-get-version)" >> "$GITHUB_OUTPUT"
        # Get the workflow summary similar to CRT workflows
      - name: Release Artifact Info
        run: |
          # shellcheck disable=SC2129
          echo "__Product:__ ${{ github.event.client_payload.payload.product }}" >> "$GITHUB_STEP_SUMMARY"
          echo "__Version:__ ${{ github.event.client_payload.payload.version }}" >> "$GITHUB_STEP_SUMMARY"
          echo "__Commit:__ ${{ github.event.client_payload.payload.sha }}" >> "$GITHUB_STEP_SUMMARY"
          echo "" >> "$GITHUB_STEP_SUMMARY"
          echo "[Build Workflow](https://github.com/${{github.event.client_payload.payload.org}}/${{github.event.client_payload.payload.repo}}/actions/runs/${{github.event.client_payload.payload.buildworkflowid}})" >> "$GITHUB_STEP_SUMMARY"

  test:
    name: Test ${{ matrix.build-artifact-name }}
    if: ${{ startsWith(github.event.client_payload.payload.branch, 'release/') }}
    needs: product-metadata
    uses: ./.github/workflows/test-run-enos-scenario-matrix.yml
    strategy:
      fail-fast: false
      matrix:
        include:
          - matrix-file-name: enos_release_testing_oss-artifactory-oss-linux-amd64-zip
            build-artifact-name: vault_${{ needs.product-metadata.outputs.vault-version }}_linux_amd64.zip
          - matrix-file-name: enos_release_testing_oss-artifactory-oss-linux-arm64-zip
            build-artifact-name: vault_${{ needs.product-metadata.outputs.vault-version }}_linux_arm64.zip
    with:
      build-artifact-name: ${{ matrix.build-artifact-name }}
      matrix-file-name: ${{ matrix.matrix-file-name }}
      matrix-test-group: ${{ needs.product-metadata.outputs.matrix-test-group }}
      vault-edition: oss
      vault-revision: ${{ needs.product-metadata.outputs.vault-revision }}
    secrets: inherit

  save-metadata:
    runs-on: linux
    needs: test
    steps:
      - name: Persist metadata
        uses: hashicorp/actions-persist-metadata@v1
