-
Notifications
You must be signed in to change notification settings - Fork 1
54 lines (43 loc) · 1.43 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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]
});