Skip to content

Update build-ios.yml #66

Update build-ios.yml

Update build-ios.yml #66

Workflow file for this run

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}}
last_commit: ${{ steps.get-last-commit.outputs.last_commit }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 获取最后一次提交
id: get-last-commit
run: |
last_commit=$(git log -1 --pretty="%h %s" --first-parent | sed 's/_/\\_/g; s/*/\\*/g; s/~/\\~/g')
echo "last_commit=$last_commit" >> $GITHUB_OUTPUT
- 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/[email protected]
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 pub get
flutter build ios --release --no-codesign
mkdir build/ios/iphoneos/Payload
cp -R build/ios/iphoneos/Runner.app build/ios/iphoneos/Payload/Runner.app
cd build/ios/iphoneos/
zip -q -r app.ipa Payload
cd ../../...
# ln -sf ./build/ios/iphoneos Payload
# zip -r9 app.ipa Payload/runner.app
- name: 重命名应用
run: |
for file in build/ios/iphoneos/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/[email protected]
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 }}"