Skip to content

Commit 8d72bf8

Browse files
committed
chore: use package@version tags in release workflow
1 parent b3ee76f commit 8d72bf8

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

.changeset/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ Publish locally (usually handled by GitHub Actions):
1919
```bash
2020
npm run release
2121
```
22+
23+
GitHub Actions creates and pushes `package@version` tags after publish.

.github/workflows/release.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,73 @@ jobs:
2828
run: npm run build
2929

3030
- name: Create release PR or publish
31+
id: changesets
3132
uses: changesets/action@v1
3233
with:
3334
commit: "chore: release packages"
3435
title: "chore: release packages"
3536
version: npm run version-packages
3637
publish: npm run release
38+
createGithubReleases: false
3739
env:
3840
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3941
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4042
NPM_CONFIG_PROVENANCE: true
43+
44+
- name: Create package@version tags
45+
if: steps.changesets.outputs.published == 'true'
46+
env:
47+
PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }}
48+
run: |
49+
node <<'EOF'
50+
const { spawnSync } = require("node:child_process");
51+
52+
const publishedPackages = JSON.parse(process.env.PUBLISHED_PACKAGES || "[]");
53+
54+
if (!Array.isArray(publishedPackages) || publishedPackages.length === 0) {
55+
console.log("No published packages found in Changesets output.");
56+
process.exit(0);
57+
}
58+
59+
function run(command, args, options = {}) {
60+
const result = spawnSync(command, args, { stdio: "inherit", ...options });
61+
if (result.status !== 0) {
62+
process.exit(result.status ?? 1);
63+
}
64+
return result;
65+
}
66+
67+
function localTagExists(tag) {
68+
const result = spawnSync("git", ["rev-parse", "-q", "--verify", `refs/tags/${tag}`], {
69+
stdio: "ignore",
70+
});
71+
return result.status === 0;
72+
}
73+
74+
function remoteTagExists(tag) {
75+
const result = spawnSync("git", ["ls-remote", "--tags", "origin", `refs/tags/${tag}`], {
76+
encoding: "utf8",
77+
});
78+
if (result.status !== 0) {
79+
process.exit(result.status ?? 1);
80+
}
81+
return result.stdout.trim().length > 0;
82+
}
83+
84+
for (const pkg of publishedPackages) {
85+
const tag = `${pkg.name}@${pkg.version}`;
86+
87+
if (remoteTagExists(tag)) {
88+
console.log(`Tag already exists on origin: ${tag}`);
89+
continue;
90+
}
91+
92+
if (!localTagExists(tag)) {
93+
console.log(`Creating tag: ${tag}`);
94+
run("git", ["tag", tag]);
95+
}
96+
97+
console.log(`Pushing tag: ${tag}`);
98+
run("git", ["push", "origin", tag]);
99+
}
100+
EOF

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ This package uses a PR-based release workflow with Changesets. Add a changeset i
3232
npm run changeset
3333
```
3434

35+
Published versions are tagged in Git using the `package@version` pattern (for example, `@typespecs/elixir-ast@0.2.0`).
36+
3537
## License
3638

3739
[MIT](./LICENSE)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"format": "tsp format lib/**/*.tsp",
2323
"changeset": "changeset",
2424
"version-packages": "changeset version",
25-
"release": "changeset publish"
25+
"release": "changeset publish --no-git-tag"
2626
},
2727
"peerDependencies": {
2828
"@typespec/compiler": "~1.9.0"

0 commit comments

Comments
 (0)