Skip to content

PR Comment Test Runner #28

PR Comment Test Runner

PR Comment Test Runner #28

Workflow file for this run

name: PR Test Runner
on:
issue_comment:
types: [created]
jobs:
test:
# Only run if the comment is on a PR and contains "run tests"
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'run tests') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required to fetch all branches
- name: Get PR branch
id: get-pr-branch
uses: actions/github-script@v7
with:
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.name,
pull_number: context.issue.number
});
return pr.head.ref;
- 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: pnpm test:minimal:pr ${{ github.event.pull_request.base.ref }} ${{ steps.get-pr-branch.outputs.result }}
- name: Update Check Run
uses: actions/github-script@v7
if: always()
with:
script: |
const conclusion = process.env.TEST_EXIT_CODE === '0' ? 'success' : 'failure';
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.name,
name: 'PR Tests',
head_sha: context.payload.pull_request.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.'
}
});