feat(infra): Add backend selective testing workflow #9
Workflow file for this run
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: backend - selective | |
| on: | |
| pull_request: | |
| # Cancel in progress workflows on pull_requests. | |
| # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| backend-test-selective: | |
| name: backend test (selective) | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 60 | |
| permissions: | |
| contents: read | |
| id-token: write | |
| actions: read # used for DIM metadata | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| instance: | |
| [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] | |
| env: | |
| MATRIX_INSTANCE_TOTAL: 22 | |
| steps: | |
| - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
| - name: Setup sentry env | |
| uses: ./.github/actions/setup-sentry | |
| id: setup | |
| with: | |
| mode: backend-ci | |
| # Download coverage artifact from a previous workflow run | |
| # actions/download-artifact doesn't support cross-run downloads, so we use alternatives | |
| # Option 1: Use dawidd6/action-download-artifact (supports cross-run downloads) | |
| - name: Download coverage database from run 20529759656 | |
| uses: dawidd6/action-download-artifact@v6 | |
| continue-on-error: true | |
| id: download-coverage | |
| with: | |
| run_id: 20529759656 | |
| name: pycoverage-sqlite-combined-20529759656 | |
| path: .coverage | |
| github_token: ${{ github.token }} | |
| # Option 2: Fallback to manual download using gh CLI | |
| - name: Manual download of coverage artifact | |
| if: steps.download-coverage.outcome == 'failure' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| echo "Downloading artifact 4972973279 (pycoverage-sqlite-combined-20529759656)..." | |
| # Download the artifact zip | |
| gh api \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| /repos/getsentry/sentry/actions/artifacts/4972973279/zip \ | |
| > coverage.zip | |
| # Extract to .coverage directory | |
| mkdir -p .coverage | |
| unzip -q coverage.zip -d .coverage | |
| rm coverage.zip | |
| echo "Coverage artifact downloaded successfully" | |
| ls -la .coverage | |
| - name: Get changed files | |
| id: changed-files | |
| uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 | |
| - name: List all changed files | |
| env: | |
| ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | |
| run: | | |
| for file in ${ALL_CHANGED_FILES}; do | |
| echo "$file was changed" | |
| done | |
| - name: Run backend tests (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }}) | |
| id: run_backend_tests | |
| run: make test-python-ci | |
| env: | |
| SELECTIVE_TESTING_ENABLED: true | |
| CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | |
| COVERAGE_DB_PATH: .coverage | |
| - name: Inspect failure | |
| if: failure() | |
| run: | | |
| if command -v devservices; then | |
| devservices logs | |
| fi | |
| # - name: Collect test data | |
| # uses: ./.github/actions/collect-test-data | |
| # if: ${{ !cancelled() }} | |
| # with: | |
| # artifact_path: .artifacts/pytest.json # TODO | |
| # gcs_bucket: ${{ secrets.COLLECT_TEST_DATA_GCS_BUCKET }} | |
| # gcp_project_id: ${{ secrets.COLLECT_TEST_DATA_GCP_PROJECT_ID }} | |
| # workload_identity_provider: ${{ secrets.SENTRY_GCP_DEV_WORKLOAD_IDENTITY_POOL }} | |
| # service_account_email: ${{ secrets.COLLECT_TEST_DATA_SERVICE_ACCOUNT_EMAIL }} | |
| # matrix_instance_number: ${{ steps.setup.outputs.matrix-instance-number }} |