add better group (#573) #2733
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: GPU Tests | |
| on: | |
| workflow_dispatch: | |
| issue_comment: | |
| types: [created] | |
| push: | |
| branches: [main] | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| # Cancel the job if new commits are pushed | |
| # https://stackoverflow.com/questions/66335225/how-to-cancel-previous-runs-in-the-pr-when-you-push-new-commitsupdate-the-curre | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.event.issue.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| set-pending: | |
| name: GPU Tests Pending | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| statuses: write | |
| steps: | |
| - name: Set pending status on PR | |
| run: | | |
| for context in "CI-Pass" "All Tests Green"; do | |
| gh api repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \ | |
| -f state=pending \ | |
| -f context="$context" \ | |
| -f description="Waiting for /test-gpu command..." | |
| done | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| check: | |
| runs-on: ubuntu-latest | |
| # Skip pull_request (handled by set-pending) and issue_comment unless /test-gpu | |
| if: >- | |
| github.event_name != 'pull_request' && ( | |
| github.event_name != 'issue_comment' || | |
| (github.event.issue.pull_request && startsWith(github.event.comment.body, '/test-gpu')) | |
| ) | |
| outputs: | |
| head-sha: ${{ steps.get-sha.outputs.sha }} | |
| permissions: | |
| pull-requests: write | |
| statuses: write | |
| steps: | |
| - name: Check permissions | |
| if: github.event_name == 'issue_comment' || github.event_name == 'workflow_dispatch' | |
| run: | | |
| PERMISSION=$(gh api repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission --jq '.permission') | |
| if [[ "$PERMISSION" != "admin" && "$PERMISSION" != "maintain" ]]; then | |
| echo "::error::Only maintainers or admins can trigger this workflow. Your permission: $PERMISSION" | |
| exit 1 | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: React to comment | |
| if: github.event_name == 'issue_comment' | |
| run: | | |
| gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content=rocket | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get PR head SHA | |
| id: get-sha | |
| if: github.event_name == 'issue_comment' | |
| run: | | |
| SHA=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefOid -q .headRefOid) | |
| echo "sha=$SHA" >> $GITHUB_OUTPUT | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set pending status on PR | |
| if: github.event_name == 'issue_comment' | |
| run: | | |
| for context in "CI-Pass" "All Tests Green"; do | |
| gh api repos/${{ github.repository }}/statuses/${{ steps.get-sha.outputs.sha }} \ | |
| -f state=pending \ | |
| -f context="$context" \ | |
| -f description="GPU tests running..." \ | |
| -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| done | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| get-envs: | |
| runs-on: ubuntu-latest | |
| needs: check | |
| outputs: | |
| stable-dev: ${{ steps.get-envs.outputs.stable-dev }} | |
| prerelease: ${{ steps.get-envs.outputs.prerelease }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| filter: blob:none | |
| fetch-depth: 0 | |
| ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || '' }} | |
| - uses: astral-sh/setup-uv@v6 | |
| with: | |
| enable-cache: false | |
| - id: get-envs | |
| run: | | |
| # Stable and dev environments | |
| STABLE_DEV_JSON=$(uvx hatch env show --json | jq -c ' | |
| to_entries | |
| | map( | |
| select(.key | startswith("hatch-test") and endswith("12") and (contains("prerelease") | not)) | |
| | { | |
| name: .key, | |
| python: .value.python | sub("3[.]13"; "3.13.3"), | |
| } | |
| )') | |
| echo "stable-dev=${STABLE_DEV_JSON}" | tee -a $GITHUB_OUTPUT | |
| # Prerelease environments | |
| PRERELEASE_JSON=$(uvx hatch env show --json | jq -c ' | |
| to_entries | |
| | map( | |
| select(.key | startswith("hatch-test") and endswith("12") and contains("prerelease")) | |
| | { | |
| name: .key, | |
| python: .value.python | sub("3[.]13"; "3.13.3"), | |
| } | |
| )') | |
| echo "prerelease=${PRERELEASE_JSON}" | tee -a $GITHUB_OUTPUT | |
| test-stable-dev: | |
| name: Test (${{ matrix.env.name }}) | |
| needs: get-envs | |
| runs-on: cirun-aws-gpu | |
| timeout-minutes: 30 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| env: ${{ fromJson(needs.get-envs.outputs.stable-dev) }} | |
| env: | |
| ENV_NAME: ${{ matrix.env.name }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| filter: blob:none | |
| ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || '' }} | |
| - uses: astral-sh/setup-uv@v6 | |
| with: | |
| python-version: ${{ matrix.env.python }} | |
| - name: Install dependencies | |
| run: uvx hatch -v env create ${{ matrix.env.name }} | |
| - name: Run tests | |
| run: | | |
| mkdir -p test-data | |
| if [[ "${{ matrix.env.name }}" == *"stable"* ]]; then | |
| uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes | |
| uvx hatch run ${{ matrix.env.name }}:coverage xml | |
| uvx hatch run ${{ matrix.env.name }}:cov-report | |
| else | |
| uvx hatch run ${{ matrix.env.name }}:run -v --color=yes | |
| fi | |
| - name: Upload test results | |
| if: ${{ !cancelled() && contains(matrix.env.name, 'stable') }} | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| report_type: test_results | |
| files: test-data/test-results.xml | |
| use_oidc: false | |
| fail_ci_if_error: false | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| - name: Upload coverage data | |
| if: contains(matrix.env.name, 'stable') | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| files: test-data/coverage.xml | |
| use_oidc: false | |
| fail_ci_if_error: false | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| test-prerelease: | |
| name: Test (${{ matrix.env.name }}) | |
| needs: get-envs | |
| runs-on: cirun-aws-gpu | |
| timeout-minutes: 30 | |
| continue-on-error: true # Prerelease failures don't fail the workflow | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| env: ${{ fromJson(needs.get-envs.outputs.prerelease) }} | |
| env: | |
| ENV_NAME: ${{ matrix.env.name }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| filter: blob:none | |
| ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || '' }} | |
| - uses: astral-sh/setup-uv@v6 | |
| with: | |
| python-version: ${{ matrix.env.python }} | |
| - name: Install dependencies | |
| run: uvx hatch -v env create ${{ matrix.env.name }} | |
| - name: Run tests | |
| run: uvx hatch run ${{ matrix.env.name }}:run -v --color=yes | |
| stable-dev-green: | |
| name: CI-Pass | |
| if: always() && github.event_name != 'pull_request' | |
| needs: | |
| - check | |
| - get-envs | |
| - test-stable-dev | |
| runs-on: ubuntu-latest | |
| permissions: | |
| statuses: write | |
| steps: | |
| - uses: re-actors/alls-green@release/v1 | |
| with: | |
| jobs: ${{ toJSON(needs) }} | |
| - name: Set success status on PR | |
| if: success() && github.event_name == 'issue_comment' | |
| run: | | |
| gh api repos/${{ github.repository }}/statuses/${{ needs.check.outputs.head-sha }} \ | |
| -f state=success \ | |
| -f context="CI-Pass" \ | |
| -f description="GPU tests passed" \ | |
| -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set failure status on PR | |
| if: failure() && github.event_name == 'issue_comment' | |
| run: | | |
| gh api repos/${{ github.repository }}/statuses/${{ needs.check.outputs.head-sha }} \ | |
| -f state=failure \ | |
| -f context="CI-Pass" \ | |
| -f description="GPU tests failed" \ | |
| -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| all-green: | |
| name: All Tests Green | |
| if: always() && github.event_name != 'pull_request' | |
| needs: | |
| - check | |
| - get-envs | |
| - test-stable-dev | |
| - test-prerelease | |
| runs-on: ubuntu-latest | |
| permissions: | |
| statuses: write | |
| steps: | |
| - uses: re-actors/alls-green@release/v1 | |
| with: | |
| allowed-failures: test-prerelease | |
| jobs: ${{ toJSON(needs) }} | |
| - name: Set success status on PR | |
| if: success() && github.event_name == 'issue_comment' | |
| run: | | |
| gh api repos/${{ github.repository }}/statuses/${{ needs.check.outputs.head-sha }} \ | |
| -f state=success \ | |
| -f context="All Tests Green" \ | |
| -f description="All GPU tests passed" \ | |
| -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set failure status on PR | |
| if: failure() && github.event_name == 'issue_comment' | |
| run: | | |
| gh api repos/${{ github.repository }}/statuses/${{ needs.check.outputs.head-sha }} \ | |
| -f state=failure \ | |
| -f context="All Tests Green" \ | |
| -f description="GPU tests failed" \ | |
| -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |