Files
lunar-mini/.gitea/workflows/miniapp-preview.yml
T
gouki e076d40daa
Publish Mini Program Dev Version / publish (push) Failing after 4s
Build and Deploy Server / build (push) Failing after 44s
fix: 注册 lunar 专属运行器并修正工作流标签
- 在 doc79 注册 act_runner-lunar(ID 43),模式参考 readitlater
- lunar-node: docker://node:22-bookworm(小程序构建)
- lunar-ci: docker://golang:1.22-bookworm(后端构建)
- 产物挂载 /opt/lunar/ci-artifacts:/ci-artifacts
- .gitignore 补充 web/ 和 .ci-tmp/
2026-08-06 23:27:41 +00:00

99 lines
4.7 KiB
YAML

name: Publish Mini Program Dev Version
on:
push:
branches:
- main
paths:
- "mini/**"
- ".gitea/workflows/miniapp-preview.yml"
jobs:
publish:
# 专属运行器:docker://node:22-bookworm(注册于 doc79,参考 new-pet-node 模式)
runs-on: lunar-node
steps:
- uses: https://gitea.neatcn.com/gouki/action-checkout@v4
with:
# Need recent commit subjects for the WeChat upload remark.
fetch-depth: 20
- name: Verify Node runtime
run: node --version
- name: Install dependencies
working-directory: mini
run: npm ci
- name: Run tests
working-directory: mini
run: npm test -- --runInBand
- name: Configure production API and app version
working-directory: mini
env:
MINIAPP_BUILD_NUMBER: ${{ gitea.run_number }}
MINIAPP_VERSION_OVERRIDE: ${{ vars.MINIAPP_VERSION_OVERRIDE }}
run: |
test -n "$MINIAPP_BUILD_NUMBER"
VERSION="$(node -e 'const {resolveVersion}=require("./ci/resolve-version.cjs"); process.stdout.write(resolveVersion(process.cwd()))')"
test -n "$VERSION"
mkdir -p ci-artifacts
printf '%s\n' "$VERSION" > ci-artifacts/resolved-version.txt
echo "Resolved Mini Program version for build+upload: $VERSION"
- name: Materialize the upload key
env:
WECHAT_CI_PRIVATE_KEY: ${{ secrets.WECHAT_CI_PRIVATE_KEY }}
run: |
test -n "$WECHAT_CI_PRIVATE_KEY"
umask 077
printf '%s' "$WECHAT_CI_PRIVATE_KEY" > "$RUNNER_TEMP/wechat-ci.key"
- name: Upload WeChat development version
working-directory: mini
env:
MINIAPP_APPID: ${{ vars.MINIAPP_APPID }}
MINIAPP_ROBOT: ${{ vars.MINIAPP_ROBOT }}
# Prefer the version resolved before build so UI label matches WeChat upload.
MINIAPP_BUILD_NUMBER: ${{ gitea.run_number }}
MINIAPP_VERSION_OVERRIDE: ${{ vars.MINIAPP_VERSION_OVERRIDE }}
WECHAT_CI_PRIVATE_KEY_PATH: ${{ runner.temp }}/wechat-ci.key
MINIAPP_UPLOAD_RESULT: ${{ gitea.workspace }}/mini/ci-artifacts/upload-result.json
MINIAPP_VERSION_LABEL: ${{ gitea.sha }}
MINIAPP_UPLOAD_DESC_ITEMS: "3"
MINIAPP_UPLOAD_DESC_MAX: "100"
run: |
test -n "$MINIAPP_APPID"
test -n "$MINIAPP_BUILD_NUMBER"
test -s ci-artifacts/resolved-version.txt
RESOLVED_VERSION="$(tr -d '\n' < ci-artifacts/resolved-version.txt)"
# Force upload to the same version that was baked into the JS bundle.
export MINIAPP_VERSION_OVERRIDE="$RESOLVED_VERSION"
mkdir -p ci-artifacts
node -e 'const c=require("./project.config.json"); if(c.appid!==process.env.MINIAPP_APPID){console.error("MINIAPP_APPID mismatch with project.config.json", process.env.MINIAPP_APPID, c.appid); process.exit(1)}'
node -e 'const {resolveVersion}=require("./ci/resolve-version.cjs"); console.log("Resolved Mini Program version:", resolveVersion(process.cwd()))'
node -e 'const {resolveUploadDesc}=require("./ci/resolve-upload-desc.cjs"); console.log("Resolved upload remark:", resolveUploadDesc({repoRoot:require("path").resolve(".."), versionLabel:process.env.MINIAPP_VERSION_LABEL}))'
# Normalize PEM newlines that may be flattened when stored in Secrets.
python3 - <<'PY'
from pathlib import Path
import os
key_path = Path(os.environ["WECHAT_CI_PRIVATE_KEY_PATH"])
text = key_path.read_text()
if "\\n" in text and "BEGIN" in text:
text = text.replace("\\n", "\n")
text = text.replace("\r\n", "\n").strip() + "\n"
key_path.write_text(text)
content = key_path.read_text()
assert "BEGIN" in content and "PRIVATE KEY" in content, "WECHAT_CI_PRIVATE_KEY is not a PEM private key"
print("private_key_lines=", len(content.splitlines()))
PY
node ci/upload-ci.cjs
test -s ci-artifacts/upload-result.json
cat ci-artifacts/upload-result.json
- name: Persist upload result on runner host
run: |
test -s mini/ci-artifacts/upload-result.json
test -d /ci-artifacts
cp mini/ci-artifacts/upload-result.json "/ci-artifacts/miniapp-upload-${{ gitea.sha }}.json"
cp mini/ci-artifacts/upload-result.json /ci-artifacts/miniapp-upload-latest.json
ls -la /ci-artifacts/miniapp-upload-latest.json
echo "Upload result saved on runner host: /opt/lunar/ci-artifacts/miniapp-upload-latest.json"
- name: Remove temporary credentials
if: always()
run: rm -f "$RUNNER_TEMP/wechat-ci.key"