mirror of
https://github.com/openclaw/clawhub.git
synced 2026-08-14 00:47:57 +00:00
fix(ci): handle initial plugin inspector pushes
This commit is contained in:
@@ -27,7 +27,12 @@ jobs:
|
||||
- name: Fetch previous main commit
|
||||
env:
|
||||
BASE_SHA: ${{ github.event.before }}
|
||||
run: git fetch --no-tags --depth=1 origin "$BASE_SHA"
|
||||
run: |
|
||||
if [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
|
||||
printf '%s\n' "Initial push detected; skipping fetch for the all-zero base SHA."
|
||||
else
|
||||
git fetch --no-tags --depth=1 origin "$BASE_SHA"
|
||||
fi
|
||||
|
||||
- name: Detect pinned Plugin Inspector change
|
||||
id: detect
|
||||
|
||||
@@ -4,9 +4,14 @@ import { resolve } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
const DEPENDENCY_NAME = "@openclaw/plugin-inspector";
|
||||
export const EMPTY_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
||||
const PACKAGE_MANIFEST_FILES = ["package.json", "packages/clawhub/package.json"];
|
||||
const PACKAGE_MANAGER_FILES = new Set([...PACKAGE_MANIFEST_FILES, "bun.lock"]);
|
||||
|
||||
export function normalizeBaseSha(base) {
|
||||
return base === "0".repeat(40) ? EMPTY_TREE_SHA : base;
|
||||
}
|
||||
|
||||
export function readPinnedPluginInspectorVersion(packageJsonText) {
|
||||
const parsed = JSON.parse(packageJsonText);
|
||||
for (const field of [
|
||||
@@ -103,6 +108,9 @@ function git(args) {
|
||||
}
|
||||
|
||||
function readPackageJsonsAt(ref) {
|
||||
if (ref === EMPTY_TREE_SHA) {
|
||||
return Object.fromEntries(PACKAGE_MANIFEST_FILES.map((file) => [file, "{}"]));
|
||||
}
|
||||
return Object.fromEntries(
|
||||
PACKAGE_MANIFEST_FILES.map((file) => [file, git(["show", `${ref}:${file}`])]),
|
||||
);
|
||||
@@ -129,9 +137,10 @@ function writeOutput(result) {
|
||||
|
||||
export function main(argv = process.argv.slice(2)) {
|
||||
const { base, head } = parseArgs(argv);
|
||||
const normalizedBase = normalizeBaseSha(base);
|
||||
const result = detectPinnedPluginInspectorChange({
|
||||
changedFiles: changedFilesBetween(base, head),
|
||||
basePackageJsonByPath: readPackageJsonsAt(base),
|
||||
changedFiles: changedFilesBetween(normalizedBase, head),
|
||||
basePackageJsonByPath: readPackageJsonsAt(normalizedBase),
|
||||
headPackageJsonByPath: readPackageJsonsAt(head),
|
||||
});
|
||||
writeOutput(result);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
detectPinnedPluginInspectorChange,
|
||||
EMPTY_TREE_SHA,
|
||||
normalizeBaseSha,
|
||||
readPinnedPluginInspectorVersion,
|
||||
} from "./plugin-inspector-pin-change.mjs";
|
||||
|
||||
@@ -18,6 +20,11 @@ const packageJsonsByPath = (rootVersion, cliVersion = rootVersion) => ({
|
||||
});
|
||||
|
||||
describe("plugin inspector pin change detection", () => {
|
||||
it("uses the empty tree for an initial push base SHA", () => {
|
||||
expect(normalizeBaseSha("0".repeat(40))).toBe(EMPTY_TREE_SHA);
|
||||
expect(normalizeBaseSha("abc123")).toBe("abc123");
|
||||
});
|
||||
|
||||
it("detects merged changes to the pinned plugin inspector dependency", () => {
|
||||
expect(
|
||||
detectPinnedPluginInspectorChange({
|
||||
|
||||
@@ -112,6 +112,10 @@ describe("package publish workflow", () => {
|
||||
expect(workflowText).toContain("dry_run=false");
|
||||
expect(workflowText).toContain("BASE_SHA: ${{ github.event.before }}");
|
||||
expect(workflowText).toContain("HEAD_SHA: ${{ github.sha }}");
|
||||
expect(workflowText).toContain(
|
||||
'if [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]',
|
||||
);
|
||||
expect(workflowText).toContain("skipping fetch for the all-zero base SHA");
|
||||
expect(workflowText).toContain("source_sha=${{ github.sha }}");
|
||||
expect(workflowText).not.toContain("pull_request_target");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user