i am handsome #308
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 | |
permissions: | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Fetch base branch | |
run: git fetch origin $GITHUB_BASE_REF | |
- 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 diff | |
run: | | |
echo "=== index.ts diff ===" | |
git diff -- index.ts | |
echo "=== package.json diff ===" | |
git diff -- package.json | |
- name: Check and Comment Changes | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { execSync } = require('child_process'); | |
const baseRef = process.env.GITHUB_BASE_REF; | |
const indexDiff = execSync(`git diff origin/${baseRef} index.ts`).toString(); | |
const packageDiff = execSync(`git diff origin/${baseRef} package.json`).toString(); | |
if (indexDiff.trim()) { | |
console.log('=== index.ts diff ==='); | |
console.log(indexDiff); | |
} | |
if (packageDiff.trim()) { | |
console.log('=== package.json diff ==='); | |
console.log(packageDiff); | |
} | |
const hasChanges = indexDiff || packageDiff; | |
const prNumber = context.payload.pull_request.number; | |
if (hasChanges) { | |
let message = '### ⚠️ Module Registration Issue Detected\n\n'; | |
message += 'Please run this command locally and commit the changes:\n```bash\npnpm generate\n```\n\n'; | |
message += 'This will ensure all utility modules are properly registered in both index.ts and package.json'; | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body: message | |
}); | |
process.exit(1); | |
} else { | |
const successMessage = '✅ All utility modules are properly registered'; | |
const comments = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber | |
}); | |
const botComment = comments.data.find(comment => | |
comment.user.type === 'Bot' && | |
(comment.body.includes('Module Registration Issue Detected') || | |
comment.body.includes('All utility modules are properly registered')) | |
); | |
if (botComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: botComment.id, | |
body: successMessage | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body: successMessage | |
}); | |
} | |
} |