From fe0ecff8f2cd7b15ec4282bc0fdca266dab20409 Mon Sep 17 00:00:00 2001 From: Ryan Harg <3821-ryan_harg@users.noreply.dev.funkwhale.audio> Date: Fri, 17 Sep 2021 06:50:19 +0000 Subject: [PATCH] #97: Add fixed version information --- app/build.gradle.kts | 2 +- changes/changelog.d/97.misc | 1 + dist/create-release.sh | 85 +++++++++++++++++++++++++++++++++++++ fdroidversion.txt | 2 + 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 changes/changelog.d/97.misc create mode 100755 dist/create-release.sh create mode 100644 fdroidversion.txt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 24b5dbc..88b23f7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -26,7 +26,7 @@ unMock { } androidGitVersion { - codeFormat = "MMNNPPBBB" + codeFormat = "MMNNPPBBB" // Keep in sync with version_code() in dist/create_release.sh format = "%tag%%-count%%-commit%%-branch%" } diff --git a/changes/changelog.d/97.misc b/changes/changelog.d/97.misc new file mode 100644 index 0000000..0b6f548 --- /dev/null +++ b/changes/changelog.d/97.misc @@ -0,0 +1 @@ +Add hard coded version information for F-Droid deployment (#97) \ No newline at end of file diff --git a/dist/create-release.sh b/dist/create-release.sh new file mode 100755 index 0000000..43106b3 --- /dev/null +++ b/dist/create-release.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# This script creates a new release of Funkwhale for Android. +# +# Usage: ./create-release.sh TAG + +# tokenize_tag() - tokenize tag parameter, splitting at dot +# +# Expects a string parameter with format MAJOR.MINOR.PATCH, e.g. 1.2.3 +# Returns an array containing elements for MAJOR, MINOR and PATCH +function tokenize_tag() { + IFS="." read -ra TOKENS <<< "$1" +} + +# version_code() - create a numeric version code from a tokenized tag parameter +# that conforms to the version code format from the +# gradle build script +# +# Expects an array parameter with entries for MAJOR, MINOR and PATCH version parts +# Returns a formatted version code, leading zeroes are stripped +function version_code() { + + result="" + + # Every version part is filled with leading zeros to a string of size 2 + for token in "$@" + do + ((leadingZeros=2-${#token})) + for _ in $(seq 1 "$leadingZeros") + do + token="${token}0" + done + result="$result$token" + done + + # strip leading zeroes, add three trailing zeroes and return + echo "${result#"${result%%[!0]*}"}000" +} + +# Validate if script is used with correct number of params +if [ $# -lt 1 ]; then + echo 'Usage: ./create-release.sh TAG' >&2 + echo ' TAG format MAJOR.MINOR.PATH, e.g. 1.2.3' >&2 + exit 1 +fi + +tokenize_tag "$1" + +# Validate tag parameter format +if [ ${#TOKENS[@]} != 3 ]; then + echo 'ERROR: Invalid tag parameter format.' >&2 + echo 'Use MAJOR.MINOR.PATCH scheme, e.g. 1.2.3' >&2 + exit 1 +fi + +# Validate that git repository is not dirty +if [ "$(git diff --stat)" != '' ]; then + echo 'ERROR: repository is dirty.' >&2 + exit 1 +fi + +TAG="$1" +MESSAGE="Creating release version $TAG" + +echo "Compiling the changelog..." +towncrier build --version "$TAG" --date $(date +"%Y-%m-%d") + +git add CHANGELOG +git comit --message "Update changelog for version $TAG" + +# Validate that git tag doesn't already exist +git fetch --all --tags +if [ "$(git tag -l | grep -e "^$TAG$")" != '' ]; then + echo "ERROR: tag $TAG already exists." >&2 + exit 1 +fi + +# Write versionCode and versionName to a file that F-Droid can parse +echo "versionCode = $(version_code "${TOKENS[@]}") +versionName = $TAG" > fdroidversion.txt + +echo "Tagging the application..." + +# Create and push tag +git tag -a -s -m "$MESSAGE" "$TAG" +git push --tags diff --git a/fdroidversion.txt b/fdroidversion.txt new file mode 100644 index 0000000..3abbd18 --- /dev/null +++ b/fdroidversion.txt @@ -0,0 +1,2 @@ +versionCode = 1010000 +versionName = 0.1.1