feat: 增加可复用部署工作流工具

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
gouki
2026-07-15 21:49:27 +08:00
co-authored by Cursor
commit ec0f2aab5a
9 changed files with 523 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
name: WeChat Mini Program Preview
description: Publish a WeChat Mini Program preview and generate a QR code.
inputs:
project-path:
description: Repository-relative directory containing project.config.json.
required: true
appid:
description: WeChat Mini Program AppID.
required: true
robot:
description: WeChat CI robot number from 1 to 30.
required: false
default: "1"
private-key-path:
description: Temporary code-upload key path.
required: true
qrcode-output:
description: Destination PNG path.
required: true
version-label:
description: Traceable commit or release label.
required: true
runs:
using: composite
steps:
- name: Publish preview
shell: bash
working-directory: ${{ inputs.project-path }}
env:
MINIAPP_APPID: ${{ inputs.appid }}
MINIAPP_ROBOT: ${{ inputs.robot }}
WECHAT_CI_PRIVATE_KEY_PATH: ${{ inputs.private-key-path }}
MINIAPP_QR_OUTPUT: ${{ inputs.qrcode-output }}
MINIAPP_VERSION_LABEL: ${{ inputs.version-label }}
run: |
temporary_script=".wechat-preview.cjs"
cp "$GITHUB_ACTION_PATH/preview.cjs" "$temporary_script"
trap 'rm -f "$temporary_script"' EXIT
node "$temporary_script"
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
const process = require("node:process");
const ci = require("miniprogram-ci");
function requireEnvironment(name) {
const value = process.env[name];
if (!value) {
throw new Error(`${name} is required.`);
}
return value;
}
async function main() {
const projectPath = process.cwd();
const privateKeyPath = path.resolve(
requireEnvironment("WECHAT_CI_PRIVATE_KEY_PATH"),
);
const qrcodeOutputDest = path.resolve(
requireEnvironment("MINIAPP_QR_OUTPUT"),
);
const appid = requireEnvironment("MINIAPP_APPID");
const robot = Number.parseInt(process.env.MINIAPP_ROBOT ?? "1", 10);
const versionLabel = requireEnvironment("MINIAPP_VERSION_LABEL");
if (!fs.existsSync(path.join(projectPath, "project.config.json"))) {
throw new Error("The working directory must contain project.config.json.");
}
if (!fs.existsSync(privateKeyPath)) {
throw new Error("The WeChat code-upload key file does not exist.");
}
if (!Number.isInteger(robot) || robot < 1 || robot > 30) {
throw new Error("MINIAPP_ROBOT must be an integer from 1 to 30.");
}
const project = new ci.Project({
appid,
type: "miniProgram",
projectPath,
privateKeyPath,
ignores: ["node_modules/**/*", ".git/**/*"],
});
await ci.preview({
project,
desc: `Automated preview ${versionLabel}`.slice(0, 50),
robot,
setting: {
es6: true,
minify: true,
autoPrefixWXSS: true,
},
qrcodeFormat: "image",
qrcodeOutputDest,
onProgressUpdate: (progress) => {
if (typeof progress === "string") {
console.log(progress);
}
},
});
console.log(`Preview QR code created: ${qrcodeOutputDest}`);
}
main().catch((error) => {
console.error(`Mini Program preview failed: ${error.message}`);
process.exitCode = 1;
});