-
Notifications
You must be signed in to change notification settings - Fork 4
104 lines (82 loc) · 2.89 KB
/
template-pr-inspection.yml
File metadata and controls
104 lines (82 loc) · 2.89 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
name: Template PR Inspection
on:
pull_request:
paths:
- 'src/fastapi_fastkit/fastapi_project_template/**'
types:
- opened
- synchronize
permissions:
contents: read
pull-requests: write
jobs:
inspect-changed-templates:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for git diff
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
- name: Install dependencies
run: pdm install -G dev
- name: Setup UV
uses: astral-sh/setup-uv@v7
- name: Verify Docker and Compose
run: |
docker --version
docker compose version
- name: Inspect changed templates
run: pdm run python scripts/inspect-changed-templates.py
- name: Create or Update PR Comment
if: always()
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- template-inspection-bot -->';
const success = '${{ job.status }}' === 'success';
const successBody = `${marker}
✅ **Template Inspection Passed**
All changed templates have been validated successfully.
---
*Last updated: ${new Date().toISOString()}*`;
const failureBody = `${marker}
❌ **Template Inspection Failed**
Please check the workflow logs for details on what needs to be fixed.
[View Logs](${context.payload.repository.html_url}/actions/runs/${context.runId})
---
*Last updated: ${new Date().toISOString()}*`;
const body = success ? successBody : failureBody;
// Find existing bot comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const botComment = comments.find(comment =>
comment.body.includes(marker)
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
console.log('Updated existing comment');
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
console.log('Created new comment');
}