From 7b4c99b133fce2f0a5c33d56307651c2f190ec66 Mon Sep 17 00:00:00 2001 From: nain <126972030+F49FF806@users.noreply.github.com> Date: Tue, 4 Jun 2024 22:30:39 +0200 Subject: [PATCH] Add versioning --- .githooks/pre-commit | 50 ++++++++++++++++++++++++++++++++++++++++++++ app/build.gradle | 4 ++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..12e4e3e --- /dev/null +++ b/.githooks/pre-commit @@ -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 diff --git a/app/build.gradle b/app/build.gradle index 584e9ca..3c1f85c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' }