Skip to content

Commit

Permalink
Add versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
nain-F49FF806 committed Jun 4, 2024
1 parent d6e0098 commit 7b4c99b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
50 changes: 50 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# Use unix timestamp, precise to 1000 seconds (~16.7 mins) as versionCode epoch.
# This lets us later generate 999 manual updates to a versionCode epoch if needed.
# Note: This scheme will remain valid for use in Google Play up to value 2100000000,
# or about year 2036 .

# Function to get the current time epoch version code
getCurrentTimeEpochVersionCode() {
# Get the current Unix timestamp in seconds
seconds=$(date +%s)
# Divide the seconds (integer division) by 1000 to get the epoch
epoch=$(($seconds / 1000))
# Multiply the epoch by 1000 to get the version code
epochVersionCode=$(($epoch * 1000))
echo $epochVersionCode
}

# Function to get the current date version name
getCurrentDateVersionName() {
# Get the current date in the format yyyy.MM.dd
currentDateVersionName=$(date +"%Y.%m.%d")
echo $currentDateVersionName
}

# Check if SKIP_VERSION_AUTO_UPDATE is set
if [ "$SKIP_VERSION_AUTO_UPDATE" = "true" ]; then
echo "Skipping automatic android app version update."
exit 0
else
echo "Incrementing android app version pre-commit."
echo "Skip by setting environment variable SKIP_VERSION_AUTO_UPDATE=true."
fi

# Get the versionCode and versionName
versionCode=$(getCurrentTimeEpochVersionCode)
versionName=$(getCurrentDateVersionName)

# Store the path to build.gradle.kts in a variable
buildGradleFilePath="app/build.gradle"

# Update the build.gradle.kts file with the new versionCode and versionName
sed -i'' -e "s/versionCode .*/versionCode $versionCode/" "$buildGradleFilePath"
sed -i'' -e "s/versionName .*/versionName \"$versionName\"/" "$buildGradleFilePath"

# Add the updated build.gradle.kts file to the staging area
git add "$buildGradleFilePath"

# Proceed with the commit
exit 0
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 16
versionName '2.6.0'
versionCode 1717533000
versionName "2024.06.04"
applicationId 'alt.nainapps.aer'
}

Expand Down

0 comments on commit 7b4c99b

Please sign in to comment.