📦 ALLG999 @ 构建027魔改版本 #307
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: 📦构建027魔改版本 | |
| run-name: 📦 ${{ github.actor }} @ 构建027魔改版本 | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 设置时区为亚洲/上海 | |
| run: | | |
| sudo timedatectl set-timezone Asia/Shanghai | |
| echo "当前时间: $(date)" | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: 设置 JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "17" | |
| distribution: "zulu" | |
| cache: gradle | |
| - name: 设置 Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| with: | |
| cache-read-only: false | |
| gradle-version: wrapper | |
| - name: 授予 gradlew 执行权限 | |
| run: chmod +x gradlew | |
| - name: 使用 Gradle 构建 | |
| run: ./gradlew assembleNormalRelease assembleCompatibleRelease -Pversion=${{ github.ref_name }} | |
| - name: 定位 APK 文件并设置输出 | |
| id: locate_apks | |
| run: | | |
| normal_apk=$(find app/build/outputs/apk/normal/release -name "*.apk" | head -n 1) | |
| compatible_apk=$(find app/build/outputs/apk/compatible/release -name "*.apk" | head -n 1) | |
| echo "normal_apk=$normal_apk" >> $GITHUB_OUTPUT | |
| echo "compatible_apk=$compatible_apk" >> $GITHUB_OUTPUT | |
| - name: 复制 APK 文件到暂存目录用于签名 | |
| run: | | |
| mkdir -p app/build/outputs/apk/all | |
| cp "${{ steps.locate_apks.outputs.normal_apk }}" app/build/outputs/apk/all/ | |
| cp "${{ steps.locate_apks.outputs.compatible_apk }}" app/build/outputs/apk/all/ | |
| - name: 签名 APK 文件 | |
| id: sign_apks | |
| uses: ilharp/sign-android-release@v2 | |
| with: | |
| releaseDir: app/build/outputs/apk/all | |
| signingKey: ${{ secrets.ANDROID_SIGNING_KEY }} | |
| keyAlias: ${{ secrets.ANDROID_KEY_ALIAS }} | |
| keyStorePassword: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} | |
| keyPassword: ${{ secrets.ANDROID_KEY_PASSWORD }} | |
| buildToolsVersion: 36.0.0 | |
| - name: 提取已签名 APK 路径 | |
| id: extract_apks | |
| run: | | |
| IFS=':' read -r -a files <<< "${{ steps.sign_apks.outputs.signedFiles }}" | |
| for file in "${files[@]}"; do | |
| if [[ "$file" == *Normal* ]]; then | |
| echo "signed_normal=$file" >> $GITHUB_OUTPUT | |
| elif [[ "$file" == *Compatible* ]]; then | |
| echo "signed_compatible=$file" >> $GITHUB_OUTPUT | |
| fi | |
| done | |
| - name: 上传 APK - 兼容版 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: apk-compatible | |
| path: ${{ steps.extract_apks.outputs.signed_compatible }} | |
| - name: 上传 APK - 标准版 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: apk-normal | |
| path: ${{ steps.extract_apks.outputs.signed_normal }} | |
| - name: 提取文件信息 | |
| id: extract_info | |
| run: | | |
| normal_file=$(basename "${{ steps.extract_apks.outputs.signed_normal }}") | |
| compatible_file=$(basename "${{ steps.extract_apks.outputs.signed_compatible }}") | |
| # 提取版本号(以"Normal-"或"Compatible-"之后的部分为起点,以"-signed"之前的内容为终点) | |
| version=$(echo "$normal_file" | sed -E 's/.*-(Normal|Compatible)-(v[^-]+).*-signed\.apk/\2/') | |
| echo "normal_file=$normal_file" >> $GITHUB_OUTPUT | |
| echo "compatible_file=$compatible_file" >> $GITHUB_OUTPUT | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| - name: 生成 APK 校验和 | |
| run: | | |
| sha256sum ${{ steps.extract_apks.outputs.signed_normal }} > CHECKSUMS-Sesame-Normal-${{ steps.extract_info.outputs.version }}.${{ env.SHORT_SHA }}-signed.apk.sha256 | |
| sha256sum ${{ steps.extract_apks.outputs.signed_compatible }} > CHECKSUMS-Sesame-Compatible-${{ steps.extract_info.outputs.version }}.${{ env.SHORT_SHA }}-signed.apk.sha256 | |
| - name: 根据版本创建标签(仅当未存在时) | |
| env: | |
| VERSION_TAG: "v${{ steps.extract_info.outputs.version }}" | |
| run: | | |
| echo "尝试创建标签: $VERSION_TAG" | |
| # 检查远程是否已有该 tag,避免冲突 | |
| if git ls-remote --tags origin "$VERSION_TAG" | grep -q "$VERSION_TAG"; then | |
| echo "Tag $VERSION_TAG 已存在,跳过创建。" | |
| else | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "$VERSION_TAG" | |
| git push origin "$VERSION_TAG" | |
| echo "✅ 标签 $VERSION_TAG 创建成功!" | |
| fi | |
| - name: 发布到频道 | |
| env: | |
| CHANNEL_ID: ${{ secrets.TG_CHAT_ID }} | |
| BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} | |
| NORMAL_FILE: ${{ steps.extract_apks.outputs.signed_normal }} | |
| COMPATIBLE_FILE: ${{ steps.extract_apks.outputs.signed_compatible }} | |
| COMMIT_MESSAGE: |+ | |
| New push to github\! | |
| ``` | |
| ${{ github.event.head_commit.message }} | |
| ```by `${{ github.event.head_commit.author.name }}` | |
| See commit detail [here](${{ github.event.head_commit.url }}) | |
| run: | | |
| ESCAPED=$(python3 -c 'import json, os, urllib.parse; print(urllib.parse.quote(json.dumps(os.environ["COMMIT_MESSAGE"])))') | |
| curl -v "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup?chat_id=${CHANNEL_ID}&media=%5B%7B%22type%22:%22document%22,%20%22media%22:%22attach://normal.apk%22,%22parse_mode%22:%22MarkdownV2%22,%22caption%22:${ESCAPED}%7D,%20%7B%22type%22:%22document%22,%22media%22:%22attach://compatible.apk%22%7D%5D" \ | |
| -F "normal.apk=@${NORMAL_FILE}" \ | |
| -F "compatible.apk=@${COMPATIBLE_FILE}" | |
| - name: 上传资源到源代码发布 | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: ${{ github.event.release.tag_name || steps.extract_info.outputs.version }} | |
| files: | | |
| ${{ steps.extract_apks.outputs.signed_compatible }} | |
| ${{ steps.extract_apks.outputs.signed_normal }} | |
| CHECKSUMS-Sesame-Normal-${{ steps.extract_info.outputs.version }}.${{ env.SHORT_SHA }}-signed.apk.sha256 | |
| CHECKSUMS-Sesame-Compatible-${{ steps.extract_info.outputs.version }}.${{ env.SHORT_SHA }}-signed.apk.sha256 | |
| tag_name: ${{ steps.extract_info.outputs.version}} | |
| draft: false | |
| append_body: true | |
| generate_release_notes: true | |
| body: | | |
| ## ✨魔改版更新内容 | |
| ${{ steps.commit_details.outputs.COMMIT_MESSAGE_BODY }} | |
| > ## 下载说明 | |
| * Normal 为正常版本,适用于`Android 8.0`及以上的系统 | |
| * Compatible 为兼容版本,适用于`Android 7.0`及以下的系统,最低支持`Android 5.1` | |
| > ~~墙内不再更新~~ 倒卖必死全家 |