name: Run Xbrl Conformance Suites

on:
  workflow_dispatch:
  pull_request_target:
    paths:
      - '.github/workflows/conformance-suites.yml'
      - 'arelle/**'
      - 'tests/**'
      - '**.py'
      - '**.pyw'
      - 'requirements*.txt'

permissions: {}

jobs:
  find-tests:
    runs-on: ubuntu-24.04
    outputs:
      matrix: ${{ steps.build-test-matrix.outputs.matrix }}
    steps:
      - uses: actions/checkout@v4.1.7
        with:
          persist-credentials: false
          ref: ${{ github.event.pull_request.head.sha }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
      - id: build-test-matrix
        run: |
          echo 'matrix<<EOF' >> $GITHUB_OUTPUT
          python -m tests.integration_tests.validation.discover_tests | tee -a $GITHUB_OUTPUT
          echo EOF >> $GITHUB_OUTPUT

  run-conformance-suite:
    name: ${{ matrix.test.short_name }}${{ matrix.test.shard && format(':{0}', matrix.test.shard) || '' }} - ${{ matrix.test.os }} - ${{ matrix.test.python_version }}
    needs: find-tests
    runs-on: ${{ matrix.test.os }}
    strategy:
      fail-fast: false
      matrix:
        test: ${{ fromJson(needs.find-tests.outputs.matrix) }}
    environment: ${{ matrix.test.environment }}
    steps:
      - uses: actions/checkout@v4.1.7
        with:
          persist-credentials: false
          ref: ${{ github.event.pull_request.head.sha }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
      - name: Configure AWS Credentials
        if: ${{ matrix.test.environment == 'integration-tests' }}
        uses: aws-actions/configure-aws-credentials@v4.0.2
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
          aws-region: us-east-1
      - name: Test Conformance Suite
        uses: ./.github/actions/test_conformance_suite
        with:
          name: ${{ matrix.test.name }}
          python_version: ${{ matrix.test.python_version }}
          shard: ${{ matrix.test.shard }}
          short_name: ${{ matrix.test.short_name }}
