Complete redesign of Subsurface version numbers

- for now all versions start with v6.0
- CICD builds use the monolithic build number as patch level, e.g. v6.0.12345
- local builds use the following algorithm
  - find the newest commit with a CICD build number that is included in the
    working tree
  - count the number of commits in the working tree since that commit
  - if there are no commits since the last CICD build, the local build version
    will be v6.0.12345-local
  - if there are N commits since the last CICD build, it will be
    v6.0.12345-N-local
- test builds in the CICD that don't create artifacts simply use a dummy release
  in order to not incorrectly increment the build number and also not to waste
  time and resources by manually checking out the nightly-build repo for each of
  these builds.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2024-01-04 20:44:31 -08:00
parent 8a2dd8db74
commit 62477d8c65
24 changed files with 295 additions and 126 deletions

View file

@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v1
- name: atomically create or retrieve the build number
id: build_nr
id: version_number
if: github.event_name == 'push'
run: |
cd .. # check out parallel to subsurface sources
@ -31,6 +31,16 @@ jobs:
git push origin main
cd ..
bash -x subsurface/scripts/get-or-create-build-nr.sh ${{ github.sha }}
cp nightly-builds/latest-subsurface-buildnumber subsurface
echo "CICD-release" > subsurface/latest-subsurface-buildnumber-extension
version=$(bash subsurface/scripts/get-version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: store dummy version and build number for pull request
if: github.event_name == 'pull_request'
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-pull-request" > latest-subsurface-buildnumber-extension
- name: run build
id: build
@ -59,15 +69,6 @@ jobs:
curl -q https://raw.githubusercontent.com/subsurface/nightly-builds/main/latest-subsurface-buildnumber > buildnr.dat
OUTPUT_DIR=$GITHUB_WORKSPACE bash -x ./subsurface/packaging/android/qmake-build.sh
- name: create version number
id: version_number
if: github.event_name == 'push'
run: |
gitversion=$(bash scripts/get-version win)
latest=$(cat ../nightly-builds/latest-subsurface-buildnumber)
version="$gitversion-$latest"
echo "version=$version" >> $GITHUB_OUTPUT
# only publish a 'release' on push events (those include merging a PR)
- name: upload binaries
if: github.event_name == 'push'

View file

@ -44,5 +44,5 @@ jobs:
email: glance@acc.umu.se
command: subsurface/scripts/build.sh -desktop -build-with-webkit
working-directory: ${{ github.workspace }}/..
version: $(/scripts/get-version linux)
version: $(/scripts/get-version)
description: Automatic scan on github actions

View file

@ -15,6 +15,25 @@ jobs:
- name: Check out sources
uses: actions/checkout@v1
- name: atomically create or retrieve the build number
id: version_number
if: github.event_name == 'push'
run: |
cd .. # check out parallel to subsurface sources
url="https://subsurface:${{ secrets.NIGHTLY_BUILDS }}@github.com/subsurface/nightly-builds"
# the clone followed by the pointless push should verify that the password is stored in the config
# that way the script doesn't need the password
git clone -b main https://github.com/subsurface/nightly-builds
cd nightly-builds
git remote set-url origin "$url"
git push origin main
cd ..
bash -x subsurface/scripts/get-or-create-build-nr.sh ${{ github.sha }}
cp nightly-builds/latest-subsurface-buildnumber subsurface
echo "CICD-release" > subsurface/latest-subsurface-buildnumber-extension
version=$(bash subsurface/scripts/get-version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: Setup API token for copr-cli
env:
API_TOKEN: ${{ secrets.COPR_TOKEN }}
@ -43,4 +62,4 @@ jobs:
run: |
cd ..
bash -x subsurface/packaging/copr/make-package.sh post

View file

@ -13,16 +13,25 @@ jobs:
steps:
- name: switch to Xcode 11
run: sudo xcode-select -s "/Applications/Xcode_11.7.app"
- name: checkout sources
uses: actions/checkout@v1
- name: setup Homebrew
run: brew install autoconf automake libtool pkg-config
- name: set our Qt build
run: |
env
curl -L --output Qt-5.14.1-ios.tar.xz https://f002.backblazeb2.com/file/Subsurface-Travis/Qt-5.14.1-ios.tar.xz
mkdir -p $HOME/Qt
xzcat Qt-5.14.1-ios.tar.xz | tar -x -C $HOME/Qt -f -
- name: store dummy version and build number for test build
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-test-build" > latest-subsurface-buildnumber-extension
- name: build Subsurface-mobile for iOS
env:
SUBSURFACE_REPO_PATH: ${{ github.workspace }}

View file

@ -31,6 +31,11 @@ jobs:
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
- name: store dummy version and build number for pull request
if: github.event_name == 'pull_request'
run: |
echo "6.0.100" > latest-subsurface-buildnumber
- name: build Subsurface
env:
SUBSURFACE_REPO_PATH: ${{ github.workspace }}

View file

@ -33,6 +33,11 @@ jobs:
bluez-libs-devel libgit2-devel libzip-devel libmtp-devel \
xorg-x11-server-Xvfb
- name: store dummy version and build number for test build
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-test-build" > latest-subsurface-buildnumber-extension
- name: build Subsurface
env:
SUBSURFACE_REPO_PATH: ${{ github.workspace }}

View file

@ -35,6 +35,11 @@ jobs:
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
- name: store dummy version and build number for test build
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-test-build" > latest-subsurface-buildnumber-extension
- name: build Subsurface-mobile
env:
SUBSURFACE_REPO_PATH: ${{ github.workspace }}

View file

@ -35,6 +35,11 @@ jobs:
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
- name: store dummy version and build number for test build
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-test-build" > latest-subsurface-buildnumber-extension
- name: build Subsurface-mobile
env:
SUBSURFACE_REPO_PATH: ${{ github.workspace }}

View file

@ -20,6 +20,31 @@ jobs:
# Needed for version determination to work
fetch-depth: 0
- name: atomically create or retrieve the build number
id: version_number
if: github.event_name == 'push'
run: |
cd .. # check out parallel to subsurface sources
url="https://subsurface:${{ secrets.NIGHTLY_BUILDS }}@github.com/subsurface/nightly-builds"
# the clone followed by the pointless push should verify that the password is stored in the config
# that way the script doesn't need the password
git clone -b main https://github.com/subsurface/nightly-builds
cd nightly-builds
git remote set-url origin "$url"
git push origin main
cd ..
bash -x subsurface/scripts/get-or-create-build-nr.sh ${{ github.sha }}
cp nightly-builds/latest-subsurface-buildnumber subsurface
echo "CICD-release" > subsurface/latest-subsurface-buildnumber-extension
version=$(bash subsurface/scripts/get-version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: store dummy version and build number for pull request
if: github.event_name == 'pull_request'
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-pull-request" > latest-subsurface-buildnumber-extension
- name: Set up LXD
uses: canonical/setup-lxd@main
@ -56,6 +81,7 @@ jobs:
run: ccache --show-stats --zero-stats
- name: Upload the snap
if: github.event_name == 'push'
uses: actions/upload-artifact@v2
with:
name: ${{ steps.build-snap.outputs.snap-name }}

View file

@ -17,6 +17,31 @@ jobs:
- name: checkout sources
uses: actions/checkout@v1
- name: atomically create or retrieve the build number
id: version_number
if: github.event_name == 'push'
run: |
cd .. # check out parallel to subsurface sources
url="https://subsurface:${{ secrets.NIGHTLY_BUILDS }}@github.com/subsurface/nightly-builds"
# the clone followed by the pointless push should verify that the password is stored in the config
# that way the script doesn't need the password
git clone -b main https://github.com/subsurface/nightly-builds
cd nightly-builds
git remote set-url origin "$url"
git push origin main
cd ..
bash -x subsurface/scripts/get-or-create-build-nr.sh ${{ github.sha }}
cp nightly-builds/latest-subsurface-buildnumber subsurface
echo "CICD-release" > subsurface/latest-subsurface-buildnumber-extension
version=$(bash subsurface/scripts/get-version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: store dummy version and build number for pull request
if: github.event_name == 'pull_request'
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-pull-request" > latest-subsurface-buildnumber-extension
- name: run build
env:
SUBSURFACE_REPO_PATH: ${{ github.workspace }}
@ -39,3 +64,35 @@ jobs:
with:
name: Linux-artifacts
path: Linux-artifacts
- name: prepare release artifacts
if: github.event_name == 'push'
run: |
mv Subsurface.AppImage Subsurface-v${{ steps.version_number.outputs.version }}.AppImage
# only publish a 'release' on push events (those include merging a PR)
- name: upload binaries
if: github.event_name == 'push'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version_number.outputs.version }}
repository: subsurface/nightly-builds
token: ${{ secrets.NIGHTLY_BUILDS }}
prerelease: false
fail_on_unmatched_files: true
files: |
./Subsurface*.AppImage
body: |
CICD release artifact
These builds are created on every merge or push into the [Subsurface repo](http://github.com/subsurface/subsurface).
This build is based on http://github.com/subsurface/subsurface/commit/${{ github.sha }}
None of these artifacts are signed.
The Android APK can be side-loaded on most Android devices. If you had a previous Subsurface-mobile version installed from the Google Play store, you'll have to uninstall that first.
The Windows installer will ask you to confirm installation of an app from an unknown developer.
The macOS DMG makes it even harder with a multi-step dance that requires opening the Privacy & Security settings in the System Preferences and explicitly confirming that you are willing to install this app.
You can find similar Subsurface-Daily builds for [Ubuntu](https://ppa.launchpadcontent.net/subsurface) and Subsurface-test for [Fedora](https://copr.fedorainfracloud.org/coprs/dirkhh/Subsurface-test).
Please report any issues with these builds in the [Subsurface user forum](https://groups.google.com/g/subsurface-divelog).

View file

@ -13,8 +13,9 @@ jobs:
steps:
- name: checkout sources
uses: actions/checkout@v1
- name: atomically create or retrieve the build number
id: build_nr
id: version_number
if: github.event_name == 'push'
run: |
cd .. # check out parallel to subsurface sources
@ -27,6 +28,16 @@ jobs:
git push origin main
cd ..
bash -x subsurface/scripts/get-or-create-build-nr.sh ${{ github.sha }}
cp nightly-builds/latest-subsurface-buildnumber subsurface
echo "CICD-release" > subsurface/latest-subsurface-buildnumber-extension
version=$(bash subsurface/scripts/get-version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: store dummy version and build number for pull request
if: github.event_name == 'pull_request'
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-pull-request" > latest-subsurface-buildnumber-extension
- name: setup Homebrew
run: brew install hidapi libxslt libjpg libmtp create-dmg confuse
@ -55,15 +66,6 @@ jobs:
echo "Created $IMG"
echo "dmg=$IMG" >> $GITHUB_OUTPUT
- name: create version number
id: version_number
if: github.event_name == 'push'
run: |
gitversion=$(bash scripts/get-version win)
latest=$(cat ../nightly-builds/latest-subsurface-buildnumber)
version="$gitversion-$latest"
echo "version=$version" >> $GITHUB_OUTPUT
# only publish a 'release' on push events (those include merging a PR)
- name: upload binaries
if: github.event_name == 'push'

View file

@ -49,7 +49,7 @@ unset LD_LIBRARY_PATH
./linuxdeployqt*.AppImage --appimage-extract-and-run ./appdir/usr/share/applications/*.desktop -exclude-libs=libdbus-1.so.3 -bundle-non-qt-libs -qmldir=./subsurface/stats -qmldir=./subsurface/map-widget/ -verbose=2
# create the AppImage
export VERSION=$(cd subsurface/scripts ; ./get-version linux) # linuxdeployqt uses this for naming the file
export VERSION=$(cd subsurface/scripts ; ./get-version) # linuxdeployqt uses this for naming the file
./linuxdeployqt*.AppImage --appimage-extract-and-run ./appdir/usr/share/applications/*.desktop -exclude-libs=libdbus-1.so.3 -appimage -qmldir=./subsurface/stats -qmldir=./subsurface/map-widget/ -verbose=2
# copy AppImage to the calling VM

View file

@ -14,6 +14,25 @@ jobs:
- name: Check out sources
uses: actions/checkout@v1
- name: atomically create or retrieve the build number
id: version_number
if: github.event_name == 'push'
run: |
cd .. # check out parallel to subsurface sources
url="https://subsurface:${{ secrets.NIGHTLY_BUILDS }}@github.com/subsurface/nightly-builds"
# the clone followed by the pointless push should verify that the password is stored in the config
# that way the script doesn't need the password
git clone -b main https://github.com/subsurface/nightly-builds
cd nightly-builds
git remote set-url origin "$url"
git push origin main
cd ..
bash -x subsurface/scripts/get-or-create-build-nr.sh ${{ github.sha }}
cp nightly-builds/latest-subsurface-buildnumber subsurface
echo "CICD-release" > subsurface/latest-subsurface-buildnumber-extension
version=$(bash subsurface/scripts/get-version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: Setup build dependencies
run: |
sudo apt-get update

View file

@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v1
- name: atomically create or retrieve the build number
id: build_nr
id: version_number
if: github.event_name == 'push'
run: |
cd .. # check out parallel to subsurface sources
@ -31,6 +31,16 @@ jobs:
git push origin main
cd ..
bash -x subsurface/scripts/get-or-create-build-nr.sh ${{ github.sha }}
cp nightly-builds/latest-subsurface-buildnumber subsurface
echo "CICD-release" > subsurface/latest-subsurface-buildnumber-extension
version=$(bash subsurface/scripts/get-version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: store dummy version and build number for pull request
if: github.event_name == 'pull_request'
run: |
echo "100" > latest-subsurface-buildnumber
echo "CICD-pull-request" > latest-subsurface-buildnumber-extension
- name: get other dependencies
env:
@ -49,15 +59,6 @@ jobs:
bash -x subsurface/.github/workflows/scripts/windows-in-container-build.sh 2>&1 | tee build.log
grep "Built target installer" build.log
- name: create version number
id: version_number
if: github.event_name == 'push'
run: |
gitversion=$(bash scripts/get-version win)
latest=$(cat ../nightly-builds/latest-subsurface-buildnumber)
version="$gitversion-$latest"
echo "version=$version" >> $GITHUB_OUTPUT
# only publish a 'release' on push events (those include merging a PR)
- name: upload binaries
if: github.event_name == 'push'

View file

@ -320,7 +320,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
execute_process(
COMMAND sh scripts/get-version linux
COMMAND bash scripts/get-version
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE SSRF_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE

View file

@ -1,7 +1,7 @@
# Generate the ssrf-config.h every 'make'
file(WRITE ${CMAKE_BINARY_DIR}/version.h.in
"#define GIT_VERSION_STRING \"@GIT_VERSION_STRING@\"
#define CANONICAL_VERSION_STRING \"@CANONICAL_VERSION_STRING@\"
"#define CANONICAL_VERSION_STRING \"@CANONICAL_VERSION_STRING@\"
#define CANONICAL_VERSION_STRING_4 \"@CANONICAL_VERSION_STRING_4@\"
")
file(COPY cmake/Modules/version.cmake

View file

@ -1,11 +1,20 @@
execute_process(
COMMAND sh ${CMAKE_TOP_SRC_DIR}/scripts/get-version linux
COMMAND bash ${CMAKE_TOP_SRC_DIR}/scripts/get-version 4
WORKING_DIRECTORY ${CMAKE_TOP_SRC_DIR}
OUTPUT_VARIABLE GIT_VERSION_STRING
OUTPUT_VARIABLE CANONICAL_VERSION_STRING_4
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND sh ${CMAKE_TOP_SRC_DIR}/scripts/get-version full
COMMAND bash ${CMAKE_TOP_SRC_DIR}/scripts/get-version 3
WORKING_DIRECTORY ${CMAKE_TOP_SRC_DIR}
OUTPUT_VARIABLE CANONICAL_VERSION_STRING_3
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND bash ${CMAKE_TOP_SRC_DIR}/scripts/get-version
WORKING_DIRECTORY ${CMAKE_TOP_SRC_DIR}
OUTPUT_VARIABLE CANONICAL_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
@ -15,8 +24,8 @@ configure_file(${SRC} ${DST} @ONLY)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
execute_process(
COMMAND cat ${CMAKE_TOP_SRC_DIR}/packaging/windows/subsurface.nsi.in
COMMAND sed -e "s/VERSIONTOKEN/${GIT_VERSION_STRING}/"
COMMAND sed -e "s/PRODVTOKEN/${CANONICAL_VERSION_STRING}/"
COMMAND sed -e "s/VERSIONTOKEN/${CANONICAL_VERSION_STRING}/"
COMMAND sed -e "s/PRODVTOKEN/${CANONICAL_VERSION_STRING_4}/"
OUTPUT_FILE ${CMAKE_BINARY_DIR}/staging/subsurface.nsi
)
endif()

View file

@ -1,9 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
#include "ssrf-version.h"
// let's leave the two redundant functions in case we change our minds on git SHAs
const char *subsurface_git_version(void)
{
return GIT_VERSION_STRING;
return CANONICAL_VERSION_STRING_4;
}
const char *subsurface_canonical_version(void)

View file

@ -84,10 +84,10 @@ mkdir -p "$BUILDROOT"/subsurface-mobile-build
pushd "$BUILDROOT"/subsurface-mobile-build
# set up the Subsurface versions by hand
GITVERSION=$(cd "$SUBSURFACE_SOURCE" ; git describe --match "v[0-9]*" --abbrev=12)
CANONICALVERSION=$(echo "$GITVERSION" | sed -e 's/-g.*$// ; s/^v//' | sed -e 's/-/./')
echo "#define GIT_VERSION_STRING \"$GITVERSION\"" > ssrf-version.h
CANONICALVERSION=$("$SUBSURFACE_SOURCE"/scripts/get-version)
echo "#define CANONICAL_VERSION_STRING \"$CANONICALVERSION\"" >> ssrf-version.h
CANONICALVERSION_4=$("$SUBSURFACE_SOURCE"/scripts/get-version 4)
echo "#define CANONICAL_VERSION_STRING_4 \"$CANONICALVERSION_4\"" >> ssrf-version.h
popd
if [ "$versionOnly" = "1" ] ; then

View file

@ -77,10 +77,10 @@ if [[ $QT_VERSION = 5.15* ]] ; then
fi
# set up the Subsurface versions by hand
GITVERSION=$(cd "$SUBSURFACE_SOURCE" ; git describe --match "v[0-9]*" --abbrev=12)
CANONICALVERSION=$(echo "$GITVERSION" | sed -e 's/-g.*$// ; s/^v//' | sed -e 's/-/./')
echo "#define GIT_VERSION_STRING \"$GITVERSION\"" > "$SUBSURFACE_SOURCE"/ssrf-version.h
CANONICALVERSION=$("$SUBSURFACE_SOURCE"/scripts/get-version)
echo "#define CANONICAL_VERSION_STRING \"$CANONICALVERSION\"" >> "$SUBSURFACE_SOURCE"/ssrf-version.h
CANONICALVERSION_4=$("$SUBSURFACE_SOURCE"/scripts/get-version 4)
echo "#define CANONICAL_VERSION_STRING_4 \"$CANONICALVERSION_4\"" >> "$SUBSURFACE_SOURCE"/ssrf-version.h
BUNDLE=org.subsurface-divelog.subsurface-mobile
if [ "${IOS_BUNDLE_PRODUCT_IDENTIFIER}" != "" ] ; then
@ -264,7 +264,7 @@ if [ "$QUICK" != "1" ] ; then
if [ ! "$CURRENT_SHA" = "$PREVIOUS_SHA" ] ; then
echo "$CURRENT_SHA" > "${PARENT_DIR}/libdivecomputer-build-${ARCH}/git.SHA"
pushd "${PARENT_DIR}/libdivecomputer-build-${ARCH}"
"${SUBSURFACE_SOURCE}/libdivecomputer/configure" --host=${BUILDCHAIN} --prefix="$PREFIX" --enable-static --disable-shared --enable-examples=no --without-libusb --without-hidapi
"${SUBSURFACE_SOURCE}/libdivecomputer/configure" --host=${BUILDCHAIN} --prefix="$PREFIX" --enable-static --disable-shared --enable-examples=no --without-libusb --without-hidapi
make -j
make install
popd

View file

@ -11,7 +11,7 @@ DMGCREATE=create-dmg
# same git version magic as in the Makefile
# for the naming of volume and dmg we want the 3 digits of the full version number
VERSION=$(cd ${DIR}/subsurface; ./scripts/get-version linux)
VERSION=$(cd ${DIR}/subsurface; ./scripts/get-version)
# first build and install Subsurface and then clean up the staging area
# make sure we didn't lose the minimum OS version

View file

@ -7,7 +7,7 @@ cd /__w
# grab the version number
cd subsurface
VERSION=$(./scripts/get-version linux)
VERSION=$(./scripts/get-version)
cd ..
# prep the container

View file

@ -1,76 +1,80 @@
#!/bin/sh
#!/bin/bash
# shellcheck disable=SC2164
# $1 - os name {linux|darwin|win}
# $2 - [optional] raw version string "vX.Y-patchN-sha1". as from `git describe'
# (see below)
set -eu
#set -x
# consistently name all builds, regardless of OS or desktop/mobile
#
# we do need to be able to create three digit (M.m.p) and four digit (M.m.p.c) version strings
# default is VERSION_EXTENSION version - an argument of '4' or '3' gets you a digits only version string
#
# we hardcode a base version - this will rarely change
# (we actually haven't discussed a situation where it would change...)
SUBSURFACE_BASE_VERSION=6.0
# little silly helper functions
croak() {
echo "$0: $*" >&2
exit 1
}
croak_usage() {
croak "Usage: $0 [3|4]"
}
[ $# -ge 1 ] || croak "missing OS argument"
os=$1
if [ $# -eq 2 ] && [ "$2" ]; then
v0=$2
else
cmd="git describe --match "v[0-9]*" --abbrev=12"
v0=$($cmd) || v0=$(cat .gitversion) || croak "odd; command '$cmd' failed"
if [[ $# -gt 1 ]] ; then croak_usage ; fi
if [[ $# -eq 1 ]] ; then
if [[ $1 != "4" && $1 != "3" ]] ; then croak_usage ; fi
DIGITS="$1"
fi
# strip off the 'v' prefix, if any
v0=${v0#v}
# figure out where we are in the file system
cd "$(dirname "$0")/../"
export SUBSURFACE_SOURCE=$PWD
case $os in
linux)
v=$v0
;;
darwin)
# just the dots in the version string - this way we can
# count them
IFS=.
set -- $v0 # split $v0 using $IFS separator
dots=$(($# - 1)) # use positional argument count
# split version string using a '-' separator
IFS=-
set -- $v0
v=$1
# do we need to add another digit?
# We know there are 1 or 2 dots in $v, so if it's just one
# or we are trying to get to 4, add one digit
if [ $dots -eq 1 ]; then
if [ $# -gt 1 ]; then
v=$v.$2
else
v=$v.0
fi
fi
;;
full|win)
# just the dots in the version string - this way we can
# count them
IFS=.
set -- $v0 # split $v0 using $IFS separator
dots=$(($# - 1)) # use positional argument count
# split version string using a '-' separator
IFS=-
set -- $v0
v=$1
if [ $dots -eq 1 ]; then
v=$v.0
fi
if [ $# -gt 1 ]; then
v=$v.$2
else
v=$v.0
fi
;;
*)
v=git.missing.please.hardcode.version
;;
esac
printf '%s' $v
# 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)
# we just grab that - otherwise we have to figure it out on the fly
if [ ! -f latest-subsurface-buildnumber ] ; then
# figure out the most recent build number, given our own git history
# this assumes that (a) we are in a checked out git tree and
# (b) we have the ability to check out another git repo
# in situations where either of these isn't true, it's the caller's
# responsibility to ensure that the latest-subsurface-buildnumber file exists
if [ ! -d "$SUBSURFACE_SOURCE/nightly-builds" ] ; then
git clone https://github.com/subsurface/nightly-builds &> /dev/null || croak "failed to clone nightly-builds repo"
fi
cd nightly-builds
git fetch &> /dev/null
LAST_BUILD_BRANCHS=$(git branch -a --sort=-committerdate --list | grep remotes/origin/branch-for | head -50 | cut -d/ -f3)
for LAST_BUILD_BRANCH in $LAST_BUILD_BRANCHS "not-found" ; do
LAST_BUILD_SHA=$(cut -d- -f 3 <<< "$LAST_BUILD_BRANCH")
git -C "$SUBSURFACE_SOURCE" merge-base --is-ancestor "$LAST_BUILD_SHA" HEAD && break
done
[ "not-found" = "$LAST_BUILD_BRANCH" ] && croak "can't find a build number for the current working tree"
git checkout "$LAST_BUILD_BRANCH" &> /dev/null || croak "failed to check out $LAST_BUILD_BRANCH in nightly-builds"
BUILDNR=$(<./latest-subsurface-buildnumber)
cd "$SUBSURFACE_SOURCE"
VERSION_EXTENSION="-"
VERSION_EXTENSION+=$(git log --pretty="oneline" "${LAST_BUILD_SHA}...HEAD" | wc -l | tr -d '[:space:]')
VERSION_EXTENSION+="-"
[ "$VERSION_EXTENSION" = "-0-" ] && VERSION_EXTENSION="-"
VERSION_EXTENSION+="local"
else
# use the files included with the sources
BUILDNR=$(<"$SUBSURFACE_SOURCE/latest-subsurface-buildnumber")
VERSION_EXTENSION=""
if [ -f "$SUBSURFACE_SOURCE/latest-subsurface-buildnumber-extension" ] ; then
VERSION_EXTENSION="-"
VERSION_EXTENSION+=$(<"$SUBSURFACE_SOURCE/latest-subsurface-buildnumber-extension")
fi
fi
COMMITS_SINCE=$(tr -cd "[:digit:]" <<<"$VERSION_EXTENSION")
[[ -z $COMMITS_SINCE ]] && COMMITS_SINCE="0"
if [[ $DIGITS == "3" ]] ; then
VERSION="${SUBSURFACE_BASE_VERSION}.${BUILDNR}"
elif [[ $DIGITS == "4" ]] ; then
VERSION="${SUBSURFACE_BASE_VERSION}.${BUILDNR}.${COMMITS_SINCE}"
else
VERSION="${SUBSURFACE_BASE_VERSION}.${BUILDNR}${VERSION_EXTENSION}"
fi
printf '%s' "$VERSION"

View file

@ -1,23 +1,24 @@
message(STATUS "processing version.cmake")
execute_process(
COMMAND sh ${CMAKE_TOP_SRC_DIR}/../scripts/get-version linux
WORKING_DIRECTORY ${CMAKE_TOP_SRC_DIR}
OUTPUT_VARIABLE GIT_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND sh ${CMAKE_TOP_SRC_DIR}/../scripts/get-version full
COMMAND bash ${CMAKE_TOP_SRC_DIR}/../scripts/get-version
WORKING_DIRECTORY ${CMAKE_TOP_SRC_DIR}
OUTPUT_VARIABLE CANONICAL_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND bash ${CMAKE_TOP_SRC_DIR}/../scripts/get-version 4
WORKING_DIRECTORY ${CMAKE_TOP_SRC_DIR}
OUTPUT_VARIABLE CANONICAL_VERSION_STRING_4
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(${SRC} ${DST} @ONLY)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
execute_process(
COMMAND cat ${CMAKE_TOP_SRC_DIR}/../packaging/windows/smtk-import.nsi.in
COMMAND sed -e "s/VERSIONTOKEN/${GIT_VERSION_STRING}/"
COMMAND sed -e "s/PRODVTOKEN/${CANONICAL_VERSION_STRING}/"
COMMAND sed -e "s/VERSIONTOKEN/${CANONICAL_VERSION_STRING}/"
COMMAND sed -e "s/PRODVTOKEN/${CANONICAL_VERSION_STRING_4}/"
OUTPUT_FILE ${CMAKE_BINARY_DIR}/staging/smtk-import.nsi
)
endif()