91 lines
3.8 KiB
YAML
91 lines
3.8 KiB
YAML
name: Build
|
||
|
||
# 触发:组织仓库的两个主分支 push + 手动(fork/PR 运行只做质检不上传,令牌只读)
|
||
on:
|
||
push:
|
||
branches: [develop, codex/editor-backend-integration]
|
||
workflow_dispatch:
|
||
|
||
env:
|
||
GH_PROXY: https://v4.gh-proxy.org
|
||
|
||
jobs:
|
||
build:
|
||
name: Build
|
||
runs-on: ubuntu-latest
|
||
# npm ci(依赖树庞大)+ webpack 4 全量构建,runner 较慢,放宽超时
|
||
timeout-minutes: 60
|
||
steps:
|
||
- uses: https://gitea.com/actions/checkout@v4
|
||
|
||
# 1. 手动安装 Node(runner 没有 hostedtoolcache,与 Backend/Frontend CI 同款)
|
||
- name: Setup Node.js manually
|
||
run: |
|
||
NODE_VERSION="22.23.3"
|
||
NODE_HASH="35947643734"
|
||
echo "Downloading Node.js v${NODE_VERSION} via proxy..."
|
||
curl -fL "${GH_PROXY}/https://github.com/actions/node-versions/releases/download/${NODE_VERSION}-${NODE_HASH}/node-${NODE_VERSION}-linux-x64.tar.gz" -o node.tar.gz
|
||
sudo mkdir -p /opt/hostedtoolcache/node/${NODE_VERSION}/x64
|
||
sudo tar -zxvf node.tar.gz -C /opt/hostedtoolcache/node/${NODE_VERSION}/x64 --strip-components=1
|
||
echo "/opt/hostedtoolcache/node/${NODE_VERSION}/x64/bin" >> "$GITHUB_PATH"
|
||
/opt/hostedtoolcache/node/${NODE_VERSION}/x64/bin/node -v
|
||
/opt/hostedtoolcache/node/${NODE_VERSION}/x64/bin/npm -v
|
||
|
||
# 2. npm 镜像
|
||
- name: Configure npm mirror
|
||
run: npm config set registry https://registry.npmmirror.com
|
||
|
||
# git 依赖(TurboWarp 的 scratch-* 是 git+ssh github 引用)在 runner 上
|
||
# 无法直连 github 且无 ssh 密钥 → 用 insteadOf 整体重写到代理。
|
||
# lock 保持 npm 的规范 ssh 形式(与 package.json 亲和,解析阶段可离线),
|
||
# 真正的 clone/ls-remote 由 git 配置在运行时透明替换。
|
||
- name: Proxy git remotes (insteadOf)
|
||
run: |
|
||
git config --global url."https://v4.gh-proxy.org/https://github.com/".insteadOf "ssh://git@github.com/"
|
||
git config --global url."https://v4.gh-proxy.org/https://github.com/".insteadOf "https://github.com/"
|
||
|
||
- name: Install dependencies
|
||
run: npm ci
|
||
|
||
# 3. micro:bit 包载入(生成物已提交入库则跳过;回退到脚本在线下载走 cross-fetch)
|
||
- name: Get micro:bit payload
|
||
run: |
|
||
if [ -f src/generated/microbit-hex-url.cjs ] && [ -f static/microbit/scratch-microbit-1.2.0.hex ]; then
|
||
echo "生成物已入库,跳过下载"
|
||
else
|
||
npm run prepublish
|
||
fi
|
||
|
||
# 4. 编辑器单元测试(Lint 跳过:menu-bar 存在既有的 24 项 lint 问题)
|
||
- name: Unit tests (sccn)
|
||
run: npx jest --runInBand test/unit/sccn test/unit/reducers/project-state-reducer.test.js
|
||
|
||
# 5. 生产构建:Webpack 4 需要 legacy OpenSSL;ROOT 决定部署子路径
|
||
- name: Build editor (ROOT=/scratch/)
|
||
env:
|
||
NODE_ENV: production
|
||
ROOT: /scratch/
|
||
NODE_OPTIONS: --openssl-legacy-provider
|
||
run: npm run build
|
||
|
||
# 6. 打包 build/(顶层无子目录,解压后直接是一组站点文件:editor.html、getter.js 等)
|
||
- name: Package build
|
||
run: |
|
||
set -eu
|
||
test -f build/editor.html
|
||
TARBALL="scratch-gui-build-${GITHUB_SHA::7}.tar.gz"
|
||
tar -czf "$TARBALL" -C build .
|
||
echo "--- 包内清单(前 20 行)---"
|
||
tar -tzf "$TARBALL" | head -20
|
||
echo "--- 大小 ---"
|
||
ls -lh "$TARBALL"
|
||
|
||
# 7. 上传为 Gitea Actions Artifact(push / 手动触发才上传)
|
||
- name: Upload build artifact
|
||
if: github.event_name != 'pull_request'
|
||
uses: https://gitea.com/actions/upload-artifact@v4
|
||
with:
|
||
name: scratch-gui-build-${{ github.sha }}
|
||
path: scratch-gui-build-*.tar.gz
|
||
retention-days: 30
|