chore(ci): Release Notes 中的 CHANGELOG部分 回退为2级标题 #84
Workflow file for this run
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: Build Sub-Store module | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| abi: | |
| description: '目标 ABI (all=全部 4 架构)' | |
| default: all | |
| type: choice | |
| options: [all, arm64-v8a, armeabi-v7a, x86_64, x86] | |
| version: | |
| description: 基础版本号 (留空则取 git tag, 如 v1.0.0) | |
| default: '' | |
| node-version: | |
| description: '内置 node 版本 (留空取最新 LTS, 如 22.14.0)' | |
| default: 'lts' | |
| push: | |
| branches: ['main', 'dev'] # main/dev 推送 → canary 构建 | |
| tags: ['v*'] | |
| permissions: | |
| contents: write | |
| jobs: | |
| metadata: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| abi-matrix: ${{ steps.meta.outputs.abi-matrix }} | |
| version: ${{ steps.meta.outputs.version }} | |
| build-type: ${{ steps.meta.outputs.build-type }} | |
| is-tag: ${{ steps.meta.outputs.is-tag }} | |
| is-prerelease: ${{ steps.meta.outputs.is-prerelease }} | |
| publish-update-json: ${{ steps.meta.outputs.publish-update-json }} | |
| steps: | |
| - id: meta | |
| shell: bash | |
| run: | | |
| if [ "${{ inputs.abi || 'all' }}" = "all" ]; then | |
| echo 'abi-matrix=["arm64-v8a","armeabi-v7a","x86_64","x86"]' >> "$GITHUB_OUTPUT" | |
| else | |
| printf 'abi-matrix=["%s"]\n' "${{ inputs.abi }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| tag="${GITHUB_REF_NAME:-}" | |
| version="${{ inputs.version }}" | |
| if [ -z "$version" ] && [[ "$GITHUB_REF" == refs/tags/v* ]]; then | |
| version="$tag" # 发布构建: 用 tag 名 | |
| fi | |
| # canary (main 推送/手动) 未指定版本时留空 → build.sh git describe 取最近 tag | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| is_tag=false | |
| is_prerelease=false | |
| publish_update_json=false | |
| build_type=release | |
| # 手动运行或 main/dev 推送视为 canary 构建; hotfix 属于稳定版修订,alpha/beta/rc 才算预发布。 | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] \ | |
| || [ "${{ github.ref }}" = "refs/heads/main" ] \ | |
| || [ "${{ github.ref }}" = "refs/heads/dev" ]; then | |
| build_type=canary | |
| elif [[ "$version" =~ -(alpha|beta|rc)([.-]|$) ]]; then | |
| is_prerelease=true | |
| build_type=prerelease | |
| elif [[ "$version" == *-hotfix* ]]; then | |
| build_type=hotfix | |
| fi | |
| if [[ "$GITHUB_REF" == refs/tags/v* ]]; then | |
| is_tag=true | |
| # SemVer prerelease tags look like v1.2.3-alpha.1. GitHub release | |
| # gets marked prerelease, and gh-pages update JSON stays on stable. | |
| if [ "$is_prerelease" = "false" ]; then | |
| publish_update_json=true | |
| fi | |
| fi | |
| echo "is-tag=$is_tag" >> "$GITHUB_OUTPUT" | |
| echo "is-prerelease=$is_prerelease" >> "$GITHUB_OUTPUT" | |
| echo "publish-update-json=$publish_update_json" >> "$GITHUB_OUTPUT" | |
| echo "build-type=$build_type" >> "$GITHUB_OUTPUT" | |
| webui: | |
| needs: metadata | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout WebUI repo | |
| uses: actions/checkout@v7 | |
| with: | |
| repository: Delusions6515/Sub-Store-Module-WebUI | |
| path: Sub-Store-Module-WebUI | |
| - name: WebUI commit hash | |
| id: webui-hash | |
| run: echo "hash=$(git -C Sub-Store-Module-WebUI rev-parse HEAD)" >> "$GITHUB_OUTPUT" | |
| # dist 按 WebUI commit hash 缓存 (4 架构共享一份), hash 不变直接复用, 跳过 pnpm install + build | |
| - name: Cache WebUI dist | |
| id: webui-cache | |
| uses: actions/cache@v6 | |
| with: | |
| path: Sub-Store-Module-WebUI/dist | |
| key: webui-dist-${{ steps.webui-hash.outputs.hash }} | |
| - name: Setup pnpm | |
| if: steps.webui-cache.outputs.cache-hit != 'true' | |
| uses: pnpm/action-setup@v6 | |
| with: | |
| version: 11.3.0 | |
| - name: Setup Node.js | |
| if: steps.webui-cache.outputs.cache-hit != 'true' | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: 24 | |
| cache: pnpm | |
| cache-dependency-path: Sub-Store-Module-WebUI/pnpm-lock.yaml | |
| - name: Build WebUI | |
| if: steps.webui-cache.outputs.cache-hit != 'true' | |
| run: | | |
| cd Sub-Store-Module-WebUI | |
| pnpm install --frozen-lockfile | |
| pnpm build | |
| ls -lh dist/ | |
| - name: Upload WebUI artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: sub-store-webui-dist | |
| path: Sub-Store-Module-WebUI/dist | |
| if-no-files-found: error | |
| build: | |
| needs: [metadata, webui] | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| abi: ${{ fromJSON(needs.metadata.outputs.abi-matrix) }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 # 完整历史: versionCode 取 git 提交数 (ZygiskNext 风格) | |
| - name: Download WebUI artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: sub-store-webui-dist | |
| path: webui-dist | |
| - name: Install dependencies | |
| run: sudo apt-get update && sudo apt-get install -y zip unzip xz-utils | |
| # 组件缓存 (bin/ 由 build.sh 自动补齐); 键含 ABI 与 ref, 新 tag 自动刷新, | |
| # 强制刷新可删除 Actions 缓存 (Caches 页) 或清空 bin/ 后重跑。 | |
| - name: Cache bin/ | |
| uses: actions/cache@v6 | |
| with: | |
| path: bin | |
| key: components-${{ runner.os }}-${{ matrix.abi }}-${{ github.ref }} | |
| - name: Build module | |
| env: | |
| TARGET_ABI: ${{ matrix.abi }} | |
| BUILD_TYPE: ${{ needs.metadata.outputs.build-type }} | |
| WEBUI_DIST_DIR: ${{ github.workspace }}/webui-dist | |
| NODE_VERSION: ${{ inputs.node-version }} | |
| run: | | |
| ./build.sh "${{ needs.metadata.outputs.version }}" | |
| ls -lh build/*.zip | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: sub-store-module-${{ matrix.abi }} | |
| path: build/*.zip | |
| if-no-files-found: error | |
| release: | |
| needs: [metadata, build] | |
| if: needs.metadata.outputs.is-tag == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - name: Generate release notes | |
| env: | |
| TAG: ${{ github.ref_name }} | |
| BUILD_TYPE: ${{ needs.metadata.outputs.build-type }} | |
| run: | | |
| args=(--tag "$TAG" --build-type "$BUILD_TYPE") | |
| [ "$BUILD_TYPE" = "release" ] && args+=(--stable-only) | |
| { | |
| python3 gen-changelog.py "${args[@]}" | |
| printf '\n构建记录: %s/%s/actions/runs/%s\n' \ | |
| "${{ github.server_url }}" "${{ github.repository }}" "${{ github.run_id }}" | |
| } > release-notes.md | |
| cat release-notes.md | |
| - name: Create or update release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| TAG: ${{ github.ref_name }} | |
| PRERELEASE: ${{ needs.metadata.outputs.is-prerelease }} | |
| run: | | |
| args=(--title "Sub-Store for Android $TAG") | |
| [ "$PRERELEASE" = "true" ] && args+=(--prerelease --latest=false) | |
| if gh release view "$TAG" >/dev/null 2>&1; then | |
| gh release view "$TAG" --json body --jq .body > current-release-notes.md | |
| awk ' | |
| BEGIN { | |
| while ((getline line < "release-notes.md") > 0) replacement = replacement line ORS | |
| close("release-notes.md") | |
| } | |
| /^##[[:space:]]+What.s Changed[[:space:]]*$/ { | |
| if (!found) printf "%s", replacement | |
| found = 1 | |
| in_changed = 1 | |
| next | |
| } | |
| in_changed && /^##[[:space:]]/ { in_changed = 0 } | |
| !in_changed { print } | |
| ' current-release-notes.md > merged-release-notes.md | |
| gh release edit "$TAG" "${args[@]}" --notes-file merged-release-notes.md | |
| else | |
| gh release create "$TAG" "${args[@]}" --notes-file release-notes.md | |
| fi | |
| gh release upload "$TAG" dist/*.zip --clobber | |
| # 发布 update JSON (各架构分开), 供管理器检测稳定版更新 | |
| # module.prop 的 updateJson 指向 gh-pages 分支上的 update-<abi>.json | |
| update-json: | |
| needs: [metadata, release] | |
| if: needs.metadata.outputs.publish-update-json == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Generate update JSON (各架构分开) + CHANGELOG.md | |
| env: | |
| TAG: ${{ github.ref_name }} | |
| BUILD_TYPE: ${{ needs.metadata.outputs.build-type }} | |
| run: | | |
| VER="${TAG#v}" # version 不带 v, 与 module.prop 保持一致 | |
| CODE=$(git rev-list HEAD --count) | |
| SHA=$(git rev-parse --short HEAD) | |
| # 生成到独立目录 json-out/, 避免与后续 gh-pages checkout 的 untracked 文件冲突 | |
| mkdir -p json-out | |
| for abi in arm64-v8a armeabi-v7a x86_64 x86; do | |
| # zipUrl 文件名里的构建类型与 release 资产的命名对齐 (release/hotfix) | |
| ZIP="sub-store-module-${VER}-${CODE}-${SHA}-${BUILD_TYPE}-${abi}.zip" | |
| cat > "json-out/update-${abi}.json" <<JSON | |
| { | |
| "version": "$VER", | |
| "versionCode": $CODE, | |
| "zipUrl": "https://github.com/Delusions6515/Sub-Store-Module/releases/download/$TAG/$ZIP", | |
| "changelog": "https://raw.githubusercontent.com/Delusions6515/Sub-Store-Module/gh-pages/CHANGELOG.md" | |
| } | |
| JSON | |
| done | |
| # CHANGELOG.md: 最近 4 个版本 (稳定/hotfix 计数, 排除 alpha/beta/rc) | |
| python3 gen-changelog.py --stable-only --with-hotfix > json-out/CHANGELOG.md | |
| ls -l json-out/ | |
| - name: Publish to gh-pages branch | |
| env: | |
| TAG: ${{ github.ref_name }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| if git fetch origin gh-pages:gh-pages 2>/dev/null; then | |
| git checkout gh-pages | |
| else | |
| # 首次: gh-pages 不存在, 用 orphan 分支创建 (清空索引只提交 JSON) | |
| git checkout --orphan gh-pages | |
| git rm -rf --cached . >/dev/null 2>&1 || git rm -rf . >/dev/null 2>&1 || true | |
| fi | |
| cp json-out/update-*.json json-out/CHANGELOG.md . | |
| git add update-*.json CHANGELOG.md | |
| if git commit -m "update json + changelog: $TAG"; then | |
| git push origin gh-pages | |
| else | |
| echo "update json 无变化, 跳过推送" | |
| fi |