chore: 初始化仓库

This commit is contained in:
Lydanne
2026-02-15 22:02:21 +08:00
commit 08d011d63f
381 changed files with 87202 additions and 0 deletions

13
actions/.gitignore vendored Normal file
View File

@@ -0,0 +1,13 @@
# Dependencies
node_modules/
# Build output
!dist/
# IDE
.idea/
*.swp
*.swo
# OS
.DS_Store

48
actions/action.yml Normal file
View File

@@ -0,0 +1,48 @@
name: "Spaceflow"
description: "Run spaceflow CLI commands in CI workflows"
author: "spaceflow"
inputs:
command:
description: "The spaceflow command to run (e.g. review, publish, ci-scripts, ci-shell, or get-output for extracting cached values)"
required: true
args:
description: "Additional arguments to pass to the command"
required: false
default: ""
from-comment:
description: "Parse command from PR comment (e.g. '/review -v 2 -l openai')"
required: false
default: ""
provider-url:
description: "Git Provider server URL (e.g. https://api.github.com)"
required: false
provider-token:
description: "Git Provider API token"
required: false
working-directory:
description: "Working directory for the command"
required: false
default: "."
dev-mode:
description: "Enable development mode (install deps and use nest to run)"
required: false
default: "false"
event-action:
description: "PR event action (opened, synchronize, closed, etc.)"
required: false
default: ""
outputs:
result:
description: "JSON string of all command outputs"
value:
description: "Extracted value from JSON (for get-output command)"
runs:
using: "node20"
main: "dist/index.js"
branding:
icon: "git-pull-request"
color: "green"

28063
actions/dist/index.js vendored Normal file

File diff suppressed because one or more lines are too long

1
actions/dist/index.js.map vendored Normal file

File diff suppressed because one or more lines are too long

131
actions/dist/licenses.txt vendored Normal file
View File

@@ -0,0 +1,131 @@
@actions/core
MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/exec
MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/http-client
MIT
Actions Http Client for Node.js
Copyright (c) GitHub, Inc.
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/io
MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@fastify/busboy
MIT
Copyright Brian White. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
tunnel
MIT
The MIT License (MIT)
Copyright (c) 2012 Koichi Kobayashi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
undici
MIT
MIT License
Copyright (c) Matteo Collina and Undici contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

1
actions/dist/sourcemap-register.js vendored Normal file

File diff suppressed because one or more lines are too long

19
actions/package.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "spaceflow-actions",
"version": "0.0.0",
"private": true,
"description": "Spaceflow Actions - GitHub/Gitea Actions for CI workflows",
"license": "UNLICENSED",
"main": "dist/index.js",
"scripts": {
"build": "ncc build src/index.js -o dist --source-map --license licenses.txt"
},
"dependencies": {
"@actions/cache": "^5.0.1",
"@actions/core": "^2.0.1",
"@actions/exec": "^2.0.0"
},
"devDependencies": {
"@vercel/ncc": "^0.38.3"
}
}

260
actions/src/index.js Normal file
View File

@@ -0,0 +1,260 @@
const core = require("@actions/core");
const exec = require("@actions/exec");
const path = require("path");
const fs = require("fs");
const os = require("os");
const OUTPUT_MARKER_START = "::spaceflow-output::";
const OUTPUT_MARKER_END = "::end::";
const CACHE_DIR = path.join(os.tmpdir(), "spaceflow-outputs");
/**
* Parse spaceflow output from stdout
* Format: ::spaceflow-output::{"key":"value"}::end::
*/
function parseOutputs(stdout) {
const outputs = {};
const regex = new RegExp(
`${OUTPUT_MARKER_START.replace(/:/g, "\\:")}(.+?)${OUTPUT_MARKER_END.replace(/:/g, "\\:")}`,
"g",
);
let match;
while ((match = regex.exec(stdout)) !== null) {
try {
const parsed = JSON.parse(match[1]);
Object.assign(outputs, parsed);
} catch {
core.warning(`Failed to parse output: ${match[1]}`);
}
}
return outputs;
}
/**
* Get value from object by path (e.g. "data.name" or "version")
*/
function getByPath(obj, pathStr) {
const parts = pathStr.split(".");
let current = obj;
for (const part of parts) {
if (current === null || current === undefined) {
return undefined;
}
current = current[part];
}
return current;
}
/**
* Read outputs from cache file by cacheId
*/
function readFromCache(cacheId) {
const cacheFile = path.join(CACHE_DIR, `${cacheId}.json`);
if (!fs.existsSync(cacheFile)) {
return null;
}
try {
const content = fs.readFileSync(cacheFile, "utf-8");
return JSON.parse(content);
} catch {
return null;
}
}
/**
* Handle get-output command - extract value from cache by cacheId and path
* Usage: get-output --cache-id <uuid> --path <key>
*/
function handleGetOutput(argsStr) {
const args = argsStr.split(/\s+/).filter(Boolean);
let cacheId = "";
let jsonPath = "";
for (let i = 0; i < args.length; i++) {
if ((args[i] === "--cache-id" || args[i] === "-c") && i + 1 < args.length) {
cacheId = args[++i];
} else if ((args[i] === "--path" || args[i] === "-p") && i + 1 < args.length) {
jsonPath = args[++i];
}
}
if (!cacheId) {
core.setFailed("Missing --cache-id argument");
return;
}
if (!jsonPath) {
core.setFailed("Missing --path argument");
return;
}
const cached = readFromCache(cacheId);
if (!cached) {
core.setFailed(`Cache not found for id: ${cacheId}`);
return;
}
const value = getByPath(cached, jsonPath);
if (value === undefined) {
core.setFailed(`Path "${jsonPath}" not found in cached outputs`);
return;
}
const outputValue = typeof value === "object" ? JSON.stringify(value) : String(value);
core.setOutput("value", outputValue);
core.info(`Extracted value: ${outputValue}`);
}
/**
* Parse command from PR comment
* Format: /review [-v <level>] [-l <mode>] [--verify-fixes] ...
* Returns: { command: string, args: string }
*/
function parseFromComment(comment) {
const trimmed = comment.trim();
// 匹配 /command 格式
const match = trimmed.match(/^\/(\S+)\s*(.*)?$/);
if (!match) {
return null;
}
return {
command: match[1],
args: (match[2] || "").trim(),
};
}
async function run() {
try {
let command = core.getInput("command", { required: false });
let args = core.getInput("args");
const fromComment = core.getInput("from-comment");
// 如果提供了 from-comment从评论中解析命令和参数
if (fromComment) {
const parsed = parseFromComment(fromComment);
if (parsed) {
command = parsed.command;
args = parsed.args;
core.info(`📝 从评论解析: command=${command}, args=${args}`);
} else {
core.setFailed(`无法解析评论指令: ${fromComment}`);
return;
}
}
if (!command) {
core.setFailed("Missing command input");
return;
}
// Handle get-output command separately (no CLI execution needed)
if (command === "get-output") {
handleGetOutput(args);
return;
}
// 对于 review 命令,自动添加 --event-action 参数
const eventAction = core.getInput("event-action");
if (command === "review" && eventAction && !args.includes("--event-action")) {
args = args ? `${args} --event-action=${eventAction}` : `--event-action=${eventAction}`;
core.info(` PR 事件类型: ${eventAction}`);
}
const workingDirectory = core.getInput("working-directory") || ".";
const devMode = core.getInput("dev-mode") === "true";
// Get Git Provider server url and token from input or environment variables
const providerUrl = core.getInput("provider-url") || process.env.GIT_PROVIDER_URL || process.env.GITHUB_SERVER_URL || "";
const providerToken =
core.getInput("provider-token") || process.env.GIT_PROVIDER_TOKEN || process.env.GITHUB_TOKEN || "";
// Set environment variables for CLI to use
if (providerUrl) {
core.exportVariable("GIT_PROVIDER_URL", providerUrl);
}
if (providerToken) {
core.exportVariable("GIT_PROVIDER_TOKEN", providerToken);
core.setSecret(providerToken);
}
// Resolve core path - core/ is a sibling directory to actions/ in the repo
const actionsDir = path.resolve(__dirname, "..");
const repoRoot = path.resolve(actionsDir, "..");
// const corePath = path.resolve(repoRoot, "core");
// core.info(`Core path: ${corePath}`);
core.info(`Dev mode: ${devMode}`);
let execCmd;
let cmdArgs;
let execCwd;
if (devMode) {
// Development mode: install deps, build all, then install plugins
core.info("Installing dependencies...");
await exec.exec("pnpm", ["install"], { cwd: repoRoot });
core.info("Building all packages...");
await exec.exec("pnpm", ["run", "setup"], { cwd: repoRoot });
core.info("Installing spaceflow plugins...");
await exec.exec("pnpm", ["spaceflow", "install"], { cwd: repoRoot });
// Run the command
execCmd = "pnpm";
cmdArgs = ["spaceflow", command];
if (args) {
cmdArgs.push(...args.split(/\s+/).filter(Boolean));
}
cmdArgs.push("--ci");
execCwd = repoRoot;
} else {
// Production mode: use npx to install and run from local path
execCmd = "npx";
cmdArgs = ["-y", "spaceflow", command];
if (args) {
cmdArgs.push(...args.split(/\s+/).filter(Boolean));
}
cmdArgs.push("--ci");
execCwd = workingDirectory;
}
core.info(`Running: ${execCmd} ${cmdArgs.join(" ")}`);
core.info(`Working directory: ${execCwd}`);
core.info(`Command: ${command}`);
core.info(`Args: ${args}`);
// Capture stdout to parse outputs
let stdout = "";
const exitCode = await exec.exec(execCmd, cmdArgs, {
cwd: execCwd,
env: {
...process.env,
GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY || "",
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || "",
GITHUB_EVENT_PATH: process.env.GITHUB_EVENT_PATH || "",
},
listeners: {
stdout: (data) => {
stdout += data.toString();
},
},
});
// Parse and set outputs
const outputs = parseOutputs(stdout);
for (const [key, value] of Object.entries(outputs)) {
core.setOutput(key, value);
core.info(`Output: ${key}=${value}`);
}
if (exitCode !== 0) {
core.setFailed(`Command failed with exit code ${exitCode}`);
}
} catch (error) {
core.setFailed(error.message || "An unexpected error occurred");
}
}
run();