From ab32c79145e9c7629febe134edd3c0c3dce1df80 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Tue, 30 Jun 2026 10:30:04 +0800 Subject: [PATCH] build: make sync-version.sh auto-increment build number --- scripts/sync-version.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/sync-version.sh b/scripts/sync-version.sh index 5894b0c5..ebac392a 100755 --- a/scripts/sync-version.sh +++ b/scripts/sync-version.sh @@ -1,9 +1,21 @@ #!/bin/bash set -e -# Extract current version from pubspec.yaml if not provided -# but here the user requested: version: 1.1.5+2 -TARGET_VERSION="1.1.5+2" +if [ -n "$1" ]; then + TARGET_VERSION="$1" +else + # Extract current version from pubspec.yaml + CURRENT_VERSION=$(grep "^version: " pubspec.yaml | awk '{print $2}') + + if [[ "$CURRENT_VERSION" == *"+"* ]]; then + BASE_VERSION=$(echo "$CURRENT_VERSION" | cut -d'+' -f1) + BUILD_NUM=$(echo "$CURRENT_VERSION" | cut -d'+' -f2) + NEXT_BUILD_NUM=$((BUILD_NUM + 1)) + TARGET_VERSION="${BASE_VERSION}+${NEXT_BUILD_NUM}" + else + TARGET_VERSION="${CURRENT_VERSION}+1" + fi +fi DATE=$(date +%Y-%m-%d) COMMIT=$(git rev-parse --short HEAD)