1+ # -----------------------------------------------------------------------------
2+ # Workflow: Bump Dev Version
3+ #
4+ # Description:
5+ # This GitHub Actions workflow automatically increments the version number
6+ # defined in `Config.xcconfig` on every push to the `dev` branch.
7+ #
8+ # Versioning Logic:
9+ # - Reads the `LOOP_FOLLOW_MARKETING_VERSION` from `Config.xcconfig`.
10+ # - If the version is in `MAJOR.MINOR.PATCH.BUILD` format (4 digits),
11+ # the `BUILD` number is incremented by 1.
12+ # - If the version is in `MAJOR.MINOR.PATCH` format (3 digits),
13+ # a `.1` is appended to start a `BUILD` count.
14+ #
15+ # Example:
16+ # - `0.5.0` → `0.5.0.1`
17+ # - `0.5.0.3` → `0.5.0.4`
18+ #
19+ # The updated version is then committed and pushed back to the `dev` branch.
20+ #
21+ # Prerequisites:
22+ # - `LOOP_FOLLOW_MARKETING_VERSION` must exist and be defined using the format:
23+ # LOOP_FOLLOW_MARKETING_VERSION = x.y.z or x.y.z.w
24+ # - GitHub Actions bot must have workflow permission to push to `dev`.
25+ # -----------------------------------------------------------------------------
26+
27+ name : Bump Dev Version
28+
29+ on :
30+ push :
31+ branches :
32+ - dev
33+
34+ jobs :
35+ bump-version :
36+ if : github.repository_owner == 'loopandlearn'
37+ runs-on : ubuntu-latest
38+
39+ steps :
40+ - name : Checkout repository
41+ uses : actions/checkout@v4
42+
43+ - name : Set up Git
44+ run : |
45+ git config --global user.name "github-actions[bot]"
46+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
47+
48+ - name : Bump dev version number in Config.xcconfig
49+ run : |
50+ FILE=Config.xcconfig
51+
52+ # Find the line with LOOP_FOLLOW_MARKETING_VERSION and extract the value
53+ VERSION_LINE=$(grep -E '^LOOP_FOLLOW_MARKETING_VERSION *= *[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?' "$FILE")
54+ CURRENT_VERSION=$(echo "$VERSION_LINE" | sed -E 's/^LOOP_FOLLOW_MARKETING_VERSION *= *//')
55+
56+ # Split version into components (up to 4)
57+ IFS='.' read -r MAJOR MINOR FIX BUILD <<< "$CURRENT_VERSION"
58+
59+ # If 4th digit not present, start at 1; else increment
60+ if [ -z "$BUILD" ]; then
61+ BUILD=1
62+ else
63+ BUILD=$((BUILD + 1))
64+ fi
65+
66+ # Construct new version
67+ NEW_VERSION="$MAJOR.$MINOR.$FIX.$BUILD"
68+ echo "New version: $NEW_VERSION"
69+
70+ # Escape dots in current version for sed replacement
71+ ESCAPED_CURRENT_VERSION=$(echo "$CURRENT_VERSION" | sed 's/\./\\./g')
72+
73+ # Replace the LOOP_FOLLOW_MARKETING_VERSION line in-place with new version
74+ if [[ "$OSTYPE" == "darwin"* ]]; then
75+ sed -i '' -E "s/LOOP_FOLLOW_MARKETING_VERSION *= *$ESCAPED_CURRENT_VERSION/LOOP_FOLLOW_MARKETING_VERSION = $NEW_VERSION/" "$FILE"
76+ else
77+ sed -i -E "s/LOOP_FOLLOW_MARKETING_VERSION *= *$ESCAPED_CURRENT_VERSION/LOOP_FOLLOW_MARKETING_VERSION = $NEW_VERSION/" "$FILE"
78+ fi
79+
80+ # Export version so it's available in the next step
81+ echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
82+
83+ - name : Commit and push changes
84+ run : |
85+ git add Config.xcconfig
86+ git commit -m "CI: Bump dev version to $NEW_VERSION"
87+ git push
0 commit comments