Skip to content

Commit 78abe49

Browse files
authored
Add workflow to block sponsor asset changes
1 parent df16bdd commit 78abe49

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Block sponsor asset changes
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
guard:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Detect changes under static/img/sponsors
17+
id: changes
18+
uses: dorny/paths-filter@v3
19+
with:
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
list-files: json
22+
filters: |
23+
sponsors:
24+
- 'static/img/sponsors/**'
25+
26+
# This step will:
27+
# 1) Add a single comment (once per PR) listing the files
28+
# 2) Fail the check whenever changes are detected (even if comment already exists)
29+
- name: Comment and fail if sponsors directory changed
30+
if: steps.changes.outputs.sponsors == 'true'
31+
uses: actions/github-script@v7
32+
env:
33+
SPONSORS_FILES_JSON: ${{ steps.changes.outputs.sponsors_files }}
34+
with:
35+
script: |
36+
const owner = context.repo.owner;
37+
const repo = context.repo.repo;
38+
const issue_number = context.payload.pull_request.number;
39+
40+
const marker = "<!-- sponsors-dir-guard -->";
41+
42+
// Parse the changed files list from dorny/paths-filter output
43+
let files = [];
44+
try {
45+
files = JSON.parse(process.env.SPONSORS_FILES_JSON || "[]");
46+
} catch (e) {
47+
files = [];
48+
}
49+
50+
const fileList = files.length
51+
? files.map(f => `- \`${f}\``).join("\n")
52+
: "- _(Unable to enumerate files, but changes were detected)_";
53+
54+
// Check if we already commented
55+
const comments = await github.paginate(github.rest.issues.listComments, {
56+
owner,
57+
repo,
58+
issue_number,
59+
per_page: 100,
60+
});
61+
62+
const alreadyCommented = comments.some(c => (c.body || "").includes(marker));
63+
64+
if (!alreadyCommented) {
65+
const body = [
66+
"🚫 **Blocked: sponsor assets directory change detected**",
67+
"",
68+
"This PR adds or modifies files under `static/img/sponsors/`.",
69+
"",
70+
"**These files should not be added or changed.**",
71+
"",
72+
"Please use the `assets/sponsors/*` directory instead."
73+
"",
74+
"**Affected files:**",
75+
fileList,
76+
"",
77+
marker
78+
].join("\n");
79+
80+
await github.rest.issues.createComment({
81+
owner,
82+
repo,
83+
issue_number,
84+
body,
85+
});
86+
} else {
87+
core.info("Sponsor directory warning comment already exists; skipping comment creation.");
88+
}
89+
90+
// Always fail the check if files in this directory were touched
91+
core.setFailed("Changes detected under static/img/sponsors/. Revert these changes to pass.");

0 commit comments

Comments
 (0)