From c4a1b624e8db8b94031e0db2720017529285861f Mon Sep 17 00:00:00 2001 From: VillagerTom Date: Thu, 20 Jun 2024 12:18:27 +0800 Subject: [PATCH] fix: workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mod: xireiki/channel-post: large_file: false 忽略`.github/workflows/`内的提交,除非修改Action自身对应的workflow文件 feat: 推送至build-ios分支触发action fix: macos command compatibility for sed fix: typo fix: remove unexisting job dependency 'android' feat: 添加iOS编译流程文件,手动触发 --- .github/workflows/CI.yml | 2 +- .github/workflows/build-ios.yml | 123 ++++++++++++++++++++++++++++++++ .github/workflows/main.yml | 2 +- 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build-ios.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 14a1a239..62743f75 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -10,7 +10,7 @@ on: - '**.txt' - '.github/**' - '.idea/**' - - '!.github/workflows/**' + - '!.github/workflows/CI.yml' jobs: update_version: diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml new file mode 100644 index 00000000..7c8385ec --- /dev/null +++ b/.github/workflows/build-ios.yml @@ -0,0 +1,123 @@ +name: Build iOS + +on: + workflow_dispatch: + push: + branches: + - 'build-ios' + paths-ignore: + - '**.md' + - '**.txt' + - '.github/**' + - '.idea/**' + - '!.github/workflows/build-ios.yml' + +jobs: + update_version: + name: Read latest version + runs-on: ubuntu-latest + + outputs: + # 定义输出变量 version,以便在其他job中引用 + new_version: ${{ steps.get-last-tag.outputs.tag}} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: 获取最后一个tag + id: get-last-tag + run: | + version=$(yq e .version pubspec.yaml | cut -d "+" -f 1) + last_tag=$(git tag --sort=committerdate | tail -1) + if (echo $last_tag | grep -v "+"); then + echo "Illegal tag!" + exit 1 + elif (echo $last_tag | grep -v $version); then + echo "No tags for current version in the repo, please add one manually." + exit 1 + fi + + echo "tag=$last_tag" >> $GITHUB_OUTPUT + + iOS: + name: Build CI (iOS) + needs: update_version + runs-on: macos-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.ref_name }} + + - 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: | + 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: PiliPalaX-iOS + path: | + build/Pili-*.ipa + + upload: + runs-on: ubuntu-latest + + needs: + - update_version + - iOS + steps: + + - uses: actions/download-artifact@v3 + with: + name: PiliPalaX-iOS + path: ./PiliPalaX-iOS + + # - 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@v1.0.7 + with: + bot_token: ${{ secrets.BOT_TOKEN }} + chat_id: ${{ secrets.CHAT_ID }} + large_file: false + method: sendFile + path: PiliPalaX-iOS/* + parse_mode: Markdown + context: "*v${{ needs.update_version.outputs.new_version }}*\n${{ needs.update_version.outputs.last_commit }}" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6319777a..a5c9385b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,7 +54,7 @@ jobs: - name: 修改pubspec.yaml run: | - sed -i "s/version: .*/version: ${{ steps.version.outputs.version }}/g" pubspec.yaml + sed -i "" "s/version: .*/version: ${{ steps.version.outputs.version }}/g" pubspec.yaml - name: flutter build apk run: flutter build apk --release --split-per-abi