mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-20 18:28:43 +00:00
Compare commits
2 Commits
fix/api-br
...
fix/ci-plu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52f3d43f0b | ||
|
|
f5d94311f4 |
108
.github/workflows/npm-publish.yml
vendored
108
.github/workflows/npm-publish.yml
vendored
@@ -573,7 +573,8 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
# Full history needed for auto-bump: git diff against previous release tag
|
||||
# Full history needed for auto-bump: git diff against the commit npm last published
|
||||
# the plugin from (its gitHead), or the previous release tag
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
|
||||
@@ -615,20 +616,49 @@ jobs:
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 2) Find the previous release tag (exclude the current one)
|
||||
PREV_TAG=$(git tag -l 'v*' --sort=-version:refname \
|
||||
| grep -v "^${CURRENT_TAG}$" | head -1 || echo "")
|
||||
if [ -z "$PREV_TAG" ]; then
|
||||
echo "No previous tag to compare — skipping bump."
|
||||
echo "bumped=false" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
# 2) Baseline: the commit npm recorded (gitHead) for the version its "latest" tag
|
||||
# serves. The previous release tag alone missed a change from a release whose plugin
|
||||
# publish failed or never ran: the next release already had it at its previous tag,
|
||||
# saw no diff, and the change never reached npm. git diff compares trees, so the
|
||||
# commit only has to be in this full-history checkout (fetch-depth: 0), not be an
|
||||
# ancestor of the release. Without a usable gitHead the previous release tag is the
|
||||
# baseline, as before; a registry failure fails the step, like npm_has_version.
|
||||
HEAD_ERR=$(mktemp)
|
||||
HEAD_RC=0
|
||||
PUBLISHED_HEAD=$(npm view "${PKG_NAME}@latest" gitHead 2>"$HEAD_ERR") || HEAD_RC=$?
|
||||
if [ "$HEAD_RC" -ne 0 ]; then
|
||||
echo "::error::npm view ${PKG_NAME}@latest gitHead failed (exit $HEAD_RC)." >&2
|
||||
cat "$HEAD_ERR" >&2
|
||||
exit 1
|
||||
fi
|
||||
rm -f "$HEAD_ERR"
|
||||
BASE=""
|
||||
if [ -z "$PUBLISHED_HEAD" ]; then
|
||||
echo "::warning::npm has no gitHead for ${PKG_NAME}@latest — comparing with the previous release tag."
|
||||
elif [[ ! "$PUBLISHED_HEAD" =~ ^[0-9a-f]{40}$ ]]; then
|
||||
echo "::warning::npm's gitHead for ${PKG_NAME}@latest is not a commit id — comparing with the previous release tag."
|
||||
elif ! git cat-file -e "${PUBLISHED_HEAD}^{commit}" 2>/dev/null; then
|
||||
echo "::warning::${PKG_NAME}@latest was published from ${PUBLISHED_HEAD}, which this checkout does not have — comparing with the previous release tag."
|
||||
else
|
||||
BASE="$PUBLISHED_HEAD"
|
||||
echo "Baseline: ${PKG_NAME}@latest was published from ${BASE}."
|
||||
fi
|
||||
if [ -z "$BASE" ]; then
|
||||
# Previous release tag (exclude the current one)
|
||||
BASE=$(git tag -l 'v*' --sort=-version:refname \
|
||||
| grep -v "^${CURRENT_TAG}$" | head -1 || echo "")
|
||||
if [ -z "$BASE" ]; then
|
||||
echo "No previous tag to compare — skipping bump."
|
||||
echo "bumped=false" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# 3) Check if plugin dir actually changed since that tag. The step runs inside the
|
||||
# plugin folder and git resolves pathspecs against the current directory, so the
|
||||
# 3) Check if plugin dir actually changed since that baseline. The step runs inside
|
||||
# the plugin folder and git resolves pathspecs against the current directory, so the
|
||||
# folder is "." here (the repo-root path matched nothing and no change was ever seen).
|
||||
if git diff --quiet "$PREV_TAG" -- .; then
|
||||
echo "⏭️ No plugin changes since $PREV_TAG — nothing to publish."
|
||||
if git diff --quiet "$BASE" -- .; then
|
||||
echo "⏭️ No plugin changes since $BASE — nothing to publish."
|
||||
echo "bumped=false" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
@@ -699,7 +729,8 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
# Full history needed for auto-bump: git diff against previous release tag
|
||||
# Full history needed for auto-bump: git diff against the commit npm last published
|
||||
# the plugin from (its gitHead), or the previous release tag
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
|
||||
@@ -741,20 +772,49 @@ jobs:
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 2) Find the previous release tag (exclude the current one)
|
||||
PREV_TAG=$(git tag -l 'v*' --sort=-version:refname \
|
||||
| grep -v "^${CURRENT_TAG}$" | head -1 || echo "")
|
||||
if [ -z "$PREV_TAG" ]; then
|
||||
echo "No previous tag to compare — skipping bump."
|
||||
echo "bumped=false" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
# 2) Baseline: the commit npm recorded (gitHead) for the version its "latest" tag
|
||||
# serves. The previous release tag alone missed a change from a release whose plugin
|
||||
# publish failed or never ran: the next release already had it at its previous tag,
|
||||
# saw no diff, and the change never reached npm. git diff compares trees, so the
|
||||
# commit only has to be in this full-history checkout (fetch-depth: 0), not be an
|
||||
# ancestor of the release. Without a usable gitHead the previous release tag is the
|
||||
# baseline, as before; a registry failure fails the step, like npm_has_version.
|
||||
HEAD_ERR=$(mktemp)
|
||||
HEAD_RC=0
|
||||
PUBLISHED_HEAD=$(npm view "${PKG_NAME}@latest" gitHead 2>"$HEAD_ERR") || HEAD_RC=$?
|
||||
if [ "$HEAD_RC" -ne 0 ]; then
|
||||
echo "::error::npm view ${PKG_NAME}@latest gitHead failed (exit $HEAD_RC)." >&2
|
||||
cat "$HEAD_ERR" >&2
|
||||
exit 1
|
||||
fi
|
||||
rm -f "$HEAD_ERR"
|
||||
BASE=""
|
||||
if [ -z "$PUBLISHED_HEAD" ]; then
|
||||
echo "::warning::npm has no gitHead for ${PKG_NAME}@latest — comparing with the previous release tag."
|
||||
elif [[ ! "$PUBLISHED_HEAD" =~ ^[0-9a-f]{40}$ ]]; then
|
||||
echo "::warning::npm's gitHead for ${PKG_NAME}@latest is not a commit id — comparing with the previous release tag."
|
||||
elif ! git cat-file -e "${PUBLISHED_HEAD}^{commit}" 2>/dev/null; then
|
||||
echo "::warning::${PKG_NAME}@latest was published from ${PUBLISHED_HEAD}, which this checkout does not have — comparing with the previous release tag."
|
||||
else
|
||||
BASE="$PUBLISHED_HEAD"
|
||||
echo "Baseline: ${PKG_NAME}@latest was published from ${BASE}."
|
||||
fi
|
||||
if [ -z "$BASE" ]; then
|
||||
# Previous release tag (exclude the current one)
|
||||
BASE=$(git tag -l 'v*' --sort=-version:refname \
|
||||
| grep -v "^${CURRENT_TAG}$" | head -1 || echo "")
|
||||
if [ -z "$BASE" ]; then
|
||||
echo "No previous tag to compare — skipping bump."
|
||||
echo "bumped=false" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# 3) Check if plugin-v2 dir actually changed since that tag. The step runs inside the
|
||||
# plugin folder and git resolves pathspecs against the current directory, so the
|
||||
# 3) Check if plugin-v2 dir actually changed since that baseline. The step runs inside
|
||||
# the plugin folder and git resolves pathspecs against the current directory, so the
|
||||
# folder is "." here (the repo-root path matched nothing and no change was ever seen).
|
||||
if git diff --quiet "$PREV_TAG" -- .; then
|
||||
echo "⏭️ No plugin-v2 changes since $PREV_TAG — nothing to publish."
|
||||
if git diff --quiet "$BASE" -- .; then
|
||||
echo "⏭️ No plugin-v2 changes since $BASE — nothing to publish."
|
||||
echo "bumped=false" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
- **fix(ci):** the OpenCode plugin auto-bump compares each plugin with the commit npm last published it from (its `gitHead`) instead of only the previous release tag, so a plugin change from a release whose plugin publish failed still reaches npm on the next release; with no usable `gitHead` it warns and falls back to the previous tag ([#20629](https://github.com/cheaper-inference/OmniRoute/pull/20629)) — thanks @maxmad64bis
|
||||
@@ -6,6 +6,11 @@
|
||||
// "No plugin changes since <tag> — nothing to publish". @omniroute/opencode-plugin-v2 changed
|
||||
// 18 files between v3.8.52 and v3.8.53 and stayed at 0.1.0 on npm.
|
||||
//
|
||||
// The baseline is the commit npm recorded (gitHead) for the plugin's latest version, falling back
|
||||
// to the previous release tag. The tag alone misses a change from a release whose plugin publish
|
||||
// failed or never ran: the next release already has that change at its previous tag, sees no
|
||||
// diff, and the change never reaches npm (#20297).
|
||||
//
|
||||
// This test runs the real step script from the workflow inside a throwaway git repository.
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
@@ -38,8 +43,12 @@ function git(cwd, ...args) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a repo with tags v1.0.0 (previous release) and v1.0.1 (current), where the plugin
|
||||
* folder changed between them only when `pluginChanged` is true, then runs the bump step in
|
||||
* Builds a repo with an untagged earlier commit, then tags v1.0.0 (previous release) and v1.0.1
|
||||
* (current), where the plugin folder changed between the tags only when `pluginChanged` is true
|
||||
* and between the earlier commit and v1.0.0 only when `changedBeforePrevious` is true. npm's
|
||||
* gitHead for the plugin's latest version is `publishedFrom`: "earlier", "previous" or "current"
|
||||
* name those commits, any other string is answered verbatim, and leaving it out answers with no
|
||||
* gitHead; `headError` fails that lookup with a network error. It then runs the bump step in
|
||||
* the plugin folder with a fake `npm` whose registry holds `published` (the manifest's own
|
||||
* 0.1.0 by default, so the step has something to bump past). A version missing from the
|
||||
* registry answers like npm does (`missing: "e404"`: exit 1 with `code E404`; `"empty"`: exit
|
||||
@@ -48,7 +57,16 @@ function git(cwd, ...args) {
|
||||
*/
|
||||
function runBump(
|
||||
jobName,
|
||||
{ pluginChanged, published = ["0.1.0"], missing = "e404", registryErrors = [], allowFailure }
|
||||
{
|
||||
pluginChanged,
|
||||
changedBeforePrevious = false,
|
||||
publishedFrom,
|
||||
headError = false,
|
||||
published = ["0.1.0"],
|
||||
missing = "e404",
|
||||
registryErrors = [],
|
||||
allowFailure,
|
||||
}
|
||||
) {
|
||||
const pkgDir = PLUGIN_JOBS[jobName];
|
||||
const dir = mkdtempSync(join(tmpdir(), "npm-plugin-bump-"));
|
||||
@@ -65,6 +83,14 @@ function runBump(
|
||||
join(repo, pkgDir, "package.json"),
|
||||
`${JSON.stringify({ name: pkgDir, version: "0.1.0" }, null, 2)}\n`
|
||||
);
|
||||
writeFileSync(
|
||||
join(repo, pkgDir, "index.js"),
|
||||
`export const v = ${changedBeforePrevious ? 0 : 1};\n`
|
||||
);
|
||||
writeFileSync(join(repo, "README.md"), "earlier\n");
|
||||
git(repo, "add", "-A");
|
||||
git(repo, "commit", "-q", "-m", "earlier release");
|
||||
const earlier = git(repo, "rev-parse", "HEAD").trim();
|
||||
writeFileSync(join(repo, pkgDir, "index.js"), "export const v = 1;\n");
|
||||
writeFileSync(join(repo, "README.md"), "root\n");
|
||||
git(repo, "add", "-A");
|
||||
@@ -78,17 +104,34 @@ function runBump(
|
||||
git(repo, "add", "-A");
|
||||
git(repo, "commit", "-q", "-m", "current release");
|
||||
git(repo, "tag", "v1.0.1");
|
||||
const commits = {
|
||||
earlier,
|
||||
previous: git(repo, "rev-parse", "v1.0.0^{commit}").trim(),
|
||||
current: git(repo, "rev-parse", "v1.0.1^{commit}").trim(),
|
||||
};
|
||||
const gitHead = publishedFrom ? (commits[publishedFrom] ?? publishedFrom) : "";
|
||||
|
||||
// Fake npm: `npm view <name>@<v> version` prints <v> when it is in PUBLISHED_VERSIONS,
|
||||
// fails with a network error when it is in REGISTRY_ERRORS, and otherwise answers "not
|
||||
// found" the NPM_MISSING way; every lookup is logged. `npm version patch` bumps the patch.
|
||||
// found" the NPM_MISSING way; every lookup is logged. `npm view <spec> gitHead` prints
|
||||
// PUBLISHED_GITHEAD (nothing when empty, as npm does for a missing field), fails when
|
||||
// GITHEAD_ERROR is set, and logs <spec> separately. `npm version patch` bumps the patch.
|
||||
const fakeNpm = join(bin, "npm");
|
||||
writeFileSync(
|
||||
fakeNpm,
|
||||
[
|
||||
"#!/usr/bin/env node",
|
||||
'const fs = require("node:fs");',
|
||||
"const [cmd, spec] = process.argv.slice(2);",
|
||||
"const [cmd, spec, field] = process.argv.slice(2);",
|
||||
'if (cmd === "view" && field === "gitHead") {',
|
||||
' fs.appendFileSync(process.env.NPM_HEAD_LOG, spec + "\\n");',
|
||||
" if (process.env.GITHEAD_ERROR) {",
|
||||
' console.error("npm error code ETIMEDOUT\\nnpm error network request to the registry failed");',
|
||||
" process.exit(1);",
|
||||
" }",
|
||||
" if (process.env.PUBLISHED_GITHEAD) console.log(process.env.PUBLISHED_GITHEAD);",
|
||||
" process.exit(0);",
|
||||
"}",
|
||||
'if (cmd === "view") {',
|
||||
' const v = spec.slice(spec.lastIndexOf("@") + 1);',
|
||||
' fs.appendFileSync(process.env.NPM_VIEW_LOG, v + "\\n");',
|
||||
@@ -119,6 +162,8 @@ function runBump(
|
||||
writeFileSync(output, "");
|
||||
const viewLog = join(dir, "npm_view.log");
|
||||
writeFileSync(viewLog, "");
|
||||
const headLog = join(dir, "npm_head.log");
|
||||
writeFileSync(headLog, "");
|
||||
const res = spawnSync("bash", ["-e", "-c", step.run], {
|
||||
cwd: join(repo, step["working-directory"]),
|
||||
encoding: "utf8",
|
||||
@@ -131,6 +176,9 @@ function runBump(
|
||||
REGISTRY_ERRORS: registryErrors.join(","),
|
||||
NPM_MISSING: missing,
|
||||
NPM_VIEW_LOG: viewLog,
|
||||
NPM_HEAD_LOG: headLog,
|
||||
PUBLISHED_GITHEAD: gitHead,
|
||||
GITHEAD_ERROR: headError ? "1" : "",
|
||||
},
|
||||
});
|
||||
if (!allowFailure) {
|
||||
@@ -144,6 +192,8 @@ function runBump(
|
||||
output: readFileSync(output, "utf8"),
|
||||
version,
|
||||
viewed: readFileSync(viewLog, "utf8").split("\n").filter(Boolean),
|
||||
headLookups: readFileSync(headLog, "utf8").split("\n").filter(Boolean),
|
||||
commits,
|
||||
};
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
@@ -239,4 +289,86 @@ for (const [jobName, pkgDir] of Object.entries(PLUGIN_JOBS)) {
|
||||
assert.match(result.output, /^bumped=false$/m, result.stdout);
|
||||
assert.equal(result.version, "0.1.0");
|
||||
});
|
||||
|
||||
test(`${jobName}: checkout keeps full history, so npm's published commit is in the clone`, () => {
|
||||
const checkout = workflow.jobs[jobName].steps.find((s) =>
|
||||
String(s.uses ?? "").startsWith("actions/checkout@")
|
||||
);
|
||||
assert.ok(checkout, `${jobName} checks out the repository`);
|
||||
assert.equal(checkout.with?.["fetch-depth"], 0);
|
||||
});
|
||||
|
||||
// npm last published the plugin from the earlier commit; the plugin changed before the
|
||||
// previous release, whose plugin publish failed. The current release leaves the plugin alone,
|
||||
// so the previous tag shows no change and the step skipped it for good.
|
||||
test(`${jobName}: a change since the commit npm last published is bumped even when the previous tag already had it`, () => {
|
||||
const scenario = { pluginChanged: false, changedBeforePrevious: true };
|
||||
const result = runBump(jobName, { ...scenario, publishedFrom: "earlier" });
|
||||
assert.match(result.output, /^bumped=true$/m, result.stdout);
|
||||
assert.equal(result.version, "0.1.1");
|
||||
assert.deepEqual(result.headLookups, [`${pkgDir}@latest`]);
|
||||
assert.ok(result.stdout.includes(result.commits.earlier), result.stdout);
|
||||
|
||||
const tagOnly = runBump(jobName, scenario);
|
||||
assert.match(tagOnly.output, /^bumped=false$/m, "the previous tag alone sees no change");
|
||||
});
|
||||
|
||||
// A re-run of a release whose plugin publish already went through: the previous tag still
|
||||
// differs, but npm already serves this exact plugin folder.
|
||||
test(`${jobName}: no change since the commit npm last published skips the bump`, () => {
|
||||
const result = runBump(jobName, { pluginChanged: true, publishedFrom: "current" });
|
||||
assert.match(result.output, /^bumped=false$/m, result.stdout);
|
||||
assert.equal(result.version, "0.1.0");
|
||||
assert.match(result.stdout, /nothing to publish/);
|
||||
assert.deepEqual(result.viewed, ["0.1.0"], "no candidate is allocated");
|
||||
});
|
||||
|
||||
test(`${jobName}: npm without a gitHead falls back to the previous release tag`, () => {
|
||||
const changed = runBump(jobName, { pluginChanged: true, changedBeforePrevious: true });
|
||||
assert.match(changed.output, /^bumped=true$/m, changed.stdout);
|
||||
assert.equal(changed.version, "0.1.1");
|
||||
assert.match(changed.stdout, /^::warning::npm has no gitHead/m);
|
||||
|
||||
const unchanged = runBump(jobName, { pluginChanged: false, changedBeforePrevious: true });
|
||||
assert.match(unchanged.output, /^bumped=false$/m, unchanged.stdout);
|
||||
assert.equal(unchanged.version, "0.1.0");
|
||||
assert.match(unchanged.stdout, /^::warning::npm has no gitHead/m);
|
||||
});
|
||||
|
||||
test(`${jobName}: a gitHead this checkout does not have falls back to the previous tag with a warning`, () => {
|
||||
const unknown = "0123456789abcdef0123456789abcdef01234567";
|
||||
for (const pluginChanged of [true, false]) {
|
||||
const result = runBump(jobName, {
|
||||
pluginChanged,
|
||||
changedBeforePrevious: true,
|
||||
publishedFrom: unknown,
|
||||
});
|
||||
assert.match(result.output, new RegExp(`^bumped=${pluginChanged}$`, "m"), result.stdout);
|
||||
assert.match(
|
||||
result.stdout,
|
||||
new RegExp(`^::warning::.*${unknown}.*previous release tag`, "m")
|
||||
);
|
||||
}
|
||||
// Registry text that is not a commit id never reaches git or a workflow command.
|
||||
const garbage = runBump(jobName, {
|
||||
pluginChanged: false,
|
||||
changedBeforePrevious: true,
|
||||
publishedFrom: "--output=/dev/null",
|
||||
});
|
||||
assert.match(garbage.output, /^bumped=false$/m, garbage.stdout);
|
||||
assert.match(garbage.stdout, /^::warning::.*not a commit id/m);
|
||||
assert.doesNotMatch(garbage.stdout + garbage.stderr, /--output/);
|
||||
});
|
||||
|
||||
test(`${jobName}: a registry error on the gitHead lookup fails the step`, () => {
|
||||
const result = runBump(jobName, {
|
||||
pluginChanged: true,
|
||||
publishedFrom: "earlier",
|
||||
headError: true,
|
||||
allowFailure: true,
|
||||
});
|
||||
assert.notEqual(result.status, 0, result.stdout);
|
||||
assert.doesNotMatch(result.output, /^bumped=/m);
|
||||
assert.match(result.stdout + result.stderr, /ETIMEDOUT/);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user