Răsfoiți Sursa

feat: 分离编译与发布Actions

HapeLee 3 luni în urmă
părinte
comite
5e3962bd7a

+ 20 - 6
.github/workflows/auto-release.yml

@@ -1,4 +1,4 @@
-name: Auto Release
+name: Auto Build
 
 on:
   push:
@@ -242,15 +242,29 @@ jobs:
           if-no-files-found: ignore
           path: ${{ github.workspace }}/mapping/mapping.txt
 
+      - name: Save release metadata
+        if: matrix.type == 'release'
+        run: |
+          {
+            echo "VERSIONL=${{ needs.prepare.outputs.versionL }}"
+            echo "LATEST_TAG=${{ needs.prepare.outputs.latest_tag }}"
+            echo "IS_RELEASE=${{ needs.prepare.outputs.is_release }}"
+          } > release-metadata.env
+
+      - name: Upload Release Metadata
+        if: matrix.type == 'release'
+        uses: actions/upload-artifact@v4
+        with:
+          name: release-metadata
+          if-no-files-found: error
+          path: release-metadata.env
+
   create_release:
     needs: [ prepare, build ]
+    # 发布已迁移到 release.yml;保留该实现一个周期以避免意外删除历史配置。
     # 仅在所有者的 push 到 main 分支时执行发布
     if: |
-      github.event_name == 'push' &&
-      github.ref == 'refs/heads/main' &&
-      github.actor == 'HapeLee' &&
-      (needs.prepare.outputs.build_number > 0 || needs.prepare.outputs.is_release == 'true') &&
-      success()
+      false
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v5

+ 0 - 21
.github/workflows/build-apk-for-user.yml

@@ -7,10 +7,6 @@ on:
         description: '要构建的分支'
         required: true
         default: 'trae/solo-agent-vhkVM3'
-      release_tag:
-        description: 'Release 标签 (留空则不上传到 Release)'
-        required: false
-        default: ''
 
 permissions:
   contents: write
@@ -90,20 +86,3 @@ jobs:
         with:
           name: legado-apks-zip-${{ github.run_number }}
           path: legado-debug-apks-*.zip
-
-      - name: Create Release and Upload
-        if: ${{ github.event.inputs.release_tag != '' }}
-        uses: softprops/action-gh-release@v2
-        with:
-          tag_name: ${{ github.event.inputs.release_tag }}
-          name: Legado Debug Build ${{ github.event.inputs.release_tag }}
-          body: |
-            自动构建的 Debug 版本
-            - 分支: ${{ github.event.inputs.branch }}
-            - 构建号: ${{ github.run_number }}
-          prerelease: true
-          files: |
-            app/build/outputs/apk/app/debug/*.apk
-            legado-debug-apks-*.zip
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 0 - 52
.github/workflows/codeql.yml

@@ -1,52 +0,0 @@
-name: "CodeQL"
-
-on:
-  push:
-    branches: [ "main" ]
-  pull_request:
-    branches: [ "main" ]
-  schedule:
-    - cron: '25 3 * * 1'
-
-jobs:
-  analyze:
-    name: Analyze (java-kotlin)
-    runs-on: ubuntu-latest
-    permissions:
-      security-events: write
-      packages: read
-      actions: read
-      contents: read
-
-    strategy:
-      fail-fast: false
-      matrix:
-        language: [ 'java-kotlin' ]
-
-    steps:
-      - name: Checkout repository
-        uses: actions/checkout@v4
-
-      - name: Set up JDK 21
-        uses: actions/setup-java@v4
-        with:
-          java-version: '21'
-          distribution: 'temurin'
-
-      - name: Initialize CodeQL
-        uses: github/codeql-action/init@v3
-        with:
-          languages: ${{ matrix.language }}
-          build-mode: manual
-
-      - name: Remove Aliyun mirrors (unreliable in CI)
-        run: |
-          sed -i '/maven.aliyun.com/d' settings.gradle
-
-      - name: Build with Gradle
-        run: ./gradlew assembleAppDebug --no-daemon --no-configuration-cache -Dorg.gradle.warning.mode=none
-
-      - name: Perform CodeQL Analysis
-        uses: github/codeql-action/analyze@v3
-        with:
-          category: "/language:${{ matrix.language }}"

+ 150 - 0
.github/workflows/release.yml

@@ -0,0 +1,150 @@
+name: Release APK
+
+on:
+  workflow_dispatch:
+    inputs:
+      build_run_id:
+        description: '成功的 Auto Build workflow run ID'
+        required: true
+        type: string
+
+permissions:
+  actions: read
+  contents: write
+
+jobs:
+  release:
+    # 与原自动发布权限保持一致;请在仓库 Settings 中按需改成你的 GitHub 用户名。
+    if: github.actor == 'HapeLee'
+    runs-on: ubuntu-latest
+    steps:
+      - name: Download artifacts from the selected build
+        id: build
+        env:
+          GH_TOKEN: ${{ github.token }}
+          RUN_ID: ${{ inputs.build_run_id }}
+        run: |
+          set -euo pipefail
+          api="https://api.github.com/repos/${GITHUB_REPOSITORY}"
+          run=$(curl --fail-with-body -sS \
+            -H "Authorization: Bearer ${GH_TOKEN}" \
+            -H "Accept: application/vnd.github+json" \
+            "${api}/actions/runs/${RUN_ID}")
+          test "$(jq -r '.conclusion' <<<"${run}")" = success
+          test "$(jq -r '.head_branch' <<<"${run}")" = main
+          echo "sha=$(jq -r '.head_sha' <<<"${run}")" >> "$GITHUB_OUTPUT"
+
+          mkdir artifacts
+          curl --fail-with-body -sS \
+            -H "Authorization: Bearer ${GH_TOKEN}" \
+            -H "Accept: application/vnd.github+json" \
+            "${api}/actions/runs/${RUN_ID}/artifacts?per_page=100" > artifacts.json
+          jq -r '.artifacts[] | select(.expired | not) | select(
+            .name == "universal-apk-release" or
+            .name == "arm64-v8a-apk-release" or
+            .name == "armeabi-v7a-apk-release" or
+            .name == "legado.app.release.mapping" or
+            .name == "release-metadata"
+          ) | .archive_download_url' artifacts.json | while read -r url; do
+            curl --fail-with-body -sSL \
+              -H "Authorization: Bearer ${GH_TOKEN}" \
+              -H "Accept: application/vnd.github+json" \
+              "$url" -o artifact.zip
+            unzip -o artifact.zip -d artifacts
+          done
+          test -f artifacts/release-metadata.env
+
+      - name: Check out the built commit
+        uses: actions/checkout@v5
+        with:
+          ref: ${{ steps.build.outputs.sha }}
+          fetch-depth: 0
+
+      - name: Prepare release files and notes
+        id: release
+        run: |
+          set -euo pipefail
+          source artifacts/release-metadata.env
+          test -n "$VERSIONL"
+          mkdir release
+          for apk in artifacts/*.apk; do
+            case "$apk" in
+              *arm64-v8a*) suffix=-arm64-v8a ;;
+              *armeabi-v7a*) suffix=-armeabi-v7a ;;
+              *) suffix= ;;
+            esac
+            mv "$apk" "release/legado-${VERSIONL}${suffix}.apk"
+          done
+          if [ -f artifacts/mapping.txt ]; then mv artifacts/mapping.txt release/; fi
+
+          if [ -n "$LATEST_TAG" ] && git rev-parse -q --verify "refs/tags/$LATEST_TAG" >/dev/null; then
+            notes=$(git log "$LATEST_TAG"..HEAD --pretty=format:'* %s' --no-merges)
+          else
+            notes=$(git log -1 --pretty=format:'* %s')
+          fi
+          [ -n "$notes" ] || notes='- 没有新的 Commit 记录。'
+          {
+            echo 'custom_body<<EOF'
+            if [ "$IS_RELEASE" != true ]; then
+              echo '**此版本为测试版,会存在不稳定问题。**'
+              echo '### [发布页](https://t.me/materado)'
+              echo '### [反馈群组](https://t.me/+Yn1_v5PZqddmMjQ1)'
+              echo
+            fi
+            echo '### 具体更新内容'
+            echo
+            echo "$notes"
+            echo EOF
+          } >> "$GITHUB_OUTPUT"
+          echo "version=$VERSIONL" >> "$GITHUB_OUTPUT"
+          echo "previous_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"
+          echo "prerelease=$([ "$IS_RELEASE" = true ] && echo false || echo true)" >> "$GITHUB_OUTPUT"
+
+      - name: Create tag at the built commit
+        env:
+          VERSION: ${{ steps.release.outputs.version }}
+        run: |
+          if git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then
+            test "$(git rev-list -n 1 "$VERSION")" = "${{ steps.build.outputs.sha }}"
+          else
+            git tag "$VERSION" "${{ steps.build.outputs.sha }}"
+            git push origin "$VERSION"
+
+      - name: Generate GitHub release notes
+        id: notes
+        env:
+          GH_TOKEN: ${{ github.token }}
+          VERSION: ${{ steps.release.outputs.version }}
+          SHA: ${{ steps.build.outputs.sha }}
+          PREVIOUS_TAG: ${{ steps.release.outputs.previous_tag }}
+          CUSTOM_BODY: ${{ steps.release.outputs.custom_body }}
+        run: |
+          set -euo pipefail
+          payload=$(jq -n \
+            --arg tag_name "$VERSION" \
+            --arg target_commitish "$SHA" \
+            --arg previous_tag_name "$PREVIOUS_TAG" \
+            '{tag_name: $tag_name, target_commitish: $target_commitish} +
+              (if $previous_tag_name == "" then {} else {previous_tag_name: $previous_tag_name} end)')
+          generated=$(curl --fail-with-body -sS -X POST \
+            -H "Authorization: Bearer ${GH_TOKEN}" \
+            -H "Accept: application/vnd.github+json" \
+            "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \
+            -d "$payload" | jq -r .body)
+          {
+            echo 'body<<EOF'
+            echo "$generated"
+            echo
+            echo "$CUSTOM_BODY"
+            echo EOF
+          } >> "$GITHUB_OUTPUT"
+          fi
+
+      - name: Create GitHub release
+        uses: softprops/action-gh-release@v2
+        with:
+          tag_name: ${{ steps.release.outputs.version }}
+          name: ${{ steps.release.outputs.prerelease == 'true' && format('Pre-release {0}', steps.release.outputs.version) || format('Release {0}', steps.release.outputs.version) }}
+          body: ${{ steps.notes.outputs.body }}
+          prerelease: ${{ steps.release.outputs.prerelease }}
+          files: release/*