-
Notifications
You must be signed in to change notification settings - Fork 21
61 lines (52 loc) · 1.77 KB
/
pr-validate.yml
File metadata and controls
61 lines (52 loc) · 1.77 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
name: PR Validation
on:
pull_request:
branches: [main]
paths:
- 'tools/**'
workflow_dispatch:
jobs:
validate:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
run: git diff --name-only origin/main...HEAD > changed_files.txt
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: pip install pyyaml
- name: Run validation
id: validate
working-directory: ${{ github.workspace }}
run: |
python .github/scripts/validate_pr.py changed_files.txt > result.txt 2>&1
echo "exit_code=$?" >> $GITHUB_OUTPUT
cat result.txt
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const result = fs.readFileSync('result.txt', 'utf8');
const exitCode = '${{ steps.validate.outputs.exit_code }}';
const icon = exitCode === '0' ? '✅' : '❌';
const status = exitCode === '0' ? '校验通过' : '校验失败,请修复后重新提交';
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## ${icon} PR 自动校验结果\n\n**状态**: ${status}\n\n\`\`\`\n${result}\n\`\`\``
});
- name: Fail if validation failed
if: steps.validate.outputs.exit_code != '0'
run: exit 1