mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 12:30:22 +00:00
fix: keep beta on newer prereleases
This commit is contained in:
@@ -2,7 +2,7 @@ import { execFileSync } from "node:child_process";
|
||||
import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { parseReleaseVersion } from "../openclaw-npm-release-check.ts";
|
||||
import { parseReleaseVersion, resolveNpmPublishPlan } from "../openclaw-npm-release-check.ts";
|
||||
|
||||
export type PluginPackageJson = {
|
||||
name?: string;
|
||||
@@ -235,7 +235,7 @@ export function collectPublishablePluginPackages(
|
||||
packageName: packageJson.name!.trim(),
|
||||
version,
|
||||
channel: parsedVersion.channel,
|
||||
publishTag: parsedVersion.channel === "beta" ? "beta" : "latest",
|
||||
publishTag: resolveNpmPublishPlan(version).publishTag,
|
||||
installNpmSpec: packageJson.openclaw?.install?.npmSpec?.trim() || undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,18 +10,31 @@ if [[ "${mode}" != "--publish" ]]; then
|
||||
fi
|
||||
|
||||
package_version="$(node -p "require('./package.json').version")"
|
||||
publish_cmd=(npm publish --access public --provenance)
|
||||
release_channel="stable"
|
||||
current_beta_version="$(npm view openclaw dist-tags.beta 2>/dev/null || true)"
|
||||
mapfile -t publish_plan < <(
|
||||
PACKAGE_VERSION="${package_version}" CURRENT_BETA_VERSION="${current_beta_version}" node --import tsx --input-type=module <<'EOF'
|
||||
import { resolveNpmPublishPlan } from "./scripts/openclaw-npm-release-check.ts";
|
||||
|
||||
if [[ "${package_version}" == *-beta.* ]]; then
|
||||
publish_cmd=(npm publish --access public --tag beta --provenance)
|
||||
release_channel="beta"
|
||||
elif [[ "${package_version}" == *-* ]]; then
|
||||
publish_cmd=(npm publish --access public --tag latest --provenance)
|
||||
fi
|
||||
const plan = resolveNpmPublishPlan(
|
||||
process.env.PACKAGE_VERSION ?? "",
|
||||
process.env.CURRENT_BETA_VERSION,
|
||||
);
|
||||
console.log(plan.channel);
|
||||
console.log(plan.publishTag);
|
||||
console.log(plan.mirrorDistTags.join(","));
|
||||
EOF
|
||||
)
|
||||
|
||||
release_channel="${publish_plan[0]}"
|
||||
publish_tag="${publish_plan[1]}"
|
||||
mirror_dist_tags_csv="${publish_plan[2]:-}"
|
||||
publish_cmd=(npm publish --access public --tag "${publish_tag}" --provenance)
|
||||
|
||||
echo "Resolved package version: ${package_version}"
|
||||
echo "Current beta dist-tag: ${current_beta_version:-<missing>}"
|
||||
echo "Resolved release channel: ${release_channel}"
|
||||
echo "Resolved publish tag: ${publish_tag}"
|
||||
echo "Resolved mirror dist-tags: ${mirror_dist_tags_csv:-<none>}"
|
||||
echo "Publish auth: GitHub OIDC trusted publishing"
|
||||
|
||||
printf 'Publish command:'
|
||||
@@ -29,3 +42,12 @@ printf ' %q' "${publish_cmd[@]}"
|
||||
printf '\n'
|
||||
|
||||
"${publish_cmd[@]}"
|
||||
|
||||
if [[ -n "${mirror_dist_tags_csv}" ]]; then
|
||||
IFS=',' read -r -a mirror_dist_tags <<< "${mirror_dist_tags_csv}"
|
||||
for dist_tag in "${mirror_dist_tags[@]}"; do
|
||||
[[ -n "${dist_tag}" ]] || continue
|
||||
echo "Mirroring openclaw@${package_version} onto dist-tag ${dist_tag}"
|
||||
npm dist-tag add "openclaw@${package_version}" "${dist_tag}"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -37,6 +37,12 @@ export type ParsedReleaseTag = {
|
||||
date: Date;
|
||||
};
|
||||
|
||||
export type NpmPublishPlan = {
|
||||
channel: "stable" | "beta";
|
||||
publishTag: "latest" | "beta";
|
||||
mirrorDistTags: ("latest" | "beta")[];
|
||||
};
|
||||
|
||||
const STABLE_VERSION_REGEX = /^(?<year>\d{4})\.(?<month>[1-9]\d?)\.(?<day>[1-9]\d?)$/;
|
||||
const BETA_VERSION_REGEX =
|
||||
/^(?<year>\d{4})\.(?<month>[1-9]\d?)\.(?<day>[1-9]\d?)-beta\.(?<beta>[1-9]\d*)$/;
|
||||
@@ -139,6 +145,68 @@ export function parseReleaseVersion(version: string): ParsedReleaseVersion | nul
|
||||
return null;
|
||||
}
|
||||
|
||||
export function compareReleaseVersions(left: string, right: string): number | null {
|
||||
const parsedLeft = parseReleaseVersion(left);
|
||||
const parsedRight = parseReleaseVersion(right);
|
||||
if (parsedLeft === null || parsedRight === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const dateDelta = parsedLeft.date.getTime() - parsedRight.date.getTime();
|
||||
if (dateDelta !== 0) {
|
||||
return Math.sign(dateDelta);
|
||||
}
|
||||
|
||||
if (parsedLeft.channel !== parsedRight.channel) {
|
||||
return parsedLeft.channel === "stable" ? 1 : -1;
|
||||
}
|
||||
|
||||
if (parsedLeft.channel === "beta" && parsedRight.channel === "beta") {
|
||||
return Math.sign((parsedLeft.betaNumber ?? 0) - (parsedRight.betaNumber ?? 0));
|
||||
}
|
||||
|
||||
return Math.sign((parsedLeft.correctionNumber ?? 0) - (parsedRight.correctionNumber ?? 0));
|
||||
}
|
||||
|
||||
export function resolveNpmPublishPlan(
|
||||
version: string,
|
||||
currentBetaVersion?: string | null,
|
||||
): NpmPublishPlan {
|
||||
const parsedVersion = parseReleaseVersion(version);
|
||||
if (parsedVersion === null) {
|
||||
throw new Error(`Unsupported release version "${version}".`);
|
||||
}
|
||||
|
||||
if (parsedVersion.channel === "beta") {
|
||||
return {
|
||||
channel: "beta",
|
||||
publishTag: "beta",
|
||||
mirrorDistTags: [],
|
||||
};
|
||||
}
|
||||
|
||||
const normalizedCurrentBeta = currentBetaVersion?.trim();
|
||||
if (normalizedCurrentBeta) {
|
||||
const betaVsStable = compareReleaseVersions(normalizedCurrentBeta, version);
|
||||
if (betaVsStable !== null && betaVsStable > 0) {
|
||||
return {
|
||||
channel: "stable",
|
||||
publishTag: "latest",
|
||||
// Keep beta on the newer prerelease train when one already exists.
|
||||
mirrorDistTags: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
channel: "stable",
|
||||
publishTag: "latest",
|
||||
// Stable promotion keeps beta aligned unless beta already points at a
|
||||
// newer prerelease train.
|
||||
mirrorDistTags: ["beta"],
|
||||
};
|
||||
}
|
||||
|
||||
export function parseReleaseTagVersion(version: string): ParsedReleaseTag | null {
|
||||
const trimmed = version.trim();
|
||||
if (!trimmed) {
|
||||
|
||||
@@ -17,20 +17,33 @@ fi
|
||||
|
||||
package_name="$(node -e 'const pkg = require(require("node:path").resolve(process.argv[1], "package.json")); console.log(pkg.name)' "${package_dir}")"
|
||||
package_version="$(node -e 'const pkg = require(require("node:path").resolve(process.argv[1], "package.json")); console.log(pkg.version)' "${package_dir}")"
|
||||
publish_cmd=(npm publish --access public --provenance)
|
||||
release_channel="stable"
|
||||
current_beta_version="$(npm view "${package_name}" dist-tags.beta 2>/dev/null || true)"
|
||||
mapfile -t publish_plan < <(
|
||||
PACKAGE_VERSION="${package_version}" CURRENT_BETA_VERSION="${current_beta_version}" node --import tsx --input-type=module <<'EOF'
|
||||
import { resolveNpmPublishPlan } from "./scripts/openclaw-npm-release-check.ts";
|
||||
|
||||
if [[ "${package_version}" == *-beta.* ]]; then
|
||||
publish_cmd=(npm publish --access public --tag beta --provenance)
|
||||
release_channel="beta"
|
||||
elif [[ "${package_version}" == *-* ]]; then
|
||||
publish_cmd=(npm publish --access public --tag latest --provenance)
|
||||
fi
|
||||
const plan = resolveNpmPublishPlan(
|
||||
process.env.PACKAGE_VERSION ?? "",
|
||||
process.env.CURRENT_BETA_VERSION,
|
||||
);
|
||||
console.log(plan.channel);
|
||||
console.log(plan.publishTag);
|
||||
console.log(plan.mirrorDistTags.join(","));
|
||||
EOF
|
||||
)
|
||||
|
||||
release_channel="${publish_plan[0]}"
|
||||
publish_tag="${publish_plan[1]}"
|
||||
mirror_dist_tags_csv="${publish_plan[2]:-}"
|
||||
publish_cmd=(npm publish --access public --tag "${publish_tag}" --provenance)
|
||||
|
||||
echo "Resolved package dir: ${package_dir}"
|
||||
echo "Resolved package name: ${package_name}"
|
||||
echo "Resolved package version: ${package_version}"
|
||||
echo "Current beta dist-tag: ${current_beta_version:-<missing>}"
|
||||
echo "Resolved release channel: ${release_channel}"
|
||||
echo "Resolved publish tag: ${publish_tag}"
|
||||
echo "Resolved mirror dist-tags: ${mirror_dist_tags_csv:-<none>}"
|
||||
echo "Publish auth: GitHub OIDC trusted publishing"
|
||||
|
||||
printf 'Publish command:'
|
||||
@@ -44,4 +57,13 @@ fi
|
||||
(
|
||||
cd "${package_dir}"
|
||||
"${publish_cmd[@]}"
|
||||
|
||||
if [[ -n "${mirror_dist_tags_csv}" ]]; then
|
||||
IFS=',' read -r -a mirror_dist_tags <<< "${mirror_dist_tags_csv}"
|
||||
for dist_tag in "${mirror_dist_tags[@]}"; do
|
||||
[[ -n "${dist_tag}" ]] || continue
|
||||
echo "Mirroring ${package_name}@${package_version} onto dist-tag ${dist_tag}"
|
||||
npm dist-tag add "${package_name}@${package_version}" "${dist_tag}"
|
||||
done
|
||||
fi
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user