GitHub Action Setup¶
The official Drape GitHub Action uploads results and posts rich PR comments automatically.
Basic Setup¶
Add this to your workflow file (e.g., .github/workflows/ci.yml):
name: CI
on: [push, pull_request]
permissions:
contents: read
pull-requests: write # PR comments
id-token: write # upload without an API key
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: pytest --junitxml=results.xml --cov --cov-report=xml:coverage.xml
continue-on-error: true
- name: Upload test results
uses: drape-io/drape-action@v2
if: always()
continue-on-error: true
with:
command: tests
file: results.xml
- name: Upload coverage
uses: drape-io/drape-action@v2
if: always()
continue-on-error: true
with:
command: coverage
file: coverage.xml
format: cobertura
What You Get¶
The action automatically:
- Uploads results to Drape for processing
- Posts PR comments with test summaries, coverage diffs, and suppression status
- Detects CI context (branch, SHA, PR number) from the GitHub Actions environment
No API key needed¶
id-token: write lets the job request a GitHub OIDC token: a short-lived token for this one repository. The action sends it to Drape in place of an API key. You have no secret to store or rotate.
Drape accepts the token when:
- The Drape GitHub App is connected for the repository's owner.
- The repository is turned on in Drape.
The token decides the Drape organization and repository, so you do not set org or repo.
Before you add id-token: write to a job that runs your tests, read Keep id-token: write away from untrusted code.
This needs drape-action v2.6.0 or later (@v2 picks it up) and Drape CLI v0.10.0 or later. The action installs the latest CLI unless you pin cli-version.
When you still need an API key¶
An api-key input always wins over the OIDC token. Use one in these cases:
- GitLab and other CI providers. See GitLab CI and Other CI providers.
- GitHub Enterprise with a custom OIDC issuer. Drape accepts tokens only from GitHub's own issuer.
- A repository you renamed on GitHub. Drape keeps the old name, so uploads without a key fail. Use an API key and set
repoto the old name.
To use a key, add it as a repository secret named DRAPE_API_KEY (Settings > Secrets and variables > Actions). Then pass it to each upload step:
Pull requests from forks cannot upload, with or without a key. GitHub gives them no OIDC token and no secrets.
Keep id-token: write away from untrusted code¶
The setup above gives id-token: write to the job that runs your tests and uploads the results. That is fine for most teams.
The risk¶
Any step in a job with id-token: write can request an OIDC token for any audience. That includes your test code and every dependency it installs. Some cloud roles (AWS, GCP or Azure) trust your repository's pull requests. A compromised dependency can use the token to assume such a role.
Pull requests from forks and Dependabot get no token. The exposure is code that runs in jobs on your own branches.
Upload from a separate job¶
Use two jobs if a cloud role trusts pull requests. Also use them if jobs that run dependencies must not get a token:
- Your test, lint and scan jobs save their reports with
actions/upload-artifact. They get noid-tokenpermission. - An upload job that runs none of your code depends on them with
needs:. It downloads the reports and runs drape-action withid-token: write.
name: CI
on: [push, pull_request]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: pytest --junitxml=results.xml --cov --cov-report=xml:coverage.xml
continue-on-error: true
- name: Save reports
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: drape-reports
path: |
results.xml
coverage.xml
upload:
needs: test
if: ${{ !cancelled() }} # upload when tests fail too
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # PR comments
id-token: write # upload without an API key
steps:
- uses: actions/download-artifact@v4
with:
name: drape-reports
- name: Upload test results
uses: drape-io/drape-action@v2
with:
command: tests
file: results.xml
job-name: test # show the test job in Drape, not this one
- name: Upload coverage
if: ${{ !cancelled() }} # upload coverage even when the test gate fails
uses: drape-io/drape-action@v2
with:
command: coverage
file: coverage.xml
format: cobertura
This setup has two costs:
- Results arrive later. PR comments and the pass/fail gate come when the upload job finishes. The gate moves to the upload job's check, so if you use required status checks, require the upload job too.
- Sharded tests need a matching matrix. Give the upload job the same matrix as the test job, with one artifact per shard. Every shard's upload then arrives together, and
total-shardsworks as before.
Scope your cloud roles¶
The better long-term fix is in your cloud roles, not in this workflow. Scope each role's trust policy to protected branches or environments, as GitHub's OIDC guide recommends. Do not let pull request runs assume a privileged role.
Switch from an API key¶
- Add
id-token: writeto your workflow's or job'spermissions:block. Keepcontents: readandpull-requests: write. - Delete the
api-key:line from each Drape step, or theDRAPE_API_KEYenv var if you run the CLI directly. While a key is set, Drape uses it and never the OIDC token. - After a green run, revoke the key on your organization's API Keys page in Drape, then delete the
DRAPE_API_KEYsecret.
Next Steps¶
- GitHub Action reference for all inputs, outputs, and advanced configuration.
- Security scans and lint reports can also be uploaded via the action.