From 2b7900b68dd362bc5f2dc7f13dbee49787106072 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sat, 27 Jul 2024 12:44:13 +1200 Subject: [PATCH] CICD: Make Version Information SemVer Compliant. Make the version information used throughout the application and build process compliant with the SemVer specifications, so that it can be processed with libraries. Signed-off-by: Michael Keller --- .github/actions/manage-version/action.yml | 2 +- packaging/android/qmake-build.sh | 3 +++ packaging/ios/build.sh | 4 ++++ scripts/build.sh | 3 +++ scripts/get-version.sh | 20 ++++++++++++-------- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/actions/manage-version/action.yml b/.github/actions/manage-version/action.yml index 6d9f81a14..72926fbf9 100644 --- a/.github/actions/manage-version/action.yml +++ b/.github/actions/manage-version/action.yml @@ -37,7 +37,7 @@ runs: PULL_REQUEST_BRANCH: ${{ github.event.pull_request.head.ref }} shell: bash run: | - echo "pull-request-$PULL_REQUEST_BRANCH" > latest-subsurface-buildnumber-extension + echo "pull-request.$PULL_REQUEST_BRANCH" > latest-subsurface-buildnumber-extension - name: store version number for the build id: version_number diff --git a/packaging/android/qmake-build.sh b/packaging/android/qmake-build.sh index 317cf46db..a9ac999c5 100755 --- a/packaging/android/qmake-build.sh +++ b/packaging/android/qmake-build.sh @@ -408,6 +408,9 @@ fi # now build the Subsurface aab make apk +# Clean up the generated ssrf-version.h file +rm -f ssrf-version.h + popd APK=$(find . -name Subsurface-mobile.apk) diff --git a/packaging/ios/build.sh b/packaging/ios/build.sh index 01bf4bd75..a94ca28fc 100755 --- a/packaging/ios/build.sh +++ b/packaging/ios/build.sh @@ -352,5 +352,9 @@ for BUILD_NOW in $BUILD_LOOP; do # it appears that a first make fails with a missing generated file, which a second # invocation of make will happily build make || make + + # Clean up the generated ssrf-version.h file + rm -f "$SUBSURFACE_SOURCE"/ssrf-version.h . + popd done diff --git a/scripts/build.sh b/scripts/build.sh index 292aa8e57..95b3e242f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -523,6 +523,9 @@ cd "$SRC" cd ${SRC_DIR} +# Remove a stale generated ssrf-version.h file (if any) +rm -f ssrf-version.h + if [ ! -d libdivecomputer/src ] ; then git submodule init git submodule update --recursive diff --git a/scripts/get-version.sh b/scripts/get-version.sh index 42c8befc0..73d9299a4 100755 --- a/scripts/get-version.sh +++ b/scripts/get-version.sh @@ -29,7 +29,7 @@ fi pushd "$(dirname "$0")/../" &> /dev/null export SUBSURFACE_SOURCE=$PWD -VERSION_EXTENSION="-" +COMMITS_SINCE="0" # add the build number to this as 'patch' component # if we run in an environment where we are given a build number (e.g. CICD builds) @@ -54,22 +54,26 @@ if [ ! -f latest-subsurface-buildnumber ] ; then git checkout "$LAST_BUILD_BRANCH" &> /dev/null || croak "failed to check out $LAST_BUILD_BRANCH in nightly-builds" BUILDNR=$(<./latest-subsurface-buildnumber) popd &> /dev/null - VERSION_EXTENSION+=$(git log --pretty="oneline" "${LAST_BUILD_SHA}...HEAD" | wc -l | tr -d '[:space:]') - VERSION_EXTENSION+="-" - [ "$VERSION_EXTENSION" = "-0-" ] && VERSION_EXTENSION="-" + COMMITS_SINCE=$(git log --pretty="oneline" "${LAST_BUILD_SHA}...HEAD" | wc -l | tr -d '[:space:]') + if [[ -z $COMMITS_SINCE ]]; then + COMMITS_SINCE="0" + fi else BUILDNR=$(<"latest-subsurface-buildnumber") fi +VERSION_EXTENSION="-" +if [ $COMMITS_SINCE -ne 0 ]; then + VERSION_EXTENSION+="patch.${COMMITS_SINCE}." +fi + if [ -f "latest-subsurface-buildnumber-extension" ] ; then - VERSION_EXTENSION+=$(<"latest-subsurface-buildnumber-extension") + SUFFIX=$(<"latest-subsurface-buildnumber-extension") + VERSION_EXTENSION+=$(sed 's/_/-/g;s/[^.a-zA-Z0-9-]//g' <<< "$SUFFIX") else VERSION_EXTENSION+="local" fi -COMMITS_SINCE=$(tr -cd "[:digit:]" <<<"$VERSION_EXTENSION") -[[ -z $COMMITS_SINCE ]] && COMMITS_SINCE="0" - if [[ $DIGITS == "1" ]] ; then VERSION="${BUILDNR}" elif [[ $DIGITS == "3" ]] ; then