-
Notifications
You must be signed in to change notification settings - Fork 1
452 lines (381 loc) · 14.5 KB
/
publish.yml
File metadata and controls
452 lines (381 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
name: Publish n8n Node
on:
workflow_dispatch:
inputs:
version-bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
- prerelease
default: 'patch'
prerelease-tag:
description: 'Prerelease tag (e.g., alpha, beta, rc) - only for prerelease'
required: false
type: string
default: 'beta'
dry-run:
description: 'Dry run (test without publishing)'
required: false
type: boolean
default: false
permissions:
contents: write
packages: write
id-token: write
env:
# These are auto-detected from package.json - no manual config needed
PACKAGE_NAME: ''
REPO_NAME: ${{ github.repository }}
jobs:
validate:
name: Validate & Prepare
runs-on: ubuntu-latest
outputs:
new-version: ${{ steps.version.outputs.new-version }}
package-name: ${{ steps.detect.outputs.package-name }}
should-publish: ${{ steps.check.outputs.should-publish }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Detect package info
id: detect
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
echo "package-name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "📦 Package: $PACKAGE_NAME"
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'pnpm'
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run linting
run: pnpm run lint
continue-on-error: true
- name: Run tests
run: pnpm run test:coverage
continue-on-error: true
- name: Bump version
id: version
run: |
PACKAGE_NAME="${{ steps.detect.outputs.package-name }}"
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Current version: $CURRENT_VERSION"
# Check NPM for existing version
NPM_VERSION=$(npm view $PACKAGE_NAME version 2>/dev/null || echo "0.0.0")
echo "Latest on NPM: $NPM_VERSION"
# Use NPM version as base if it exists
if [ "$NPM_VERSION" != "0.0.0" ]; then
npm version $NPM_VERSION --no-git-tag-version --allow-same-version
fi
# Bump version
if [ "${{ inputs.version-bump }}" = "prerelease" ]; then
NEW_VERSION=$(npm version prerelease --preid=${{ inputs.prerelease-tag }} --no-git-tag-version)
else
NEW_VERSION=$(npm version ${{ inputs.version-bump }} --no-git-tag-version)
fi
NEW_VERSION=${NEW_VERSION#v}
echo "New version: $NEW_VERSION"
echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Sync banner.config version
run: |
NEW_VERSION="${{ steps.version.outputs.new-version }}"
BANNER_FILE="scripts/banner.config"
if [ -f "$BANNER_FILE" ]; then
# Update version in banner.config
node -e "
const fs = require('fs');
const config = JSON.parse(fs.readFileSync('$BANNER_FILE', 'utf8'));
config.version = '$NEW_VERSION';
fs.writeFileSync('$BANNER_FILE', JSON.stringify(config, null, 2) + '\n');
"
echo "✅ Banner config updated to v$NEW_VERSION"
else
echo "ℹ️ No banner.config found, skipping"
fi
- name: Generate banner image
if: hashFiles('scripts/update-banner.js') != ''
run: |
echo "Generating banner image..."
# Check if required secrets are available
if [ -z "$BANNER_API_BASE_URL" ] || [ -z "$BANNER_API_KEY" ]; then
echo "⚠️ BANNER_API_BASE_URL or BANNER_API_KEY not configured"
echo "⚠️ Skipping banner generation - please configure secrets"
exit 0
fi
# Run banner generation
if npm run update:banner; then
echo "✅ Banner generation command completed"
else
echo "❌ Banner generation failed"
exit 1
fi
# Verify the file was created/updated
if [ -f "intro.png" ]; then
echo "✅ intro.png exists ($(stat -c%s intro.png 2>/dev/null || stat -f%z intro.png) bytes)"
else
echo "❌ intro.png not found after generation"
exit 1
fi
env:
BANNER_API_BASE_URL: ${{ secrets.BANNER_API_BASE_URL }}
BANNER_API_KEY: ${{ secrets.BANNER_API_KEY }}
- name: Commit version bump and banner
run: |
# Stage all version-related changes
git add package.json pnpm-lock.yaml 2>/dev/null || true
git add scripts/banner.config 2>/dev/null || true
git add intro.png 2>/dev/null || true
if git diff --cached --quiet; then
echo "No version changes to commit"
else
git commit -m "chore: bump version to v${{ steps.version.outputs.new-version }}"
git push origin ${{ github.ref_name }}
echo "✅ Version bump and banner committed"
fi
- name: Verify package structure
run: |
echo "Verifying n8n community node requirements..."
if ! grep -q "n8n-community-node-package" package.json; then
echo "❌ Missing keyword: n8n-community-node-package"
exit 1
fi
if ! node -e "const pkg = require('./package.json'); if (!pkg.n8n?.nodes?.length) process.exit(1)"; then
echo "❌ Missing n8n.nodes in package.json"
exit 1
fi
echo "✅ Package structure validated"
- name: Build package
run: pnpm run build
- name: Verify build artifacts
run: |
if [ ! -d "dist" ]; then
echo "❌ dist directory not found"
exit 1
fi
# Check for credentials
CRED_FILE=$(node -p "require('./package.json').n8n.credentials[0]" 2>/dev/null || echo "")
if [ -n "$CRED_FILE" ] && [ -f "$CRED_FILE" ]; then
echo "✅ Credentials verified: $CRED_FILE"
fi
# Check for at least one node
NODE_FILE=$(node -p "require('./package.json').n8n.nodes[0]" 2>/dev/null || echo "")
if [ -n "$NODE_FILE" ] && [ -f "$NODE_FILE" ]; then
echo "✅ Node verified: $NODE_FILE"
fi
echo "✅ Build artifacts verified"
- name: Test package pack
run: |
mkdir -p /tmp/test-pack
pnpm pack --pack-destination /tmp/test-pack
echo "✅ Package packed successfully"
- name: Determine if should publish
id: check
run: |
if [ "${{ inputs.dry-run }}" = "true" ]; then
echo "should-publish=false" >> $GITHUB_OUTPUT
echo "🔍 Dry run mode"
else
echo "should-publish=true" >> $GITHUB_OUTPUT
echo "✅ Ready to publish"
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
dist/
package.json
README.md
LICENSE
retention-days: 1
publish-npm:
name: Publish to NPM
runs-on: ubuntu-latest
needs: validate
if: needs.validate.outputs.should-publish == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node.js for NPM
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Verify NPM authentication
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to NPM
run: |
PACKAGE_NAME="${{ needs.validate.outputs.package-name }}"
echo "Publishing $PACKAGE_NAME v${{ needs.validate.outputs.new-version }}..."
pnpm publish --access public --provenance --no-git-checks
echo "✅ Published to NPM"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Verify publication
continue-on-error: true
run: |
sleep 30
PACKAGE_NAME="${{ needs.validate.outputs.package-name }}"
NPM_VERSION=$(npm view $PACKAGE_NAME version 2>/dev/null || echo "not-found")
if [ "$NPM_VERSION" = "${{ needs.validate.outputs.new-version }}" ]; then
echo "✅ Verified: v$NPM_VERSION"
else
echo "⚠️ Propagating..."
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-github:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
needs: validate
if: needs.validate.outputs.should-publish == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node.js for GitHub Packages
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@${{ github.repository_owner }}'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Prepare scoped package
run: |
OWNER="${{ github.repository_owner }}"
REPO_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2)
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.name = '@${OWNER,,}/${REPO_NAME}';
pkg.publishConfig = {
registry: 'https://npm.pkg.github.com',
access: 'public'
};
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
"
echo "✅ Configured for @${{ github.repository_owner }}"
- name: Publish to GitHub Packages
run: |
pnpm publish --provenance --no-git-checks
echo "✅ Published to GitHub Packages"
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [validate, publish-npm, publish-github]
if: needs.validate.outputs.should-publish == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name }}
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Create Git tag
run: |
git tag -a "v${{ needs.validate.outputs.new-version }}" -m "Release v${{ needs.validate.outputs.new-version }}"
git push origin "v${{ needs.validate.outputs.new-version }}"
- name: Generate release notes
run: |
PACKAGE_NAME="${{ needs.validate.outputs.package-name }}"
OWNER="${{ github.repository_owner }}"
REPO=$(echo "${{ github.repository }}" | cut -d'/' -f2)
cat > release_notes.md << EOF
## 🚀 $PACKAGE_NAME v${{ needs.validate.outputs.new-version }}
### 📦 Installation
**n8n Cloud/Self-Hosted:**
Settings → Community Nodes → Install \`$PACKAGE_NAME\`
**npm:**
\`\`\`bash
npm install $PACKAGE_NAME
\`\`\`
### 📍 Package Locations
- [NPM Registry](https://www.npmjs.com/package/$PACKAGE_NAME)
- [GitHub Packages](https://github.com/${{ github.repository }}/packages)
---
**Published:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")
**Commit:** ${{ github.sha }}
EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.validate.outputs.new-version }}
name: v${{ needs.validate.outputs.new-version }}
body_path: release_notes.md
draft: false
prerelease: ${{ contains(needs.validate.outputs.new-version, '-') }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
PACKAGE_NAME="${{ needs.validate.outputs.package-name }}"
echo "## 🎉 Publication Complete!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** v${{ needs.validate.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- ✅ [NPM](https://www.npmjs.com/package/$PACKAGE_NAME)" >> $GITHUB_STEP_SUMMARY
echo "- ✅ [GitHub Packages](https://github.com/${{ github.repository }}/packages)" >> $GITHUB_STEP_SUMMARY
echo "- ✅ [Release](https://github.com/${{ github.repository }}/releases/tag/v${{ needs.validate.outputs.new-version }})" >> $GITHUB_STEP_SUMMARY
notify-failure:
name: Notify on Failure
runs-on: ubuntu-latest
needs: [validate, publish-npm, publish-github, create-release]
if: failure()
steps:
- name: Failure Summary
run: |
echo "## ❌ Publication Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check logs for details." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Workflow:** ${{ github.workflow }}" >> $GITHUB_STEP_SUMMARY
echo "**Run:** ${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY