Last active
February 26, 2025 17:42
-
-
Save JonasDoe/a3750ac54cf53886b1500d17d14b8e5b to your computer and use it in GitHub Desktop.
Run Test for PR with /test comment
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: Test | |
on: | |
push: | |
branches: ['main', 'master'] | |
tags: ['!**'] | |
issue_comment: | |
types: [created] | |
jobs: | |
test: | |
# it's triggered by a push, or by an issue comment in a PR with /test | |
if: github.event.pusher || (github.event.issue.pull_request && github.event.comment.body == '/test') | |
runs-on: self-hosted | |
timeout-minutes: 30 | |
steps: | |
- name: Get PR details | |
uses: xt0rted/pull-request-comment-branch@v3 | |
id: comment-branch | |
if: github.event.issue.pull_request | |
- name: Set commit status as pending | |
uses: myrotvorets/set-commit-status-action@master | |
with: | |
sha: ${{ steps.comment-branch.outputs.head_sha }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: pending | |
if: github.event.issue.pull_request | |
# Checkout either the PR's branch or the main/master branch | |
- name: Checkout PR branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.comment-branch.outputs.head_ref }} | |
if: github.event.issue.pull_request | |
- name: Checkout current branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{github.ref}} | |
if: github.event.pusher | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Setup GitHub Packages | |
run: | | |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.REGISTRY_READ_ONLY }}" >> .npmrc | |
echo "@mycompany:registry=https://npm.pkg.github.com/" >> .npmrc | |
- name: Install dependencies | |
run: npm ci | |
- name: Run test | |
run: npm run test | |
- name: Set commit status as pending | |
uses: myrotvorets/set-commit-status-action@master | |
with: | |
sha: ${{ steps.comment-branch.outputs.head_sha }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: success | |
if: github.event.issue.pull_request && success() | |
- name: Set commit status as pending | |
uses: myrotvorets/set-commit-status-action@master | |
with: | |
sha: ${{ steps.comment-branch.outputs.head_sha }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: failure | |
if: github.event.issue.pull_request && failure() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment