Skip to content

Commit e411474

Browse files
authored
fix: correct release (#6)
1 parent ca214ff commit e411474

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

scripts/release.cjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
// @ts-check
22

3+
// copied from https://github.com/changesets/action/blob/04d574e831923498156e0b2b93152878063203a3/scripts/release.ts
4+
35
const { version } = require("../package.json");
4-
const { exec } = require("@actions/exec");
6+
const { exec, getExecOutput } = require("@actions/exec");
57

68
async function main() {
9+
const tag = `v${version}`;
10+
11+
const { exitCode, stderr } = await getExecOutput(
12+
`git`,
13+
["ls-remote", "--exit-code", "origin", "--tags", `refs/tags/${tag}`],
14+
{ ignoreReturnCode: true }
15+
);
16+
if (exitCode === 0) {
17+
console.log(`Action is not being published because version ${tag} is already published`);
18+
return;
19+
}
20+
/**
21+
* Exit with status "2" when no matching refs are found in the remote repository.
22+
* @see https://git-scm.com/docs/git-ls-remote#Documentation/git-ls-remote.txt---exit-code
23+
*/
24+
if (exitCode !== 2) {
25+
throw new Error(`git ls-remote exited with ${exitCode.toString()}:\n${stderr}`);
26+
}
27+
728
await exec("git", ["checkout", "--detach"]);
829
await exec("git", ["add", "--force", "dist"]);
930
await exec("git", ["commit", "-m", `publish: v${version}`]);
1031

11-
// needs to work, git tag itself is not used
1232
await exec("changeset", ["tag"]);
1333

1434
const [major] = version.split(".");
35+
const branch = `v${major}`;
1536

16-
await exec("git", ["push", "--force", "origin", `HEAD:refs/heads/v${major}`]);
37+
await exec("git", ["push", "--force", "--follow-tags", "origin", `HEAD:refs/heads/${branch}`]);
1738
}
1839

1940
void main();

0 commit comments

Comments
 (0)