flutter.yml: 修改当 Git 浅克隆时生成版本号的方式为依据编译编号或者日期

服务器只是浅克隆1层代码,有 GITHUB_RUN_NUMBER 的就依据此环境变量。
对于本地如果浅克隆,没有 GITHUB_RUN_NUMBER 的就依据编译日期。
This commit is contained in:
Calcitem 2020-12-13 11:10:59 +08:00
parent 9795f08fcd
commit 43ac139d90
2 changed files with 26 additions and 13 deletions

View File

@ -26,11 +26,17 @@ jobs:
with: with:
channel: 'stable' # or: 'dev' or 'beta' channel: 'stable' # or: 'dev' or 'beta'
- name: Export environment valiables
run: export
- name: Create App version
run: git fetch --tags; git tag; git log -n1; bash -x ./version.sh
- name: Print Flutter SDK version - name: Print Flutter SDK version
run: flutter --version run: flutter --version
- name: Install dependencies - name: Install dependencies
run: ./version.sh; cd src/ui/flutter; flutter pub get; flutter pub global activate intl_utils; flutter --no-color pub global run intl_utils:generate run: cd src/ui/flutter; flutter pub get; flutter pub global activate intl_utils; flutter --no-color pub global run intl_utils:generate
# Uncomment this step to verify the use of 'dart format' on each commit. # Uncomment this step to verify the use of 'dart format' on each commit.
# - name: Verify formatting # - name: Verify formatting
@ -41,7 +47,7 @@ jobs:
# want to change this to 'flutter test'. # want to change this to 'flutter test'.
#- name: Run tests #- name: Run tests
# run: dart test # run: dart test
# Build # Build
- name: Build apk - name: Build apk
run: cd src/ui/flutter; flutter build apk run: cd src/ui/flutter; flutter build apk

View File

@ -13,19 +13,26 @@ LOCALVER="$(wc -l config.git-hash | awk '{print $1}')"
TAG="$(git describe --tags "$(git rev-list --tags --max-count=1)")" TAG="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
if [ "$LOCALVER" -gt "1" ] ; then if [ "$LOCALVER" -gt "1" ] ; then
VER=$(git rev-list origin/$GIT_BRANCH | sort | join config.git-hash - | wc -l | awk '{print $1}') VER=$(git rev-list origin/$GIT_BRANCH | sort | join config.git-hash - | wc -l | awk '{print $1}')
if [ "$VER" != "$LOCALVER" ] ; then if [ "$VER" != "$LOCALVER" ] ; then
VER="$VER+$((LOCALVER-VER))" VER="$VER+$((LOCALVER-VER))"
fi fi
if git status | grep -q "modified:" ; then if git status | grep -q "modified:" ; then
VER="${VER}M" VER="${VER}M"
fi fi
VER="$VER g$(git rev-list HEAD -n 1 | cut -c 1-7)" VER="$VER g$(git rev-list HEAD -n 1 | cut -c 1-7)"
GIT_VERSION="$TAG r$VER" GIT_VERSION="$TAG r$VER"
APP_VERSION="${TAG:1}+${LOCALVER-VER}" APP_VERSION="${TAG:1}+${LOCALVER-VER}"
else else
GIT_VERSION= DATE=$(date +%Y%m%d)
VER="x" if [ -n "$GITHUB_RUN_NUMBER" ] ; then
VER="$GITHUB_RUN_NUMBER"
GIT_VERSION="$TAG #$VER"
else
VER="${DATE:2}"
GIT_VERSION="$TAG Build $VER"
fi
APP_VERSION="${TAG:1}+${VER}"
fi fi
rm -f config.git-hash rm -f config.git-hash