From 43ac139d9079fdf527d85b9a5c3d38c5cb76602a Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sun, 13 Dec 2020 11:10:59 +0800 Subject: [PATCH] =?UTF-8?q?flutter.yml:=20=E4=BF=AE=E6=94=B9=E5=BD=93=20Gi?= =?UTF-8?q?t=20=E6=B5=85=E5=85=8B=E9=9A=86=E6=97=B6=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E7=9A=84=E6=96=B9=E5=BC=8F=E4=B8=BA?= =?UTF-8?q?=E4=BE=9D=E6=8D=AE=E7=BC=96=E8=AF=91=E7=BC=96=E5=8F=B7=E6=88=96?= =?UTF-8?q?=E8=80=85=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 服务器只是浅克隆1层代码,有 GITHUB_RUN_NUMBER 的就依据此环境变量。 对于本地如果浅克隆,没有 GITHUB_RUN_NUMBER 的就依据编译日期。 --- .github/workflows/flutter.yml | 10 ++++++++-- version.sh | 29 ++++++++++++++++++----------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index 12fd775c..8d1493dc 100644 --- a/.github/workflows/flutter.yml +++ b/.github/workflows/flutter.yml @@ -26,11 +26,17 @@ jobs: with: 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 run: flutter --version - 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. # - name: Verify formatting @@ -41,7 +47,7 @@ jobs: # want to change this to 'flutter test'. #- name: Run tests # run: dart test - + # Build - name: Build apk run: cd src/ui/flutter; flutter build apk diff --git a/version.sh b/version.sh index f826cb7c..e671a139 100755 --- a/version.sh +++ b/version.sh @@ -13,19 +13,26 @@ LOCALVER="$(wc -l config.git-hash | awk '{print $1}')" TAG="$(git describe --tags "$(git rev-list --tags --max-count=1)")" if [ "$LOCALVER" -gt "1" ] ; then - VER=$(git rev-list origin/$GIT_BRANCH | sort | join config.git-hash - | wc -l | awk '{print $1}') - if [ "$VER" != "$LOCALVER" ] ; then - VER="$VER+$((LOCALVER-VER))" - fi - if git status | grep -q "modified:" ; then - VER="${VER}M" - fi - VER="$VER g$(git rev-list HEAD -n 1 | cut -c 1-7)" - GIT_VERSION="$TAG r$VER" + VER=$(git rev-list origin/$GIT_BRANCH | sort | join config.git-hash - | wc -l | awk '{print $1}') + if [ "$VER" != "$LOCALVER" ] ; then + VER="$VER+$((LOCALVER-VER))" + fi + if git status | grep -q "modified:" ; then + VER="${VER}M" + fi + VER="$VER g$(git rev-list HEAD -n 1 | cut -c 1-7)" + GIT_VERSION="$TAG r$VER" APP_VERSION="${TAG:1}+${LOCALVER-VER}" else - GIT_VERSION= - VER="x" + DATE=$(date +%Y%m%d) + 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 rm -f config.git-hash