Skip to content

Commit 813f235

Browse files
committed
fix auto publish
1 parent 24c3f63 commit 813f235

File tree

2 files changed

+72
-14
lines changed

2 files changed

+72
-14
lines changed

.github/workflows/auto-publish.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ jobs:
1919
with:
2020
fetch-depth: 2 # Need previous commit for diff
2121

22+
- name: Setup pnpm
23+
uses: pnpm/action-setup@v4
24+
with:
25+
version: latest
26+
2227
- name: Setup Node.js
2328
uses: actions/setup-node@v4
2429
with:
2530
node-version: '20.x'
26-
cache: 'npm'
31+
cache: 'pnpm'
2732

2833
- name: Install dependencies
29-
run: npm install
34+
run: pnpm install
3035

3136
- name: Check if auto-publishing is configured
3237
id: check-config

.github/workflows/pr-publish.yml

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: PR Auto-publish Detection
33
on:
44
pull_request:
55
types: [opened, synchronize, reopened]
6-
paths:
7-
- 'recipes/**'
86

97
jobs:
108
detect-and-comment:
@@ -31,16 +29,24 @@ jobs:
3129
if [ -z "$CHANGED_CODEMODS" ]; then
3230
echo "has-changes=false" >> $GITHUB_OUTPUT
3331
echo "No codemod changes detected"
34-
exit 0
32+
else
33+
echo "has-changes=true" >> $GITHUB_OUTPUT
34+
echo "codemods=$CHANGED_CODEMODS" >> $GITHUB_OUTPUT
35+
echo "Changed codemods: $CHANGED_CODEMODS"
36+
fi
37+
38+
- name: Check API key configuration
39+
id: check-api-key
40+
run: |
41+
if [ -z "${{ secrets.CODEMOD_API_KEY }}" ]; then
42+
echo "api-key-configured=false" >> $GITHUB_OUTPUT
43+
echo "API key not configured"
44+
else
45+
echo "api-key-configured=true" >> $GITHUB_OUTPUT
46+
echo "API key is configured"
3547
fi
36-
37-
echo "has-changes=true" >> $GITHUB_OUTPUT
38-
echo "codemods=$CHANGED_CODEMODS" >> $GITHUB_OUTPUT
39-
40-
echo "Changed codemods: $CHANGED_CODEMODS"
4148
4249
- name: Comment on PR
43-
if: steps.detect.outputs.has-changes == 'true'
4450
uses: actions/github-script@v7
4551
with:
4652
script: |
@@ -53,17 +59,23 @@ jobs:
5359
// Check if we already commented
5460
const existingComment = comments.find(comment =>
5561
comment.user.type === 'Bot' &&
56-
comment.body.includes('Auto-publish on merge')
62+
(comment.body.includes('Auto-publish') || comment.body.includes('Codemod Registry'))
5763
);
5864
5965
if (existingComment) {
6066
console.log('Comment already exists, skipping...');
6167
return;
6268
}
6369
70+
const hasChanges = '${{ steps.detect.outputs.has-changes }}' === 'true';
6471
const codemods = '${{ steps.detect.outputs.codemods }}'.split(' ').filter(Boolean);
72+
const apiKeyConfigured = '${{ steps.check-api-key.outputs.api-key-configured }}' === 'true';
73+
74+
let commentBody;
6575
66-
const commentBody = `## 🚀 Codemods Ready for Auto-Publish
76+
if (hasChanges && apiKeyConfigured) {
77+
// Codemod changes + API key configured
78+
commentBody = `## 🚀 Codemods Ready for Auto-Publish
6779
6880
**Changed codemods:** ${codemods.map(c => `\`${c}\``).join(', ')}
6981
@@ -74,10 +86,51 @@ jobs:
7486
- ✅ Version conflicts are auto-resolved (patch version bump)
7587
- ✅ Publishing errors are handled gracefully
7688
77-
**Note:** Make sure the \`CODEMOD_API_KEY\` secret is configured in the repository settings for auto-publishing to work.
89+
---
90+
*This comment was automatically generated by the auto-publish detection workflow.*`;
91+
92+
} else if (hasChanges && !apiKeyConfigured) {
93+
// Codemod changes + no API key
94+
commentBody = `## 📦 Codemods Detected
95+
96+
**Changed codemods:** ${codemods.map(c => `\`${c}\``).join(', ')}
97+
98+
**Auto-publishing is available!** 🎉
99+
100+
These codemods can be **automatically published** to the Codemod Registry when this PR is merged to \`main\`.
101+
102+
**To enable auto-publishing:**
103+
1. Get API key from [https://app.codemod.com/api-keys](https://app.codemod.com/api-keys)
104+
2. Create GitHub Environment: Repository Settings → Environments → New environment (name it \`production\`)
105+
3. Add secret: \`CODEMOD_API_KEY\` with your API key
106+
107+
**What happens when enabled:**
108+
- ✅ Codemods are automatically published to the registry
109+
- ✅ Version conflicts are auto-resolved (patch version bump)
110+
- ✅ Publishing errors are handled gracefully
111+
112+
---
113+
*This comment was automatically generated by the auto-publish detection workflow.*`;
114+
115+
} else {
116+
// No codemod changes
117+
commentBody = `## 📦 Codemod Repository
118+
119+
This repository supports **automatic codemod publishing** to the Codemod Registry.
120+
121+
**To enable auto-publishing:**
122+
1. Get API key from [https://app.codemod.com/api-keys](https://app.codemod.com/api-keys)
123+
2. Create GitHub Environment: Repository Settings → Environments → New environment (name it \`production\`)
124+
3. Add secret: \`CODEMOD_API_KEY\` with your API key
125+
126+
**What happens when enabled:**
127+
- ✅ Codemods in \`recipes/\` are automatically published to the registry
128+
- ✅ Version conflicts are auto-resolved (patch version bump)
129+
- ✅ Publishing errors are handled gracefully
78130
79131
---
80132
*This comment was automatically generated by the auto-publish detection workflow.*`;
133+
}
81134
82135
await github.rest.issues.createComment({
83136
owner: context.repo.owner,

0 commit comments

Comments
 (0)