Create hey.md #7
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 Verification Workflow | |
permissions: | |
issues: write | |
pull-requests: write | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
verify-pr: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Verify File Paths, Names and Contents | |
id: verify_files | |
run: | | |
#!/bin/bash | |
set -e | |
VALID=true | |
EXPECTED_PATH_PATTERN="^.*_book_app/add_book_features/(create_book\.txt|list_all_books\.txt)$" | |
for file in $(git diff --name-only origin/main...HEAD); do | |
echo "Checking $file" | |
if [[ ! $file =~ $EXPECTED_PATH_PATTERN ]] || [ ! -s "$file" ]; then | |
echo "Invalid file path or empty file: $file" | |
VALID=false | |
fi | |
done | |
echo "::set-output name=valid::$VALID" | |
- name: Label PR | |
if: always() | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const isValid = ${{ steps.verify_files.outputs.valid }}; | |
const prNumber = context.payload.pull_request.number; | |
const label = isValid === 'true' ? 'valid' : 'invalid'; | |
github.rest.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
labels: [label] | |
}); | |