ok-to-test-command #30
This file contains 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: Tests | |
on: | |
pull_request: | |
repository_dispatch: | |
types: [ok-to-test-command] | |
jobs: | |
# Branch-based pull request | |
integration-trusted: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Run tests | |
env: | |
TEST_SECRET: ${{ secrets.TEST_SECRET }} | |
run: if [[ -z $TEST_SECRET ]]; then exit 1; else echo "OK"; fi | |
# Repo owner has commented /ok-to-test on a (fork-based) pull request | |
integration-fork: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
checks: write | |
if: | | |
github.event_name == 'repository_dispatch' && | |
github.event.client_payload.slash_command.args.named.sha != '' && | |
contains( | |
github.event.client_payload.pull_request.head.sha, | |
github.event.client_payload.slash_command.args.named.sha | |
) | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge' | |
- name: Run tests | |
env: | |
TEST_SECRET: ${{ secrets.TEST_SECRET }} | |
run: if [[ -z $TEST_SECRET ]]; then exit 1; else echo "OK"; fi | |
# Update check run called "integration-fork" | |
- uses: actions/github-script@v7 | |
id: update-check-run | |
if: ${{ always() }} | |
env: | |
number: ${{ github.event.client_payload.pull_request.number }} | |
job: ${{ github.job }} | |
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run | |
conclusion: ${{ job.status }} | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { data: pull } = await github.rest.pulls.get({ | |
...context.repo, | |
pull_number: process.env.number | |
}); | |
const ref = pull.head.sha; | |
const { data: checks } = await github.rest.checks.listForRef({ | |
...context.repo, | |
ref | |
}); | |
const check = checks.check_runs.filter(c => c.name === process.env.job); | |
const { data: result } = await github.rest.checks.update({ | |
...context.repo, | |
check_run_id: check[0].id, | |
status: 'completed', | |
conclusion: process.env.conclusion | |
}); | |
return result; |