mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-21 11:22:16 +08:00
修改自动编译版本号生成逻辑
改为根据上一个tag计算版本号 修正filter语法错误 匹配*.*.*+*格式tag 使用参数`fetch-depth: 0`取得所有分支和tags, 改回HEAD作为统计中的末端提交 Revert "末端提交应由HEAD改为FETCH_HEAD" This reverts commit df5b6d0552d173f22e4e40a27366ee3ea4178c65. 限制仅在push到main分支时触发Action 避免替换Flutter build-number 末端提交应由HEAD改为FETCH_HEAD 检查当前HEAD 修正语法错误 修正version的格式错误 打印version变量 统计当前分支第一父提交数作为子版本号
This commit is contained in:
50
.github/workflows/CI.yml
vendored
50
.github/workflows/CI.yml
vendored
@@ -4,7 +4,7 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- '*'
|
- 'main'
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
- '**.txt'
|
- '**.txt'
|
||||||
@@ -23,19 +23,46 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
#- name: 获取first parent commit次数
|
||||||
|
# id: get-first-parent-commit-count
|
||||||
|
# run: |
|
||||||
|
# version=$(yq e .version pubspec.yaml | cut -d "+" -f 1)
|
||||||
|
# recent_release_tag=$(git tag -l | grep $version | egrep -v "[-|+]" || true)
|
||||||
|
# if [[ "x$recent_release_tag" == "x" ]]; then
|
||||||
|
# echo "当前版本tag不存在,请手动生成tag."
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
# git log --oneline HEAD
|
||||||
|
# first_parent_commit_count=$(git rev-list --first-parent --count $recent_release_tag..HEAD)
|
||||||
|
# echo "count=$first_parent_commit_count" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: 从tag获取之前的version_code与beta版本号
|
||||||
|
id: get-previous-codes
|
||||||
|
run: |
|
||||||
|
version=$(yq e .version pubspec.yaml | cut -d "+" -f 1)
|
||||||
|
last_tag=$(git describe --tags | awk -F"-" '{for(i=1;i<=NF-2;i++) printf "%s", $i}')
|
||||||
|
echo $last_tag | grep "+" || echo "Tag格式不正确" && exit 1
|
||||||
|
echo $last_tag | grep $version || echo "当前版本tag不存在,请手动添加tag." && exit 1
|
||||||
|
|
||||||
|
version_code=$(echo $last_tag | cut -d "+" -f 2)
|
||||||
|
beta_code=0$(echo $last_tag | cut -d "+" -f 1 | cut -d "." -f 4)
|
||||||
|
|
||||||
|
echo "beta-code=$beta_code" >> $GITHUB_OUTPUT
|
||||||
|
echo "version-code=$version_code" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: 更新版本号
|
- name: 更新版本号
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
# 读取版本号
|
# 读取版本号
|
||||||
VERSION=$(yq e .version pubspec.yaml)
|
version_name=$(yq e .version pubspec.yaml | cut -d "+" -f 1)
|
||||||
|
let beta_code=${{ steps.get-previous-codes.outputs.beta-code }}+1
|
||||||
# 获取GitHub Actions的run_number
|
let version_code=${{ steps.get-previous-codes.outputs.version-code }}+1
|
||||||
RUN_NUMBER=${{ github.run_number }}
|
|
||||||
|
|
||||||
# 构建新版本号
|
# 构建新版本号
|
||||||
NEW_VERSION=$(echo $VERSION | awk -F+ -v run_number="$RUN_NUMBER" '{print $1"+"run_number}')
|
NEW_VERSION=${version_name}-beta.${beta_code}+${version_code}
|
||||||
|
|
||||||
# 输出新版本号
|
# 输出新版本号
|
||||||
echo "New version: $NEW_VERSION"
|
echo "New version: $NEW_VERSION"
|
||||||
@@ -105,9 +132,10 @@ jobs:
|
|||||||
|
|
||||||
- name: 重命名应用
|
- name: 重命名应用
|
||||||
run: |
|
run: |
|
||||||
|
version_name=$(yq e .version pubspec.yaml | cut -d "+" -f 1)
|
||||||
for file in build/app/outputs/flutter-apk/app-*.apk; do
|
for file in build/app/outputs/flutter-apk/app-*.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]}${{ needs.update_version.outputs.new_version }}.apk"
|
new_file_name="build/app/outputs/flutter-apk/Pili-${BASH_REMATCH[1]}${version_name}.apk"
|
||||||
mv "$file" "$new_file_name"
|
mv "$file" "$new_file_name"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -149,9 +177,9 @@ jobs:
|
|||||||
|
|
||||||
- name: 重命名应用
|
- name: 重命名应用
|
||||||
run: |
|
run: |
|
||||||
DATE=${{ steps.date.outputs.date }}
|
version_name=$(yq e .version pubspec.yaml | cut -d "+" -f 1)
|
||||||
for file in app.ipa; do
|
for file in app.ipa; do
|
||||||
new_file_name="build/Pili-${{ needs.update_version.outputs.new_version }}.ipa"
|
new_file_name="build/Pili-${version_name}.ipa"
|
||||||
mv "$file" "$new_file_name"
|
mv "$file" "$new_file_name"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
28
.github/workflows/main.yml
vendored
28
.github/workflows/main.yml
vendored
@@ -5,7 +5,8 @@ on:
|
|||||||
push:
|
push:
|
||||||
# push tag时触发
|
# push tag时触发
|
||||||
tags:
|
tags:
|
||||||
- "v*.*.*"
|
- "[0-9]+.[0-9]+.[0-9]+*"
|
||||||
|
- "!*beta*"
|
||||||
|
|
||||||
# 可以有多个jobs
|
# 可以有多个jobs
|
||||||
jobs:
|
jobs:
|
||||||
@@ -47,6 +48,14 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||||
|
|
||||||
|
- name: 获取版本号
|
||||||
|
id: version
|
||||||
|
run: echo "version=${GITHUB_REF#refs/tags/}" >>$GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: 修改pubspec.yaml
|
||||||
|
run: |
|
||||||
|
sed -i "s/version: .*/version: ${{ steps.version.outputs.version }}/g" pubspec.yaml
|
||||||
|
|
||||||
- name: flutter build apk
|
- name: flutter build apk
|
||||||
run: flutter build apk --release --split-per-abi
|
run: flutter build apk --release --split-per-abi
|
||||||
env:
|
env:
|
||||||
@@ -61,9 +70,6 @@ jobs:
|
|||||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||||
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD}}
|
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD}}
|
||||||
|
|
||||||
- name: 获取版本号
|
|
||||||
id: version
|
|
||||||
run: echo "version=${GITHUB_REF#refs/tags/v}" >>$GITHUB_OUTPUT
|
|
||||||
|
|
||||||
# - name: 获取当前日期
|
# - name: 获取当前日期
|
||||||
# id: date
|
# id: date
|
||||||
@@ -71,7 +77,6 @@ jobs:
|
|||||||
|
|
||||||
- name: 重命名应用
|
- name: 重命名应用
|
||||||
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-*.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"
|
||||||
@@ -100,19 +105,22 @@ jobs:
|
|||||||
cache: true
|
cache: true
|
||||||
flutter-version: 3.16.5
|
flutter-version: 3.16.5
|
||||||
|
|
||||||
|
- name: 获取版本号
|
||||||
|
id: version
|
||||||
|
run: echo "version=${GITHUB_REF#refs/tags/}" >>$GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: 修改pubspec.yaml
|
||||||
|
run: |
|
||||||
|
sed -i "s/version: .*/version: ${{ steps.version.outputs.version }}/g" pubspec.yaml
|
||||||
|
|
||||||
- name: flutter build ipa
|
- name: flutter build ipa
|
||||||
run: |
|
run: |
|
||||||
flutter build ios --release --no-codesign
|
flutter build ios --release --no-codesign
|
||||||
ln -sf ./build/ios/iphoneos Payload
|
ln -sf ./build/ios/iphoneos Payload
|
||||||
zip -r9 app.ipa Payload/runner.app
|
zip -r9 app.ipa Payload/runner.app
|
||||||
|
|
||||||
- name: 获取版本号
|
|
||||||
id: version
|
|
||||||
run: echo "version=${GITHUB_REF#refs/tags/v}" >>$GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: 重命名应用
|
- name: 重命名应用
|
||||||
run: |
|
run: |
|
||||||
DATE=${{ steps.date.outputs.date }}
|
|
||||||
for file in app.ipa; do
|
for file in app.ipa; do
|
||||||
new_file_name="build/Pili-${{ steps.version.outputs.version }}.ipa"
|
new_file_name="build/Pili-${{ steps.version.outputs.version }}.ipa"
|
||||||
mv "$file" "$new_file_name"
|
mv "$file" "$new_file_name"
|
||||||
|
|||||||
Reference in New Issue
Block a user