-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdev-version.sh
executable file
·47 lines (37 loc) · 1.39 KB
/
dev-version.sh
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# dev-version.sh -- this generates filenames like 'viam-agent-v0.15.1-dev.4-x86_64' for prereleases.
# To test locally, comment out the `git status` stanza and do:
# `GITHUB_REF_NAME=main ./dev-setup.sh` (to just see the version)
# `GITHUB_REF_NAME=main make all` (for an actual build)
# Exit with a blank if tree is dirty
if [ -n "$(git status -s)" ]; then
exit 0
fi
# See if we have a direct tag
DIRECT_TAG=$(git tag --points-at | tr - \~ | sort -Vr | tr \~ - | head -n1)
if [ -n "$DIRECT_TAG" ]; then
echo ${DIRECT_TAG}
exit 0
fi
if [ -z "$GITHUB_REF_NAME" ]; then
GITHUB_REF_NAME=$(git rev-parse --abbrev-ref HEAD)
fi
# If we're not on main, we have no (automated) version to create
if [ "$GITHUB_REF_NAME" != "main" ]; then
exit 0
fi
# If we don't have a direct tag, use the most recent non-RC tag
DESC=$(git describe --tags --match="v*" --exclude="*-rc*" --long | sed 's/^v//')
BASE_VERSION=$(echo "$DESC" | cut -d'-' -f1)
COMMITS_SINCE_TAG=$(echo "$DESC" | cut -d'-' -f2)
# Calculate next version by incrementing patch number
NEXT_VERSION=$(echo "$BASE_VERSION" | awk -F. '{$3+=1}1' OFS=.)
# Set TAG_VERSION based on commits since last tag
if [ "$COMMITS_SINCE_TAG" -eq 0 ]; then
TAG_VERSION="$BASE_VERSION"
else
TAG_VERSION="${NEXT_VERSION}-dev.${COMMITS_SINCE_TAG}"
fi
# Set PATH_VERSION based on TAG_VERSION
PATH_VERSION="v${TAG_VERSION}"
echo ${PATH_VERSION}