Skip to content

add codemod

add codemod #29

Workflow file for this run

name: PR Auto-publish Detection
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'recipes/**'
jobs:
detect-and-comment:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for diff
- name: Detect codemod changes
id: detect
run: |
# Get the base and head commits
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "Comparing $BASE_SHA..$HEAD_SHA"
# Find changed codemod directories
CHANGED_CODEMODS=$(git diff --name-only $BASE_SHA..$HEAD_SHA | grep '^recipes/' | cut -d'/' -f1-2 | sort -u | tr '\n' ' ')
if [ -z "$CHANGED_CODEMODS" ]; then
echo "has-changes=false" >> $GITHUB_OUTPUT
echo "No codemod changes detected"
exit 0
fi
echo "has-changes=true" >> $GITHUB_OUTPUT
echo "codemods=$CHANGED_CODEMODS" >> $GITHUB_OUTPUT
echo "Changed codemods: $CHANGED_CODEMODS"
- name: Comment on PR
if: steps.detect.outputs.has-changes == 'true'
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
// Check if we already commented
const existingComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Auto-publish on merge')
);
if (existingComment) {
console.log('Comment already exists, skipping...');
return;
}
const codemods = '${{ steps.detect.outputs.codemods }}'.split(' ').filter(Boolean);
const commentBody = `## 🚀 Codemods Ready for Auto-Publish
**Changed codemods:** ${codemods.map(c => `\`${c}\``).join(', ')}
These codemods will be **automatically published** to the Codemod Registry when this PR is merged to \`main\`.
**What happens on merge:**
- ✅ Codemods are automatically published to the registry
- ✅ Version conflicts are auto-resolved (patch version bump)
- ✅ Publishing errors are handled gracefully
**Note:** Make sure the \`CODEMOD_API_KEY\` secret is configured in the repository settings for auto-publishing to work.
---
*This comment was automatically generated by the auto-publish detection workflow.*`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});