Skip to content

Instantly share code, notes, and snippets.

@JonasDoe
Created April 8, 2024 18:52
Show Gist options
  • Save JonasDoe/a3750ac54cf53886b1500d17d14b8e5b to your computer and use it in GitHub Desktop.
Save JonasDoe/a3750ac54cf53886b1500d17d14b8e5b to your computer and use it in GitHub Desktop.
Run Test for PR with /test comment
name: Test
on:
workflow_dispatch:
inputs:
used-branch:
description: Branch the test shall be run on
default: master
required: true
push:
branches: ['main', 'master']
tags: ['!**']
# pull_request:
# types: [opened, reopened, ready_for_review]
issue_comment:
types: [created]
jobs:
build:
if: >-
(github.event.action != 'pull_request' || (github.event.pull_request.draft == false && github.event.action != 'issue_comment')) &&
(github.event.action != 'issue_comment' || (github.event.issue.pull_request && github.event.comment.body == '/test'))
runs-on: [self-hosted, linux]
timeout-minutes: 30
steps:
- name: Get PR details
uses: xt0rted/pull-request-comment-branch@v2
id: comment-branch
if: github.event.issue.pull_request && github.event.comment.body == '/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: pending
if: steps.comment-branch.outputs.head_sha != ''
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
if: steps.comment-branch.outputs.head_sha != '' && inputs.used-branch == ''
- name: Checkout selected branch
uses: actions/checkout@v4
if: inputs.used-branch != '' && steps.comment-branch.outputs.head_sha == ''
with:
ref: ${{ github.event.inputs.used-branch }}
- name: Checkout current branch
uses: actions/checkout@v4
with:
ref: ${{github.ref}}
if: inputs.used-branch == '' && steps.comment-branch.outputs.head_sha == ''
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run component tests
run: npm run test:all
- name: Build production bundle
run: npm run build
- 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: steps.comment-branch.outputs.head_sha != ''
- 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: failure()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment