-
Notifications
You must be signed in to change notification settings - Fork 12
80 lines (69 loc) · 2.59 KB
/
validate-pull-request.yml
File metadata and controls
80 lines (69 loc) · 2.59 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Validate Pull Request
on:
pull_request_target:
types: [opened, synchronize, reopened, labeled]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
validate-metadata:
runs-on: ubuntu-latest
steps:
- name: Debug PR information
run: |
echo "Event: ${{ github.event_name }}"
echo "Action: ${{ github.event.action }}"
echo "PR number: ${{ github.event.number }}"
echo "Base ref: ${{ github.base_ref }}"
echo "Head ref: ${{ github.head_ref }}"
echo "Head SHA: ${{ github.event.pull_request.head.sha }}"
echo "Head repo: ${{ github.event.pull_request.head.repo.full_name }}"
echo "Base repo: ${{ github.repository }}"
- name: Remove validation label if present
if: github.event.action == 'labeled' && github.event.label.name == 'run validation'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'run validation'
})
- name: Checkout base branch to get latest validation script
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
fetch-depth: 0
path: base-repo
- name: Checkout PR code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
path: pr-repo
- name: Copy validation script from base branch
run: |
mkdir -p pr-repo/.github/scripts/
cp base-repo/.github/scripts/validate-pull-request.js pr-repo/.github/scripts/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Change to PR directory and validate
working-directory: pr-repo
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_EVENT_PATH: ${{ github.event_path }}
GITHUB_BASE_REF: ${{ github.base_ref }}
PR_NUMBER: ${{ github.event.number }}
run: |
# Get changed files using git in the PR directory
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD 2>/dev/null || git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
echo "Changed files: $CHANGED_FILES"
# Run the validation script
node .github/scripts/validate-pull-request.js $CHANGED_FILES