-
Notifications
You must be signed in to change notification settings - Fork 1k
143 lines (124 loc) Β· 5.9 KB
/
Copy pathpr-compliance-check.yml
File metadata and controls
143 lines (124 loc) Β· 5.9 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
name: PR Compliance Check
permissions: read-all
on:
pull_request:
types:
- opened
- synchronize
- reopened
pull_request_review:
types:
- submitted
jobs:
compliance-check:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Check if PR is from fork
id: fork-check
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo "is_fork=true" >> $GITHUB_OUTPUT
echo "_This PR is from a fork - compliance check will run with limited permissions._"
else
echo "is_fork=false" >> $GITHUB_OUTPUT
fi
- name: Run PR compliance check
env:
GH_TOKEN: ${{ github.token }}
run: |
echo -e "## π PR Compliance Check Results:\n" >> compliance_report.md
PR_NUMBER="${{ github.event.pull_request.number }}"
IS_FORK="${{ steps.fork-check.outputs.is_fork }}"
if [ "$IS_FORK" = "true" ]; then
echo -e "**Source**: π External fork contribution.\n" >> compliance_report.md
fi
# Run compliance check for this PR
if [ -f "./scripts/batch_pr_compliance.sh" ] && [ -x "./scripts/batch_pr_compliance.sh" ]; then
./scripts/batch_pr_compliance.sh "$PR_NUMBER" > compliance_output.txt 2>&1
# Parse results for this PR
if grep -q "β
PR $PR_NUMBER: Compliant" compliance_output.txt; then
echo "β
**Status**: Compliant - All requirements met!" >> compliance_report.md
elif grep -q "β" compliance_output.txt; then
echo -e "β **Status**: Non-Compliant - Issues found that need fixing.\n" >> compliance_report.md
echo -e "### Issues Found:\n" >> compliance_report.md
grep "β PR $PR_NUMBER:" compliance_output.txt | sed 's/β PR [0-9]*: /- /' >> compliance_report.md
fi
echo "" >> compliance_report.md
# Review status information
if grep -q "π¨\|β
\|βΉοΈ" compliance_output.txt; then
echo "### Review Status:" >> compliance_report.md
grep -E "(π¨|β
|βΉοΈ) PR $PR_NUMBER:" compliance_output.txt | sed "s/PR $PR_NUMBER: //" >> compliance_report.md
echo "" >> compliance_report.md
fi
else
echo -e "β οΈ **Status**: Compliance script not found - manual review required.\n" >> compliance_report.md
fi
# Add helpful guidance
if grep -q "β" compliance_output.txt 2>/dev/null; then
echo -e "### Quick Fix Guide:\n" >> compliance_report.md
echo "- **Title Format**: Use \`\`\`<Add|Update|Remove> \`username/repo\` \`\`\`." >> compliance_report.md
echo "- **Description**: Remove 'plugin' word, end with period." >> compliance_report.md
echo -e "- **Repository**: Ensure public repo with README and license.\n" >> compliance_report.md
echo "_After fixing issues, push new commits to update this check._" >> compliance_report.md
else
echo -e "### Next Steps:\n" >> compliance_report.md
if [ "$IS_FORK" = "true" ]; then
echo "β
Thank you for your contribution!" >> compliance_report.md
echo "π Ready for maintainer review." >> compliance_report.md
else
echo "β
Ready for manual review by maintainers." >> compliance_report.md
echo "π Repository quality will be analyzed automatically." >> compliance_report.md
fi
fi
echo -e "\n---\n" "_Automated check powered by [enhanced PR review scripts](scripts/)._" >> compliance_report.md
- name: Post compliance results as comment (non-fork only)
if: steps.fork-check.outputs.is_fork == 'false'
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('compliance_report.md', 'utf8');
const prNumber = ${{ github.event.pull_request.number }};
try {
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existingComment = comments.find(comment =>
comment.body.includes('π PR Compliance Check Results') &&
(comment.user.type === 'Bot' || comment.user.login === 'github-actions[bot]')
);
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: report
});
console.log(`β
Updated compliance comment on PR #${prNumber}`);
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: report
});
console.log(`β
Posted compliance comment on PR #${prNumber}`);
}
} catch (error) {
console.error(`β Failed to post compliance comment: ${error.message}`);
core.setFailed(`Failed to post comment: ${error.message}`);
}
- name: Output compliance report for fork PRs
if: steps.fork-check.outputs.is_fork == 'true'
run: |
echo -e "Fork PR detected - compliance report saved as workflow output.\n" "$(cat compliance_report.md)\n"
echo "β οΈ Maintainers: Review the compliance report above for this fork PR."