PR Comment Test Runner #29
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: PR Test Runner | |
on: | |
issue_comment: | |
types: [created] | |
jobs: | |
test: | |
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'run tests') }} | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: read | |
checks: write | |
contents: read | |
steps: | |
- name: Get PR information | |
id: pr-info | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { data: pullRequest } = await github.rest.pulls.get({ | |
...context.repo, | |
pull_number: context.issue.number | |
}); | |
console.log('PR Info:', pullRequest); | |
return { | |
head_ref: pullRequest.head.ref, | |
head_sha: pullRequest.head.sha, | |
base_ref: pullRequest.base.ref | |
} | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: Install dependencies | |
run: pnpm install | |
- name: Run tests | |
id: run-tests | |
run: | | |
PR_INFO='${{ steps.pr-info.outputs.result }}' | |
BASE_REF=$(echo $PR_INFO | jq -r '.base_ref') | |
HEAD_REF=$(echo $PR_INFO | jq -r '.head_ref') | |
pnpm test:minimal:pr "$BASE_REF" "$HEAD_REF" | |
- name: Create Check Run | |
if: always() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const pr_info = JSON.parse(process.env.PR_INFO); | |
const conclusion = process.env.TEST_EXIT_CODE === '0' ? 'success' : 'failure'; | |
await github.rest.checks.create({ | |
...context.repo, | |
name: 'PR Tests', | |
head_sha: pr_info.head_sha, | |
status: 'completed', | |
conclusion: conclusion, | |
output: { | |
title: conclusion === 'success' ? 'Tests passed' : 'Tests failed', | |
summary: conclusion === 'success' | |
? '✅ All tests have passed successfully' | |
: '❌ Some tests have failed. Please check the test output for details.' | |
} | |
}); | |
env: | |
PR_INFO: ${{ steps.pr-info.outputs.result }} |