Skip to content

Commit

Permalink
fix: run dist-tag after changeset publish to set latest tag on npm (#…
Browse files Browse the repository at this point in the history
…2199)

Changeset doesn't allow custom tags with prereleases 🤷
changesets/changesets#546
  • Loading branch information
KyleAMathews authored Dec 19, 2024
1 parent e3be748 commit 712241a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/changesets_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
- name: Add latest tag to published packages
if: steps.changesets.outputs.published == 'true'
run: node scripts/tag-latest.mjs
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
"ci:publish": "pnpm '/^ci:publish:.+/'",
"ci:publish:hex-electric": "pnpm run --dir packages/sync-service publish:hex",
"ci:publish:hex-electric-client": "pnpm run --dir packages/elixir-client publish:hex",
"ci:publish:npm": "pnpm changeset publish --tag latest",
"ci:publish:npm": "pnpm changeset publish",
"ci:version": "pnpm exec changeset version",
"example-backend:down": "dotenv -e .env.dev -- docker compose -f .support/docker-compose.yml down --volumes",
"example-backend:just_up": "dotenv -e .env.dev -- docker compose -f ./.support/docker-compose.yml up -d",
"example-backend:up": "pnpm example-backend:down && pnpm example-backend:just_up",
"stylecheck-all": "pnpm --if-present --recursive run stylecheck"
},
"devDependencies": {
"glob": "^10.3.10"
}
}
16 changes: 10 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions scripts/tag-latest.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { glob } from "glob"
import { readFileSync } from "fs"
import { execSync } from "child_process"

async function tagLatest() {
// Find all package.json files in the packages directory
const packageFiles = glob.sync("./packages/*/package.json")

for (const file of packageFiles) {
const pkg = JSON.parse(readFileSync(file))
const { name, version, private: isPrivate } = pkg

if (!name || !version || isPrivate) continue

console.log(`Tagging ${name}@${version} as latest`)
try {
execSync(`npm dist-tag add ${name}@${version} latest`, {
stdio: "inherit",
env: { ...process.env },
})
} catch (e) {
console.error(`Failed to tag ${name}@${version}:`, e)
process.exit(1)
}
}
}

tagLatest().catch((e) => {
console.error(e)
process.exit(1)
})

0 comments on commit 712241a

Please sign in to comment.