Update CI.yml

This commit is contained in:
orz12
2024-02-02 02:58:11 +08:00
parent f8b8082af7
commit 040f0300e7

View File

@@ -1,8 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: CI name: CI
on: on:
@@ -17,14 +12,11 @@ on:
- '.idea/**' - '.idea/**'
- '!.github/workflows/**' - '!.github/workflows/**'
# 可以有多个jobs
jobs: jobs:
build_apk: android:
name: Build CI (Push) name: Build CI (Android)
# 运行环境 ubuntu-latest window-latest mac-latest
runs-on: ubuntu-latest runs-on: ubuntu-latest
# 每个jobs中可以有多个steps
steps: steps:
- name: 代码迁出 - name: 代码迁出
uses: actions/checkout@v3 uses: actions/checkout@v3
@@ -40,7 +32,7 @@ jobs:
uses: actions/cache@v2 uses: actions/cache@v2
id: cache-flutter id: cache-flutter
with: with:
path: /root/flutter-sdk # Flutter SDK 的路径 path: /root/flutter-sdk
key: ${{ runner.os }}-flutter-${{ hashFiles('**/pubspec.lock') }} key: ${{ runner.os }}-flutter-${{ hashFiles('**/pubspec.lock') }}
- name: 安装Flutter - name: 安装Flutter
@@ -59,7 +51,6 @@ jobs:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
- name: flutter build apk - name: flutter build apk
# 对应 android/app/build.gradle signingConfigs中的配置项
run: flutter build apk --release --split-per-abi run: flutter build apk --release --split-per-abi
env: env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
@@ -70,27 +61,83 @@ jobs:
id: version id: version
run: echo "version=${GITHUB_SHA::7}" >>$GITHUB_OUTPUT run: echo "version=${GITHUB_SHA::7}" >>$GITHUB_OUTPUT
# - name: 获取当前日期 - name: 重命名应用
# id: date
# run: echo "date=$(date +'%m%d')" >>$GITHUB_OUTPUT
- name: 重命名应用 Pili-arm64-v8a-*.apk
run: | run: |
# DATE=${{ steps.date.outputs.date }} for file in build/app/outputs/flutter-apk/app-*.apk; do
for file in build/app/outputs/flutter-apk/app-*-release.apk; do if [[ $file =~ app-(.?*)release.apk ]]; then
if [[ $file =~ app-(.*)-release.apk ]]; then new_file_name="build/app/outputs/flutter-apk/Pili-${BASH_REMATCH[1]}${{ steps.version.outputs.version }}.apk"
new_file_name="build/app/outputs/flutter-apk/Pili-${BASH_REMATCH[1]}-${{ steps.version.outputs.version }}.apk"
mv "$file" "$new_file_name" mv "$file" "$new_file_name"
fi fi
done done
- name: Upload ARM64
uses: actions/upload-artifact@v3
with:
name: Pili-arm64-v8a-${{ steps.version.outputs.version }}
path: build/app/outputs/flutter-apk/Pili-arm64-v8a-*.apk
- name: Upload x86_64 - name: 上传
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: Pili-x86_64-${{ steps.version.outputs.version }} name: Pilipala-CI
path: build/app/outputs/flutter-apk/Pili-x86_64-*.apk path: |
build/app/outputs/flutter-apk/Pili-*.apk
iOS:
name: Build CI (iOS)
runs-on: macos-latest
steps:
- name: 代码迁出
uses: actions/checkout@v4
- 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: flutter build ipa
run: |
flutter build ios --release --no-codesign
ln -sf ./build/ios/iphoneos Payload
zip -r9 app.ipa Payload/runner.app
- name: 获取版本号
id: version
run: echo "version=${GITHUB_SHA::7}" >>$GITHUB_OUTPUT
- name: 重命名应用
run: |
DATE=${{ steps.date.outputs.date }}
for file in app.ipa; do
new_file_name="build/Pili-${{ steps.version.outputs.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:
- 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: v${{ github.run_number }}
token: ${{ secrets.GIT_TOKEN }}
commit: main
tag: v${{ github.run_number }}
prerelease: true
allowUpdates: true
artifacts: Pilipala-CI/*