Forráskód Böngészése

Refactor: Add auto-incrementing APP_DEV_VERSION workflow for dev builds

Deniz Cengiz 1 éve
szülő
commit
5ff472c069

+ 56 - 43
.github/workflows/DO_NOT_RUN_auto_version_dev.yml

@@ -2,29 +2,39 @@
 # Workflow: Bump Dev Version
 #
 # Description:
-# This GitHub Actions workflow automatically increments the version number
-# defined in `Config.xcconfig` on every push to the `dev` branch.
+# This GitHub Actions workflow automatically manages and increments the
+# `APP_DEV_VERSION` defined in `Config.xcconfig` on every push to `dev` branch.
+# This version is used for internal tracking and diagnostics (e.g. in
+# Crashlytics) and follows a 4-digit semantic versioning format:
+# `MAJOR.MINOR.PATCH.FEATURE`.
 #
 # Versioning Logic:
-# - Reads the `APP_VERSION` from `Config.xcconfig`.
-# - If the version is in `MAJOR.MINOR.PATCH.BUILD` format (4 digits),
-#   the `BUILD` number is incremented by 1.
-# - If the version is in `MAJOR.MINOR.PATCH` format (3 digits),
-#   a `.1` is appended to start a `BUILD` count.
+# - Reads the base version from `APP_VERSION = x.y.z`
+# - Reads the last internal dev version from `APP_DEV_VERSION`
 #
-# Example:
-# - `0.5.0` → `0.5.0.1`
-# - `0.5.0.3` → `0.5.0.4`
+# Behavior:
+# - If `APP_DEV_VERSION` matches `APP_VERSION` (e.g. both are `0.5.0`),
+#   it assumes the first dev push after a release and sets `APP_DEV_VERSION`
+#   to `APP_VERSION.1` (e.g. `0.5.0.1`)
+# - If `APP_DEV_VERSION` is already in 4-digit form (e.g. `0.5.0.3`),
+#   it increments the fourth digit (e.g. → `0.5.0.4`)
 #
-# The updated version is then committed and pushed back to the `dev` branch.
+# Example Progression:
+# - Release sets `APP_VERSION = 0.5.0`, `APP_DEV_VERSION = 0.5.0`
+# - First push to `dev`:      → `APP_DEV_VERSION = 0.5.0.1`
+# - Second push to `dev`:     → `APP_DEV_VERSION = 0.5.0.2`
+# - ...
+#
+# The updated value is committed and pushed back to the `dev` branch.
 #
 # Prerequisites:
-# - `APP_VERSION` must exist and be defined using the format:
-#    APP_VERSION = x.y.z or x.y.z.w
-# - GitHub Actions bot must have workflow permission to push to `dev`.
+# - `APP_VERSION` must be present in `Config.xcconfig` in the form `x.y.z`
+# - `APP_DEV_VERSION` must either match `APP_VERSION` or be `x.y.z.w`
+# - GitHub Actions must have write permission to push to `dev`
+# - This workflow only runs when the repository owner is `nightscout`
 # -----------------------------------------------------------------------------
 
-name: Bump Dev Version
+name: Bump APP_DEV_VERSION on dev push
 
 on:
   push:
@@ -32,12 +42,12 @@ on:
       - dev
 
 jobs:
-  bump-version:
-    if: github.repository_owner == 'nightscout'
+  bump-dev-version:
+    if: github.repository.owner == 'nightscout'
     runs-on: ubuntu-latest
 
     steps:
-      - name: Checkout repository
+      - name: Checkout repo
         uses: actions/checkout@v4
 
       - name: Set up Git
@@ -45,43 +55,46 @@ jobs:
           git config --global user.name "github-actions[bot]"
           git config --global user.email "github-actions[bot]@users.noreply.github.com"
 
-      - name: Bump dev version number in Config.xcconfig
+      - name: Bump APP_DEV_VERSION
         run: |
           FILE=Config.xcconfig
 
-          # Find the line with APP_VERSION and extract the value
-          VERSION_LINE=$(grep -E '^APP_VERSION *= *[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?' "$FILE")
-          CURRENT_VERSION=$(echo "$VERSION_LINE" | sed -E 's/^APP_VERSION *= *//')
-          
-          # Split version into components (up to 4)
-          IFS='.' read -r MAJOR MINOR FIX BUILD <<< "$CURRENT_VERSION"
+          # Read current APP_VERSION
+          BASE_VERSION=$(grep '^APP_VERSION' "$FILE" | cut -d '=' -f2 | xargs)
 
-          # If 4th digit not present, start at 1; else increment
-          if [ -z "$BUILD" ]; then
-            BUILD=1
+          # Read existing APP_DEV_VERSION, if any
+          DEV_LINE=$(grep '^APP_DEV_VERSION' "$FILE" || echo "")
+          if [ -z "$DEV_LINE" ]; then
+            CURRENT_DEV_VERSION="$BASE_VERSION"
           else
-            BUILD=$((BUILD + 1))
+            CURRENT_DEV_VERSION=$(echo "$DEV_LINE" | cut -d '=' -f2 | xargs)
           fi
 
-          # Construct new version
-          NEW_VERSION="$MAJOR.$MINOR.$FIX.$BUILD"
-          echo "New version: $NEW_VERSION"
-
-          # Escape dots in current version for sed replacement
-          ESCAPED_CURRENT_VERSION=$(echo "$CURRENT_VERSION" | sed 's/\./\\./g')
+          echo "APP_VERSION       = $BASE_VERSION"
+          echo "APP_DEV_VERSION   = $CURRENT_DEV_VERSION"
 
-          # Replace the APP_VERSION line in-place with new version
-          if [[ "$OSTYPE" == "darwin"* ]]; then
-            sed -i '' -E "s/APP_VERSION *= *$ESCAPED_CURRENT_VERSION/APP_VERSION = $NEW_VERSION/" "$FILE"
+          # Decide next dev version
+          if [ "$CURRENT_DEV_VERSION" = "$BASE_VERSION" ]; then
+            # First post-release commit to dev → bump to .1
+            NEW_DEV_VERSION="${BASE_VERSION}.1"
+            if [ -z "$DEV_LINE" ]; then
+              echo "APP_DEV_VERSION = $NEW_DEV_VERSION" >> "$FILE"
+            else
+              sed -i -E "s|^APP_DEV_VERSION *= *.*|APP_DEV_VERSION = $NEW_DEV_VERSION|" "$FILE"
+            fi
           else
-            sed -i -E "s/APP_VERSION *= *$ESCAPED_CURRENT_VERSION/APP_VERSION = $NEW_VERSION/" "$FILE"
+            # Already in .X form → bump last digit
+            IFS='.' read -r MAJOR MINOR PATCH FEATURE <<< "$CURRENT_DEV_VERSION"
+            FEATURE=$((FEATURE + 1))
+            NEW_DEV_VERSION="$MAJOR.$MINOR.$PATCH.$FEATURE"
+            sed -i -E "s|^APP_DEV_VERSION *= *.*|APP_DEV_VERSION = $NEW_DEV_VERSION|" "$FILE"
           fi
 
-          # Export version so it's available in the next step
-          echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
+          echo "NEW APP_DEV_VERSION = $NEW_DEV_VERSION"
+          echo "NEW_DEV_VERSION=$NEW_DEV_VERSION" >> $GITHUB_ENV
 
-      - name: Commit and push changes
+      - name: Commit and push updated dev version
         run: |
           git add Config.xcconfig
-          git commit -m "CI: Bump dev version to $NEW_VERSION"
+          git commit -m "CI: Bump APP_DEV_VERSION to $NEW_DEV_VERSION"
           git push

+ 1 - 1
Config.xcconfig

@@ -1,6 +1,6 @@
 APP_DISPLAY_NAME = Trio
 APP_VERSION = 0.4.1
-APP_BUILD_NUMBER = 1
+APP_DEV_VERSION = 0.4.1
 COPYRIGHT_NOTICE =
 DEVELOPER_TEAM = ##TEAM_ID##
 BUNDLE_IDENTIFIER = org.nightscout.$(DEVELOPMENT_TEAM).trio

+ 2 - 0
Trio/Resources/Info.plist

@@ -4,6 +4,8 @@
 <dict>
 	<key>AppGroupID</key>
 	<string>$(APP_GROUP_ID)</string>
+	<key>AppDevVersion</key>
+	<string>$(APP_DEV_VERSION)</string>
 	<key>BGTaskSchedulerPermittedIdentifiers</key>
 	<array>
 		<string>$(PRODUCT_BUNDLE_IDENTIFIER).background-task.critical-event-log</string>

+ 1 - 0
Trio/Sources/Application/AppDelegate.swift

@@ -18,6 +18,7 @@ class AppDelegate: NSObject, UIApplicationDelegate, ObservableObject, UNUserNoti
         // the next app boot, but this is fine since the app will need
         // to boot after a crash
         Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(crashReportingEnabled)
+        Crashlytics.crashlytics().setCustomValue(Bundle.main.appDevVersion ?? "unknown", forKey: "app_dev_version")
 
         return true
     }

+ 18 - 1
Trio/Sources/Application/TrioApp.swift

@@ -115,9 +115,20 @@ extension Notification.Name {
             "\(key): \(value.branch) \(value.commitSHA)"
         }.joined(separator: ", ")
 
+        var versionNumber: String {
+            let releaseVersion = Bundle.main.releaseVersionNumber ?? "unknown"
+            let devVersion = Bundle.main.appDevVersion ?? "unknown"
+
+            if releaseVersion == devVersion {
+                return releaseVersion
+            } else {
+                return devVersion
+            }
+        }
+
         debug(
             .default,
-            "Trio Started: v\(Bundle.main.releaseVersionNumber ?? "")(\(Bundle.main.buildVersionNumber ?? "")) [buildDate: \(String(describing: BuildDetails.shared.buildDate()))] [buildExpires: \(String(describing: BuildDetails.shared.calculateExpirationDate()))] [Branch: \(BuildDetails.shared.branchAndSha)] [submodules: \(submodulesInfo)]"
+            "Trio Started: v\(versionNumber)(\(Bundle.main.buildVersionNumber ?? "")) [buildDate: \(String(describing: BuildDetails.shared.buildDate()))] [buildExpires: \(String(describing: BuildDetails.shared.calculateExpirationDate()))] [Branch: \(BuildDetails.shared.branchAndSha)] [submodules: \(submodulesInfo)]"
         )
         // Fix bug in iOS 18 related to the translucent tab bar
         configureTabBarAppearance()
@@ -447,3 +458,9 @@ extension Notification.Name {
         }
     }
 }
+
+public extension Bundle {
+    var appDevVersion: String? {
+        object(forInfoDictionaryKey: "AppDevVersion") as? String
+    }
+}

+ 10 - 1
Trio/Sources/Modules/Settings/View/SettingsRootView.swift

@@ -78,7 +78,16 @@ extension Settings {
                     Section(
                         header: Text("BRANCH: \(buildDetails.branchAndSha)").textCase(nil),
                         content: {
-                            let versionNumber = Bundle.main.releaseVersionNumber ?? String(localized: "Unknown")
+                            var versionNumber: String {
+                                let releaseVersion = Bundle.main.releaseVersionNumber ?? String(localized: "Unknown")
+                                let devVersion = Bundle.main.appDevVersion ?? String(localized: "Unknown")
+
+                                if releaseVersion == devVersion {
+                                    return releaseVersion
+                                } else {
+                                    return devVersion
+                                }
+                            }
                             let buildNumber = Bundle.main.buildVersionNumber ?? String(localized: "Unknown")
 
                             NavigationLink(destination: SubmodulesView(buildDetails: buildDetails)) {