Skip to content

Manual Validate Pattern #469

Manual Validate Pattern

Manual Validate Pattern #469

# Manual trigger that will post information back to the pull request with required changes.
name: Manual Validate Pattern
on:
workflow_dispatch:
inputs:
prNumber:
description: "PR Number"
required: true
jobs:
validate-pull-request:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
env:
NODE_ENV: dev
PR_NUMBER: ${{ inputs.prNumber }}
steps:
# Since we are manually triggering the workflow the previous checkout has the main branch. In order to checkout the branch/code of the PR
# we need first to use the PR number to retrieve the PR SHA number. This means we need three steps to: checkout the repo,
# run a custom script to get the SHA, and then finally checkout the PR branch
- name: Checkout Repo
uses: actions/checkout@v3
# Use the fork repo URL in subsequent steps
- name: Get repo URL
run: echo "REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV
- name: Dump github context
run: echo "$GITHUB_CONTEXT"
shell: bash
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Extract PR details
id: extract_PR_details
uses: actions/github-script@v6
with:
script: |
const script = require('.github/scripts/get_pr_info.js');
await script({github, context, core});
- name: Checkout PR code
uses: actions/checkout@v3
with:
ref: ${{ steps.extract_PR_details.outputs.headSHA }}
- run: cd scripts && npm i
- name: Validate
run: node scripts/validate.js
env: # Or as an environment variable
MODIFIED_FILES: ${{ steps.extract_PR_details.outputs.files }}
ADDED_FILES: "${{ steps.changed-files.outputs.added_files }}"
PR_NUMBER: ${{ inputs.prNumber }}
TOKEN: "${{ secrets.GITHUB_TOKEN }}"