name: Test Conformance Suite
description: Runs pytest against conformance suite runner using given inputs. Adds logs to workflow run.
inputs:
  name:
    description: Name of the conformance suite to run
    required: true
  python_version:
    description: Python version to use
    required: true
  shard:
    description: Optional selection of shards to run (e.g. "0", "0-3")
    required: false
  short_name:
    description: Optional shortened version of name for compact display (defaults to `name`)
    required: false

runs:
  using: composite
  steps:
    - name: Checkout EDGAR
      if: ${{ inputs.name == 'efm_current' }}
      uses: actions/checkout@v4.1.7
      with:
        repository: Arelle/EDGAR
        path: arelle/plugin/EDGAR
    - name: Install Python 3
      uses: actions/setup-python@v5.2.0
      with:
        cache: 'pip'
        check-latest: true
        python-version: ${{ inputs.python_version }}
    - name: Install dependencies
      shell: bash
      run: |
        python -m pip install --upgrade pip setuptools wheel
        pip install -r requirements-test.txt
    - name: Run integration tests with pytest
      shell: bash
      run: |
        pytest -s --disable-warnings \
        --junitxml=conf-junit.xml \
        --offline \
        --log-to-file \
        --download-missing \
        --download-private \
        --download-cache \
        --name=${{ inputs.name }}${{ inputs.shard && format(' --shard={0}', inputs.shard) || '' }} \
        tests/integration_tests/validation/test_conformance_suites.py
    - name: Cat logs
      if: always()
      shell: bash
      run: tail -n+1 conf-*log.txt
    - id: build-artifact-name
      if: always()
      shell: bash
      run: |
        printf 'artifact-name=%s%s %s %s logs' "${{ inputs.short_name || inputs.name }}" "${{ inputs.shard && format(' {0}', inputs.shard) || '' }}" "${{ runner.os }}" "${{ inputs.python_version }}" >> $GITHUB_OUTPUT
    - name: Upload logs and reports
      if: always()
      uses: actions/upload-artifact@v4.4.0
      with:
        name: ${{ steps.build-artifact-name.outputs.artifact-name }}
        if-no-files-found: error
        path: 'conf-*'
