Skip to content

Commit 32fc24f

Browse files
committed
feat: Add automated version management system
Version Management System: - Add version.properties as single source of truth for app versions - Update build.gradle.kts to read version from properties file - Create sync-version.sh script to update versions from git tags - Add pre-push git hook to validate version synchronization - Add setup-hooks.sh for easy contributor onboarding Features: - Automatic version code calculation from semantic version - Support for release candidate and pre-release suffixes (e.g., 1.0.0-rc) - Git hook validation prevents version mismatches - Shared via source control for all contributors Usage: 1. ./scripts/setup-hooks.sh (one-time setup) 2. ./scripts/sync-version.sh v1.0.0-rc 3. git add . && git commit -m 'chore: bump version to 1.0.0-rc' 4. git tag v1.0.0-rc && git push origin main --tags This ensures git tags always match Android app versions, eliminating manual version management errors and enabling automated releases.
1 parent 7163945 commit 32fc24f

File tree

6 files changed

+171
-2
lines changed

6 files changed

+171
-2
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Open the app and tap "Settings" to:
4848

4949
## Installation
5050

51+
### Download Release
52+
Download the latest APK from [Releases](https://github.com/cango91/Detracktor/releases) and install on your Android device.
53+
54+
### Build from Source
5155
Build the APK using Android Studio or Gradle:
5256

5357
```bash
@@ -56,6 +60,26 @@ Build the APK using Android Studio or Gradle:
5660

5761
The APK will be generated at `app/build/outputs/apk/debug/app-debug.apk`
5862

63+
## Development
64+
65+
### Version Management
66+
This project uses automated version synchronization between git tags and Android app versions:
67+
68+
```bash
69+
# Set up git hooks (one-time setup for contributors)
70+
./scripts/setup-hooks.sh
71+
72+
# Update version for new release
73+
./scripts/sync-version.sh v1.2.3
74+
75+
# Commit and tag
76+
git add . && git commit -m "chore: bump version to 1.2.3"
77+
git tag v1.2.3
78+
git push origin main --tags
79+
```
80+
81+
The pre-push hook automatically validates that git tags match the Android app version declared in `version.properties`.
82+
5983
## Privacy
6084

6185
Detracktor operates entirely offline with no network access, data collection, or analytics. All processing happens locally on your device.

app/build.gradle.kts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
import java.util.Properties
3+
4+
// Load version from version.properties file
5+
val versionPropsFile = file("../version.properties")
6+
val versionProps = Properties()
7+
if (versionPropsFile.exists()) {
8+
versionProps.load(versionPropsFile.inputStream())
9+
}
10+
211
plugins {
312
alias(libs.plugins.android.application)
413
alias(libs.plugins.kotlin.android)
@@ -20,8 +29,8 @@ android {
2029
applicationId = "com.gologlu.detracktor"
2130
minSdk = 29
2231
targetSdk = 36
23-
versionCode = 1
24-
versionName = "1.0"
32+
versionCode = versionProps.getProperty("VERSION_CODE", "1").toInt()
33+
versionName = versionProps.getProperty("VERSION_NAME", "1.0")
2534

2635
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2736
}
@@ -174,4 +183,12 @@ tasks.register<JacocoReport>("jacocoFullReport") {
174183
"outputs/code_coverage/debugAndroidTest/connected/coverage.ec"
175184
)
176185
})
186+
}
187+
188+
// Task to verify version loading
189+
tasks.register("printVersion") {
190+
doLast {
191+
println("Version Name: ${android.defaultConfig.versionName}")
192+
println("Version Code: ${android.defaultConfig.versionCode}")
193+
}
177194
}

hooks/pre-push

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# pre-push hook to validate version synchronization
3+
# Install with: cp hooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push
4+
5+
set -e
6+
7+
# Check if we're pushing a tag
8+
while read local_ref local_sha remote_ref remote_sha; do
9+
if [[ "$local_ref" =~ refs/tags/ ]]; then
10+
TAG_NAME=$(basename "$local_ref")
11+
12+
echo "Validating version synchronization for tag: $TAG_NAME"
13+
14+
# Extract version from tag (remove 'v' prefix)
15+
TAG_VERSION="${TAG_NAME#v}"
16+
17+
# Check if version.properties exists
18+
if [ ! -f "version.properties" ]; then
19+
echo "Error: version.properties not found!"
20+
echo "Run: ./scripts/sync-version.sh $TAG_NAME"
21+
exit 1
22+
fi
23+
24+
# Read current version from version.properties
25+
CURRENT_VERSION=$(grep "VERSION_NAME=" version.properties | cut -d'=' -f2)
26+
27+
# Compare versions
28+
if [ "$TAG_VERSION" != "$CURRENT_VERSION" ]; then
29+
echo "Error: Version mismatch!"
30+
echo " Tag version: $TAG_VERSION"
31+
echo " version.properties: $CURRENT_VERSION"
32+
echo ""
33+
echo "To fix:"
34+
echo "1. Run: ./scripts/sync-version.sh $TAG_NAME"
35+
echo "2. Commit the changes"
36+
echo "3. Try pushing again"
37+
exit 1
38+
fi
39+
40+
echo "✅ Version synchronization validated: $TAG_VERSION"
41+
fi
42+
done
43+
44+
exit 0

scripts/setup-hooks.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
# setup-hooks.sh - Install git hooks for version management
3+
4+
set -e
5+
6+
echo "Setting up git hooks for version management..."
7+
8+
# Install pre-push hook
9+
if [ -f "hooks/pre-push" ]; then
10+
cp hooks/pre-push .git/hooks/pre-push
11+
chmod +x .git/hooks/pre-push
12+
echo "✅ Installed pre-push hook for version validation"
13+
else
14+
echo "❌ hooks/pre-push not found"
15+
exit 1
16+
fi
17+
18+
echo ""
19+
echo "🎉 Git hooks installed successfully!"
20+
echo ""
21+
echo "Usage:"
22+
echo "1. Update version: ./scripts/sync-version.sh v1.2.3"
23+
echo "2. Commit changes: git add . && git commit -m 'chore: bump version to 1.2.3'"
24+
echo "3. Create tag: git tag v1.2.3"
25+
echo "4. Push: git push origin main --tags"
26+
echo ""
27+
echo "The pre-push hook will validate version synchronization automatically."

scripts/sync-version.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# sync-version.sh - Synchronize version.properties with git tag
5+
# Usage: ./scripts/sync-version.sh v1.2.3
6+
7+
if [ $# -eq 0 ]; then
8+
echo "Usage: $0 <version-tag>"
9+
echo "Example: $0 v1.2.3"
10+
exit 1
11+
fi
12+
13+
TAG_VERSION="$1"
14+
15+
# Remove 'v' prefix if present
16+
VERSION_NAME="${TAG_VERSION#v}"
17+
18+
# Validate version format (basic semver check)
19+
if ! [[ "$VERSION_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
20+
echo "Error: Version must be in format X.Y.Z or X.Y.Z-suffix"
21+
echo "Got: $VERSION_NAME"
22+
exit 1
23+
fi
24+
25+
# Calculate version code from version name (simple increment scheme)
26+
# You can customize this logic based on your needs
27+
IFS='.' read -ra VERSION_PARTS <<< "${VERSION_NAME%%-*}"
28+
MAJOR=${VERSION_PARTS[0]}
29+
MINOR=${VERSION_PARTS[1]}
30+
PATCH=${VERSION_PARTS[2]}
31+
32+
# Simple version code calculation: MAJOR * 10000 + MINOR * 100 + PATCH
33+
VERSION_CODE=$((MAJOR * 10000 + MINOR * 100 + PATCH))
34+
35+
echo "Updating version.properties:"
36+
echo " VERSION_NAME: $VERSION_NAME"
37+
echo " VERSION_CODE: $VERSION_CODE"
38+
39+
# Update version.properties
40+
cat > version.properties << EOF
41+
# App version configuration
42+
# This file is the single source of truth for version information
43+
VERSION_NAME=$VERSION_NAME
44+
VERSION_CODE=$VERSION_CODE
45+
EOF
46+
47+
echo "Version synchronized successfully!"
48+
echo ""
49+
echo "Next steps:"
50+
echo "1. Review the changes: git diff version.properties"
51+
echo "2. Commit the version update: git add version.properties && git commit -m 'chore: bump version to $VERSION_NAME'"
52+
echo "3. Create the tag: git tag $TAG_VERSION"
53+
echo "4. Push with tags: git push origin main --tags"

version.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# App version configuration
2+
# This file is the single source of truth for version information
3+
VERSION_NAME=1.0.0-rc
4+
VERSION_CODE=10000

0 commit comments

Comments
 (0)