@@ -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
0 commit comments