From a3abed0a03d04edc16371b34ce8c70e6b9381d80 Mon Sep 17 00:00:00 2001 From: VillagerTom Date: Tue, 20 Feb 2024 13:07:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ealpha.yml,=20=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E7=BC=96=E8=AF=91=E6=8E=A8=E9=80=81=E8=87=B3alpha?= =?UTF-8?q?=E5=88=86=E6=94=AF=E7=9A=84=E4=BB=A3=E7=A0=81=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E8=87=B3Telegram=E9=A2=91=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/alpha.yml | 209 ++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 .github/workflows/alpha.yml diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml new file mode 100644 index 00000000..e56fb2f9 --- /dev/null +++ b/.github/workflows/alpha.yml @@ -0,0 +1,209 @@ +name: CI + +on: + workflow_dispatch: + push: + branches: + - 'alpha' + paths-ignore: + - '**.md' + - '**.txt' + - '.github/**' + - '.idea/**' + - '!.github/workflows/**' + +jobs: + update_version: + name: Read and update version + runs-on: ubuntu-latest + + outputs: + # 定义输出变量 version,以便在其他job中引用 + new_version: ${{ steps.version.outputs.new_version }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.ref_name }} + + - name: 获取first parent commit次数 + id: get-first-parent-commit-count + run: | + version=$(yq e .version pubspec.yaml | cut -d "+" -f 1) + git fetch origin "refs/tags/*:refs/tags/*" + recent_release_tag=$(git tag -l | grep $version | egrep -v "[-|+]" || true) + if [[ "x$recent_release_tag" == "x" ]]; then + echo "当前版本tag不存在,请手动生成tag." + exit 1 + fi + first_parent_commit_count=$(git rev-list --first-parent --count $recent_release_tag..FETCH_HEAD) + echo "count=$first_parent_commit_count" >> $GITHUB_OUTPUT + + - name: 更新版本号 + id: version + run: | + # 读取版本号 + VERSION=$(yq e .version pubspec.yaml | cut -d "+" -f 1) + + # 获取GitHub Actions的run_number + #RUN_NUMBER=${{ github.run_number }} + + # 构建新版本号 + NEW_VERSION=$VERSION-alpha.${{ steps.get-first-parent-commit-count.outputs.count }} + + # 输出新版本号 + echo "New version: $NEW_VERSION" + + # 设置新版本号为输出变量 + echo "new_version=$NEW_VERSION" >>$GITHUB_OUTPUT + + android: + name: Build CI (Android) + needs: update_version + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: 构建Java环境 + uses: actions/setup-java@v3 + with: + distribution: "zulu" + java-version: "17" + token: ${{secrets.GIT_TOKEN}} + + - name: 检查缓存 + uses: actions/cache@v2 + id: cache-flutter + with: + path: /root/flutter-sdk + key: ${{ runner.os }}-flutter-${{ hashFiles('**/pubspec.lock') }} + + - name: 安装Flutter + if: steps.cache-flutter.outputs.cache-hit != 'true' + uses: subosito/flutter-action@v2 + with: + flutter-version: 3.16.5 + channel: any + + - name: 下载项目依赖 + run: flutter pub get + + - name: 解码生成 jks + run: echo $KEYSTORE_BASE64 | base64 -di > android/app/vvex.jks + env: + KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} + + - name: 更新版本号 + id: version + run: | + # 更新pubspec.yaml文件中的版本号 + sed -i "s/version: .*+/version: ${{ needs.update_version.outputs.new_version }}+/g" pubspec.yaml + + - name: flutter build apk + run: flutter build apk --release --split-per-abi + env: + KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD}} + + - name: 重命名应用 + run: | + for file in build/app/outputs/flutter-apk/app-*.apk; do + if [[ $file =~ app-(.?*)release.apk ]]; then + new_file_name="build/app/outputs/flutter-apk/Pili-${BASH_REMATCH[1]}${{ needs.update_version.outputs.new_version }}.apk" + mv "$file" "$new_file_name" + fi + done + + - name: 上传 + uses: actions/upload-artifact@v3 + with: + name: Pilipala-CI + path: | + build/app/outputs/flutter-apk/Pili-*.apk + + iOS: + name: Build CI (iOS) + needs: update_version + runs-on: macos-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: 安装Flutter + if: steps.cache-flutter.outputs.cache-hit != 'true' + uses: subosito/flutter-action@v2.10.0 + with: + cache: true + flutter-version: 3.16.5 + + - name: 更新版本号 + id: version + run: | + # 更新pubspec.yaml文件中的版本号 + sed -i "" "s/version: .*+/version: ${{ needs.update_version.outputs.new_version }}+/g" pubspec.yaml + + - name: flutter build ipa + run: | + flutter build ios --release --no-codesign + ln -sf ./build/ios/iphoneos Payload + zip -r9 app.ipa Payload/runner.app + + - name: 重命名应用 + run: | + DATE=${{ steps.date.outputs.date }} + for file in app.ipa; do + new_file_name="build/Pili-${{ needs.update_version.outputs.new_version }}.ipa" + mv "$file" "$new_file_name" + done + + - name: 上传 + uses: actions/upload-artifact@v3 + with: + if-no-files-found: error + name: Pilipala-CI + path: | + build/Pili-*.ipa + + upload: + runs-on: ubuntu-latest + + needs: + - update_version + - android + - iOS + steps: + + - uses: actions/download-artifact@v3 + with: + name: Pilipala-CI + path: ./Pilipala-CI + + # - name: Upload Pre-release + # uses: ncipollo/release-action@v1 + # with: + # name: ${{ needs.update_version.outputs.new_version }} + # token: ${{ secrets.GIT_TOKEN }} + # commit: main + # tag: ${{ needs.update_version.outputs.new_version }} + # prerelease: true + # allowUpdates: true + # artifacts: Pilipala-CI/* + + - name: 发送到Telegram频道 + uses: xireiki/channel-post@main + with: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + CHAT_ID: ${{ secrets.CHAT_ID }} + METHOD: sendMediaGroup + path: | + ./Pilipala-CI/Pili-${{ needs.update_version.outputs.new_version }}.ipa + ./Pilipala-CI/Pili-arm64-${{ needs.update_version.outputs.new_version }}.apk + ./Pilipala-CI/Pili-armeabi-v7a-${{ needs.update_version.outputs.new_version }}.apk + ./Pilipala-CI/Pili-x86_64-${{ needs.update_version.outputs.new_version }}.apk + CONTEXT: "**Pre-release:** ${{ needs.update_version.outputs.new_version }}" + PARSE_MODE: Markdown