summaryrefslogtreecommitdiff
path: root/generate-version.sh
blob: 8375c864cac6460079bab6db597f6f165e6e5dfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh

exec 3>&2 2> /dev/null
SRCDIR=$(dirname "$0")
cd "$SRCDIR"
CWD=$(realpath "$PWD")
exec 2>&3

# If it's not from a git checkout, assume it's from a tarball
if ! git rev-parse --is-inside-git-dir > /dev/null 2>&1; then
    VERSION_FROM_DIR_NAME=$(basename "$CWD" | sed -n 's/^accountsservice-\([^-]*\)$/\1/p')

    if [ -n "$VERSION_FROM_DIR_NAME" ]; then
        echo "$VERSION_FROM_DIR_NAME"
        exit 0
    fi

    echo "Source doesn't appear to come from an accountsservice git clone or tarball. Version unknown."
    exit 1
fi

# If it is from a git checkout, derive the version from the date of the last commit, and the number
# of commits since the last release.
COMMITS_SINCE_LAST_RELEASE=$(git rev-list $(git describe --abbrev=0)..HEAD --count)
date +%y.%V.${COMMITS_SINCE_LAST_RELEASE} -d "@$(git log -1 --pretty=format:%ct)"