mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-24 10:58:37 +00:00
fix(release): validate plugin clawhub publish args
This commit is contained in:
@@ -2,21 +2,44 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
echo "usage: bash scripts/plugin-clawhub-publish.sh [--dry-run|--publish|--pack] <package-dir>"
|
||||
}
|
||||
|
||||
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mode="${1:-}"
|
||||
package_dir="${2:-}"
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
repo_root="$(cd "${script_dir}/.." && pwd)"
|
||||
invocation_root="$(pwd)"
|
||||
|
||||
if [[ "${mode}" != "--dry-run" && "${mode}" != "--publish" && "${mode}" != "--pack" ]]; then
|
||||
echo "usage: bash scripts/plugin-clawhub-publish.sh [--dry-run|--publish|--pack] <package-dir>" >&2
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
shift
|
||||
|
||||
if [[ "${1:-}" == "--" ]]; then
|
||||
shift
|
||||
fi
|
||||
package_dir=""
|
||||
if [[ "$#" -gt 0 ]]; then
|
||||
case "$1" in
|
||||
-*) echo "unexpected plugin ClawHub package-dir option: $1" >&2; exit 2 ;;
|
||||
*) package_dir="$1"; shift ;;
|
||||
esac
|
||||
fi
|
||||
if [[ -z "${package_dir}" ]]; then
|
||||
echo "missing package dir" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$#" -gt 0 ]]; then
|
||||
echo "unexpected plugin ClawHub publish argument: $1" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ ! "${package_dir}" =~ ^extensions/[a-z0-9][a-z0-9._-]*$ ]]; then
|
||||
echo "invalid package dir: ${package_dir}" >&2
|
||||
|
||||
@@ -1147,6 +1147,49 @@ describe("buildOpenClawReleaseClawHubRuntimeState", () => {
|
||||
});
|
||||
|
||||
describe("plugin-clawhub-publish.sh", () => {
|
||||
it("prints help before package or ClawHub checks", () => {
|
||||
const output = execFileSync(
|
||||
"bash",
|
||||
[join(process.cwd(), "scripts/plugin-clawhub-publish.sh"), "--help"],
|
||||
{
|
||||
encoding: "utf8",
|
||||
},
|
||||
);
|
||||
|
||||
expect(output.trim()).toBe(
|
||||
"usage: bash scripts/plugin-clawhub-publish.sh [--dry-run|--publish|--pack] <package-dir>",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects option-like package dirs before package or ClawHub checks", () => {
|
||||
expect(() =>
|
||||
execFileSync(
|
||||
"bash",
|
||||
[join(process.cwd(), "scripts/plugin-clawhub-publish.sh"), "--dry-run", "--wat"],
|
||||
{
|
||||
encoding: "utf8",
|
||||
},
|
||||
),
|
||||
).toThrow("unexpected plugin ClawHub package-dir option: --wat");
|
||||
});
|
||||
|
||||
it("rejects extra arguments before package or ClawHub checks", () => {
|
||||
expect(() =>
|
||||
execFileSync(
|
||||
"bash",
|
||||
[
|
||||
join(process.cwd(), "scripts/plugin-clawhub-publish.sh"),
|
||||
"--dry-run",
|
||||
"extensions/demo-plugin",
|
||||
"extra",
|
||||
],
|
||||
{
|
||||
encoding: "utf8",
|
||||
},
|
||||
),
|
||||
).toThrow("unexpected plugin ClawHub publish argument: extra");
|
||||
});
|
||||
|
||||
it("previews the publish command through the ClawHub CLI dry-run preflight", () => {
|
||||
const repoDir = createTempPluginRepo();
|
||||
const binDir = join(repoDir, "bin");
|
||||
|
||||
Reference in New Issue
Block a user