Repository navigation
Nightly 发布 #60
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Nightly 发布" | |
| on: | |
| schedule: | |
| - cron: "0 16 * * *" | |
| workflow_dispatch: | |
| concurrency: | |
| group: nightly-release-${{ github.ref }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| actions: read | |
| env: | |
| RELEASE_BRANCH: main | |
| jobs: | |
| validate-nightly: | |
| name: 校验来源并准备 Nightly 元数据 | |
| runs-on: ubuntu-22.04 | |
| timeout-minutes: 10 | |
| outputs: | |
| matrix: ${{ steps.matrix.outputs.matrix }} | |
| tag: ${{ steps.meta.outputs.tag }} | |
| version: ${{ steps.meta.outputs.version }} | |
| release_name: ${{ steps.meta.outputs.release_name }} | |
| release_body: ${{ steps.meta.outputs.release_body }} | |
| source_sha: ${{ steps.meta.outputs.source_sha }} | |
| steps: | |
| - name: 校验仅允许从 main 分支发布 | |
| if: github.ref != format('refs/heads/{0}', env.RELEASE_BRANCH) | |
| run: | | |
| echo "❌ Nightly 发布仅允许从 ${RELEASE_BRANCH} 分支触发,当前来源:${GITHUB_REF}" | |
| exit 1 | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: 生成共享平台矩阵 | |
| id: matrix | |
| run: | | |
| set -euo pipefail | |
| jq -e ' | |
| .include as $rows | | |
| ($rows | type == "array" and length > 0) and | |
| ([$rows[].asset_key] | length == (unique | length)) and | |
| (all($rows[]; | |
| (.platform | type == "string" and length > 0) and | |
| (.name | type == "string" and length > 0) and | |
| (.args | type == "string") and | |
| (.rust_target | type == "string") and | |
| (.asset_os == "linux" or .asset_os == "macos" or .asset_os == "windows") and | |
| (.asset_arch == "x64" or .asset_arch == "arm64") and | |
| (.asset_key | test("^[a-z0-9-]+$")) | |
| )) | |
| ' .github/release-matrix.json >/dev/null | |
| MATRIX="$(jq -c . .github/release-matrix.json)" | |
| echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT" | |
| - name: 生成 Nightly 标签与 Release 信息 | |
| id: meta | |
| run: | | |
| set -euo pipefail | |
| VERSION="$(grep -m 1 -oP '"version"\s*:\s*"\K[^"]+' package.json)" | |
| if [ -z "$VERSION" ]; then | |
| echo "❌ 无法从 package.json 提取版本号" | |
| exit 1 | |
| fi | |
| SOURCE_SHA="$(git rev-parse HEAD)" | |
| DATE_LOCAL="$(TZ=Asia/Shanghai date +%Y%m%d)" | |
| DATE_LABEL="$(TZ=Asia/Shanghai date +%Y-%m-%d)" | |
| SHORT_SHA="$(printf '%s' "$SOURCE_SHA" | cut -c1-7)" | |
| TAG="nightly-${DATE_LOCAL}-${SHORT_SHA}" | |
| RELEASE_NAME="Sea Lantern Nightly ${DATE_LABEL} (${RELEASE_BRANCH}@${SHORT_SHA})" | |
| { | |
| echo "tag=$TAG" | |
| echo "version=$VERSION" | |
| echo "release_name=$RELEASE_NAME" | |
| echo "source_sha=$SOURCE_SHA" | |
| echo "release_body<<EOF" | |
| echo "## 下载说明" | |
| echo "" | |
| echo "每日 0 点自动构建的预览版本,基于最新 main 分支,不保证可用性。" | |
| echo "" | |
| echo "- \`x64-setup.exe\`:Windows 64 位安装包。" | |
| echo "- \`x64_en-US.msi\`:Windows 64 位安装包,适合需要 MSI 的场景。" | |
| echo "- \`Sea.Lantern_${VERSION}_windows_x64_portable.zip\` / \`Sea.Lantern_${VERSION}_windows_arm64_portable.zip\`:Windows 免安装版,解压后直接运行。" | |
| echo "- \`x64.dmg\`:适用于 Intel Mac。" | |
| echo "- \`aarch64.dmg\`:适用于 Apple 芯片 Mac。" | |
| echo "- \`Sea.Lantern_${VERSION}_macos_x64_portable.tar.gz\` / \`Sea.Lantern_${VERSION}_macos_arm64_portable.tar.gz\`:Mac 免安装版,解压后把 \`.app\` 放到任意位置即可打开。" | |
| echo "- \`*.AppImage\`:Linux 免安装版,给文件执行权限后即可直接运行。" | |
| echo "- \`*.deb\` / \`*.rpm\`:Linux 安装包。" | |
| echo "" | |
| echo "本次构建基于 ${RELEASE_BRANCH} 分支提交 ${SHORT_SHA},仅发布在 GitHub Release。" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| test-nightly: | |
| name: 全量检查 (${{ matrix.name }}) | |
| needs: validate-nightly | |
| permissions: | |
| contents: read | |
| timeout-minutes: 60 | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJSON(needs.validate-nightly.outputs.matrix) }} | |
| runs-on: ${{ matrix.platform }} | |
| env: | |
| RUSTFLAGS: "--cfg ci_skip_validation" | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.validate-nightly.outputs.source_sha }} | |
| - name: 安装系统依赖 (Ubuntu 专用) | |
| if: runner.os == 'Linux' | |
| uses: ./.github/actions/install-tauri-dependencies | |
| - name: 设置 pnpm 环境 | |
| uses: ./.github/actions/setup-pnpm | |
| - name: 设置 Rust 环境 | |
| uses: ./.github/actions/setup-rust | |
| with: | |
| components: rustfmt | |
| cache: "true" | |
| - name: 安装前端依赖 | |
| run: pnpm install --frozen-lockfile | |
| - name: 运行前端全量检查 | |
| run: pnpm run fmt:check && pnpm run lint && pnpm run build:check | |
| - name: 运行前端测试 | |
| run: pnpm test | |
| - name: 检查 Rust 格式 | |
| run: cargo fmt --all -- --check | |
| - name: 运行 Rust Check | |
| run: cargo check --workspace --all-targets | |
| - name: 运行 Rust 全量测试 | |
| run: | | |
| cargo test -p sealantern-application | |
| cargo test -p sealantern-core --lib | |
| cargo test -p sealantern-feature | |
| cargo test -p sealantern-infra --all-features | |
| cargo test -p sealantern-contract | |
| cargo test -p sealantern-server | |
| cargo test --bin sealantern -p sealantern | |
| build-tauri-nightly: | |
| name: 构建 Nightly (${{ matrix.name }}) | |
| needs: | |
| - validate-nightly | |
| - test-nightly | |
| permissions: | |
| contents: read | |
| timeout-minutes: 90 | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJSON(needs.validate-nightly.outputs.matrix) }} | |
| runs-on: ${{ matrix.platform }} | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.validate-nightly.outputs.source_sha }} | |
| - name: 安装系统依赖 (Ubuntu 专用) | |
| if: runner.os == 'Linux' | |
| uses: ./.github/actions/install-tauri-dependencies | |
| with: | |
| install-xdg-utils: "true" | |
| - name: 设置 pnpm 环境 | |
| uses: ./.github/actions/setup-pnpm | |
| - name: 设置 Rust 环境 | |
| uses: ./.github/actions/setup-rust | |
| with: | |
| targets: ${{ matrix.rust_target }} | |
| cache: "true" | |
| - name: 安装前端依赖 | |
| run: pnpm install --frozen-lockfile | |
| - name: 构建 Tauri 产物 | |
| uses: tauri-apps/tauri-action@v0 | |
| with: | |
| args: ${{ matrix.args }} -c src-tauri/tauri.conf.json | |
| - name: 收集 Unix 发布产物 | |
| if: runner.os != 'Windows' | |
| shell: bash | |
| env: | |
| ASSET_OS: ${{ matrix.asset_os }} | |
| VERSION: ${{ needs.validate-nightly.outputs.version }} | |
| ASSET_ARCH: ${{ matrix.asset_arch }} | |
| ASSET_KEY: ${{ matrix.asset_key }} | |
| run: | | |
| bash scripts/ci/collect-assets.sh \ | |
| "$ASSET_OS" "$VERSION" "$ASSET_ARCH" "$ASSET_KEY" | |
| - name: 收集并打包 Windows 发布产物 | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| env: | |
| VERSION: ${{ needs.validate-nightly.outputs.version }} | |
| ASSET_ARCH: ${{ matrix.asset_arch }} | |
| ASSET_KEY: ${{ matrix.asset_key }} | |
| run: | | |
| $params = @{ | |
| Version = $env:VERSION | |
| AssetArch = $env:ASSET_ARCH | |
| AssetKey = $env:ASSET_KEY | |
| } | |
| & ./scripts/ci/collect-assets.ps1 @params | |
| - name: 上传本平台构建产物到工作流 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-assets-${{ matrix.asset_key }} | |
| path: ${{ runner.temp }}/release-assets-${{ matrix.asset_key }}/* | |
| if-no-files-found: error | |
| retention-days: 3 | |
| publish-nightly: | |
| name: 汇总并发布 Nightly | |
| needs: | |
| - validate-nightly | |
| - build-tauri-nightly | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| actions: read | |
| contents: write | |
| steps: | |
| - name: 检出发布脚本 | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.validate-nightly.outputs.source_sha }} | |
| - name: 下载全部平台构建产物 | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: release-assets-* | |
| path: release-assets | |
| - name: 校验并直接发布 Nightly Release | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| MATRIX_JSON: ${{ needs.validate-nightly.outputs.matrix }} | |
| TAG: ${{ needs.validate-nightly.outputs.tag }} | |
| RELEASE_NAME: ${{ needs.validate-nightly.outputs.release_name }} | |
| RELEASE_BODY: ${{ needs.validate-nightly.outputs.release_body }} | |
| SOURCE_SHA: ${{ needs.validate-nightly.outputs.source_sha }} | |
| run: | | |
| bash scripts/ci/publish-assets.sh \ | |
| release-assets "$TAG" "$RELEASE_NAME" "$SOURCE_SHA" false true true | |
| cleanup-old-nightly: | |
| name: 清理旧 Nightly 发布 | |
| needs: | |
| - validate-nightly | |
| - publish-nightly | |
| if: ${{ needs.publish-nightly.result == 'success' }} | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: 删除当前 Nightly 之外的旧发布 | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| CURRENT_TAG: ${{ needs.validate-nightly.outputs.tag }} | |
| run: | | |
| set -euo pipefail | |
| mapfile -t NIGHTLY_TAGS < <( | |
| gh api "repos/${GITHUB_REPOSITORY}/releases?per_page=100" --paginate --jq '.[] | select(.prerelease and (.tag_name | startswith("nightly-"))) | .tag_name' | |
| ) | |
| deleted=0 | |
| for tag in "${NIGHTLY_TAGS[@]}"; do | |
| if [ "$tag" = "$CURRENT_TAG" ]; then | |
| continue | |
| fi | |
| echo "删除旧 Nightly Release: $tag" | |
| gh release delete "$tag" --repo "$GITHUB_REPOSITORY" --cleanup-tag -y | |
| deleted=1 | |
| done | |
| if [ "$deleted" -eq 0 ]; then | |
| echo "没有需要清理的旧 Nightly Release。" | |
| fi |