Skip to content

Commit 3c9e85d

Browse files
committed
ci: add npm publish cooldown
1 parent d22ae6b commit 3c9e85d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
env:
1515
MARKETPLACE_PR_TOKEN: ${{ secrets.MARKETPLACE_PR_TOKEN }}
16+
PUBLISH_COOLDOWN_MINUTES: "10"
1617
steps:
1718
- uses: actions/checkout@v4
1819
- uses: pnpm/action-setup@v4
@@ -28,6 +29,9 @@ jobs:
2829
env:
2930
DATABASE_URL: "postgresql://postgres:password@localhost:5432/napgram?schema=public"
3031
- run: pnpm validate
32+
- name: Check publish window
33+
run: |
34+
node --input-type=module -e "import fs from 'fs'; const pkg = JSON.parse(fs.readFileSync('package.json','utf8')); const name = pkg.name; const version = pkg.version; const cooldown = Number(process.env.PUBLISH_COOLDOWN_MINUTES || '10'); if (!Number.isFinite(cooldown) || cooldown <= 0) { console.log('Publish cooldown disabled'); process.exit(0); } const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(name)}`); if (res.status === 404) { console.log('Package not found on registry; skip cooldown check'); process.exit(0); } if (!res.ok) { throw new Error(`Registry request failed: ${res.status}`); } const data = await res.json(); if (data?.versions?.[version]) { console.error(`Version ${version} already published for ${name}`); process.exit(1); } const time = data?.time || {}; const ignore = new Set(['created','modified']); const dates = Object.entries(time).filter(([key]) => !ignore.has(key)).map(([, value]) => new Date(value)).filter((date) => !Number.isNaN(date.valueOf())); if (!dates.length) { console.log('No publish timestamps found'); process.exit(0); } const last = new Date(Math.max(...dates.map((date) => date.valueOf()))); const ageMinutes = (Date.now() - last.getTime()) / 60000; if (ageMinutes < cooldown) { console.error(`Last publish was ${ageMinutes.toFixed(1)} minutes ago; cooldown is ${cooldown} minutes`); process.exit(1); } console.log('Publish window ok');"
3135
- run: pnpm pack:zip
3236
- run: pnpm pack:tgz
3337
- run: pnpm -s marketplace:snippet > marketplace-index-snippet.json

0 commit comments

Comments
 (0)