Merge branch 'main' into dev #23
This file contains 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: Build alpha | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- 'dev' | |
paths-ignore: | |
- '**.md' | |
- '**.txt' | |
- '.github/**' | |
- '.idea/**' | |
- '!.github/workflows/build-alpha.yml' | |
jobs: | |
update_version: | |
name: Read latest version | |
runs-on: ubuntu-latest | |
outputs: | |
# 定义输出变量 version,以便在其他job中引用 | |
new_version: ${{ steps.update-version.outputs.new_version }} | |
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) | |
echo "last_commit=$last_commit" >> $GITHUB_OUTPUT | |
- name: 生成alpha版本号 | |
id: update-version | |
run: | | |
version_name=$(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! ($last_tag)" | |
exit 1 | |
elif (echo $last_tag | grep -v $version_name); then | |
echo "No tags for current version in the repo, please add one manually." | |
exit 1 | |
fi | |
version_code=$(echo $last_tag | cut -d "+" -f 2) | |
datetime=$(date -u -d "8 hours" +%m%d%H%M) | |
echo "new_version=${version_name}-alpha.${datetime}+${version_code}" >> $GITHUB_OUTPUT | |
build_matrix: | |
name: Build CI (${{ matrix.target_platform }}) | |
needs: update_version | |
runs-on: ${{ matrix.build_os }} | |
strategy: | |
matrix: | |
target_platform: [android-arm, android-arm64, android-x64, android-universal, iOS] | |
include: | |
- build_os: ubuntu-latest | |
- target_platform: iOS | |
build_os: macos-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: 构建Java环境 | |
if: startsWith(matrix.target_platform, 'android') | |
uses: actions/setup-java@v3 | |
with: | |
distribution: "zulu" | |
java-version: "21" | |
token: ${{ secrets.GIT_TOKEN }} | |
- name: 安装Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: 3.24.4 | |
channel: stable | |
- name: 修复Flutter 3.24中文字重异常 | |
if: startsWith(matrix.target_platform, 'android') | |
run: | | |
cd $FLUTTER_ROOT | |
git config --global user.name "orz12" | |
git config --global user.email "[email protected]" | |
git cherry-pick d4124bd --strategy-option theirs | |
# Flutter precache | |
flutter --version | |
cd - | |
- name: 下载项目依赖 | |
run: flutter pub get | |
- name: 解码生成 jks | |
if: startsWith(matrix.target_platform, 'android') | |
run: echo $KEYSTORE_BASE64 | base64 -di > android/app/vvex.jks | |
env: | |
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} | |
- name: 更新版本号 | |
id: version | |
run: | | |
yq ".version=\"${{ needs.update_version.outputs.new_version }}\"" pubspec.yaml > tmp.yaml | |
mv tmp.yaml pubspec.yaml | |
- name: flutter build apk (universal) | |
if: matrix.target_platform == 'android-universal' | |
run: flutter build apk --release | |
env: | |
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
- name: flutter build apk (${{ matrix.target_platform }}) | |
if: startsWith(matrix.target_platform, 'android') && matrix.target_platform != 'android-universal' | |
run: flutter build apk --release --split-per-abi --target-platform=${{ matrix.target_platform }} | |
env: | |
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
- name: flutter build ipa | |
if: matrix.target_platform == 'iOS' | |
run: | | |
flutter build ios --release --no-codesign | |
ln -sf ./build/ios/iphoneos Payload | |
zip -r9 app.ipa Payload/runner.app | |
- name: 重命名安装包(${{ matrix.target_platform }}) | |
if: startsWith(matrix.target_platform, 'android') | |
run: | | |
version_name=$(yq e .version pubspec.yaml | cut -d "+" -f 1) | |
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]}${version_name}.apk" | |
mv "$file" "$new_file_name" | |
fi | |
done | |
- name: 重命名安装包(iOS) | |
if: matrix.target_platform == 'iOS' | |
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: 上传至artifact (${{ matrix.target_platform }}) | |
if: startsWith(matrix.target_platform, 'android') | |
uses: actions/upload-artifact@v3 | |
with: | |
name: PiliPalaX-alpha | |
path: | | |
build/app/outputs/flutter-apk/Pili-*.apk | |
- name: 上传至artifact (iOS) | |
if: matrix.target_platform == 'iOS' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: PiliPalaX-alpha | |
path: | | |
build/Pili-*.ipa | |
upload: | |
runs-on: ubuntu-latest | |
needs: | |
- update_version | |
- build_matrix | |
steps: | |
- name: 从artifact下载 | |
uses: actions/download-artifact@v3 | |
with: | |
name: PiliPalaX-alpha | |
path: ./PiliPalaX-alpha | |
- name: 发送到Telegram频道 | |
uses: xireiki/[email protected] | |
with: | |
bot_token: ${{ secrets.BOT_TOKEN }} | |
chat_id: ${{ secrets.CHAT_ID }} | |
api_id: ${{ secrets.TELEGRAM_API_ID }} | |
api_hash: ${{ secrets.TELEGRAM_API_HASH }} | |
large_file: true | |
method: sendFile | |
path: PiliPalaX-alpha/* | |
parse_mode: Markdown | |
context: "*v${{ needs.update_version.outputs.new_version }}*\n${{ needs.update_version.outputs.last_commit }}" |