mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
push prereleases branches
This commit is contained in:
+12
-14
@@ -1,11 +1,15 @@
|
|||||||
import { Buffer } from "node:buffer";
|
import { Buffer } from "node:buffer";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { exec } from "@actions/exec";
|
import { exec } from "@actions/exec";
|
||||||
|
import major from "semver/functions/major.js";
|
||||||
|
import prerelease from "semver/functions/prerelease.js";
|
||||||
import pkgJson from "../package.json" with { type: "json" };
|
import pkgJson from "../package.json" with { type: "json" };
|
||||||
|
|
||||||
const tag = `v${pkgJson.version}`;
|
const tag = `v${pkgJson.version}`;
|
||||||
const releaseLine = `v${pkgJson.version.split(".")[0]}`;
|
const prereleaseTag = prerelease(pkgJson.version)?.[0];
|
||||||
const isPrerelease = pkgJson.version.includes("-");
|
const releaseLine = `v${major(pkgJson.version)}${
|
||||||
|
prereleaseTag === undefined ? "" : `-${prereleaseTag}`
|
||||||
|
}`;
|
||||||
const githubToken = process.env.GITHUB_TOKEN;
|
const githubToken = process.env.GITHUB_TOKEN;
|
||||||
if (!githubToken) {
|
if (!githubToken) {
|
||||||
throw new Error("GITHUB_TOKEN is required");
|
throw new Error("GITHUB_TOKEN is required");
|
||||||
@@ -26,16 +30,10 @@ await exec("git", ["commit", "-m", tag]);
|
|||||||
|
|
||||||
await exec("changeset", ["git-tag"]);
|
await exec("changeset", ["git-tag"]);
|
||||||
|
|
||||||
if (isPrerelease) {
|
await exec(
|
||||||
await exec("git", ["push", "origin", `refs/tags/${tag}`], {
|
"git",
|
||||||
|
["push", "--force", "origin", `HEAD:refs/heads/${releaseLine}`],
|
||||||
|
{
|
||||||
env: gitEnv,
|
env: gitEnv,
|
||||||
});
|
},
|
||||||
} else {
|
);
|
||||||
await exec(
|
|
||||||
"git",
|
|
||||||
["push", "--force", "origin", `HEAD:refs/heads/${releaseLine}`],
|
|
||||||
{
|
|
||||||
env: gitEnv,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user