This file contains 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: Validate Utils Registration | |
on: | |
pull_request_target: | |
paths: | |
- 'src/**' | |
- 'index.ts' | |
- 'package.json' | |
- 'scripts/generate-utils.mjs' | |
permissions: | |
pull-requests: write | |
jobs: | |
check-utils: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out PR head | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
fetch-depth: 0 | |
- name: Fetch base branch | |
run: git fetch origin ${{ github.event.pull_request.base.ref }} | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Generate Utils | |
run: node scripts/generate-utils.mjs | |
- name: Debug local diff after generate | |
run: | | |
echo "=== index.ts diff ===" | |
git diff -- index.ts | |
echo "=== package.json diff ===" | |
git diff -- package.json | |
- name: Check for leftover changes | |
run: | | |
git diff --exit-code index.ts package.json | |
- name: Post failure comment | |
if: failure() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const prNumber = context.payload.pull_request.number; | |
const { data: allComments } = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
}); | |
const warningMsg = "### ⚠️ Module Registration Issue Detected\n\n" | |
+ "It looks like there are unregistered or mismatched modules in `package.json` exports or `index.ts`. " | |
+ "Please run the following commands locally to update and commit:\n\n" | |
+ "```bash\n" | |
+ "pnpm generate\n" | |
+ "git commit -am \"fix: update utils\"\n" | |
+ "git push\n" | |
+ "```\n"; | |
const existingBotComment = allComments.find(comment => | |
( | |
comment.body.includes('Module Registration Issue Detected') || | |
comment.body.includes('All utility modules are properly registered') | |
) | |
); | |
if (existingBotComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: existingBotComment.id, | |
body: warningMsg, | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body: warningMsg, | |
}); | |
} | |
- name: Post success comment | |
if: success() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const prNumber = context.payload.pull_request.number; | |
const { data: allComments } = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
}); | |
const successMsg = "✅ All utility modules are properly registered in `index.ts` and `package.json` exports!"; | |
const existingBotComment = allComments.find(comment => | |
( | |
comment.body.includes('Module Registration Issue Detected') || | |
comment.body.includes('All utility modules are properly registered') | |
) | |
); | |
if (existingBotComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: existingBotComment.id, | |
body: successMsg, | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body: successMsg, | |
}); | |
} |