Test sponsor PR check #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Block sponsor asset changes | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| guard: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Detect changes under static/img/sponsors | |
| id: changes | |
| uses: dorny/paths-filter@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| list-files: json | |
| filters: | | |
| sponsors: | |
| - 'static/img/sponsors/**' | |
| # This step will: | |
| # 1) Add a single comment (once per PR) listing the files | |
| # 2) Fail the check whenever changes are detected (even if comment already exists) | |
| - name: Comment and fail if sponsors directory changed | |
| if: steps.changes.outputs.sponsors == 'true' | |
| uses: actions/github-script@v7 | |
| env: | |
| SPONSORS_FILES_JSON: ${{ steps.changes.outputs.sponsors_files }} | |
| with: | |
| script: | | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const issue_number = context.payload.pull_request.number; | |
| const marker = "<!-- sponsors-dir-guard -->"; | |
| // Parse the changed files list from dorny/paths-filter output | |
| let files = []; | |
| try { | |
| files = JSON.parse(process.env.SPONSORS_FILES_JSON || "[]"); | |
| } catch (e) { | |
| files = []; | |
| } | |
| const fileList = files.length | |
| ? files.map(f => `- \`${f}\``).join("\n") | |
| : "- _(Unable to enumerate files, but changes were detected)_"; | |
| // Check if we already commented | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| owner, | |
| repo, | |
| issue_number, | |
| per_page: 100, | |
| }); | |
| const alreadyCommented = comments.some(c => (c.body || "").includes(marker)); | |
| if (!alreadyCommented) { | |
| const body = [ | |
| "🚫 **Blocked: sponsor assets directory change detected**", | |
| "", | |
| "This PR adds or modifies files under `static/img/sponsors/`.", | |
| "", | |
| "**These files should not be added or changed.**", | |
| "", | |
| "Please use the `assets/sponsors/*` directory instead." | |
| "", | |
| "**Affected files:**", | |
| fileList, | |
| "", | |
| marker | |
| ].join("\n"); | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body, | |
| }); | |
| } else { | |
| core.info("Sponsor directory warning comment already exists; skipping comment creation."); | |
| } | |
| // Always fail the check if files in this directory were touched | |
| core.setFailed("Changes detected under static/img/sponsors/. Revert these changes to pass."); |