2020-12-30 18:26:25 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-03-10 18:08:47 +03:00
|
|
|
# AdGuard Home Version Generation Script
|
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
# This script generates versions based on the current git tree state. The valid
|
|
|
|
# output formats are:
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
# * For release versions, "v0.123.4". This version should be the one in the
|
|
|
|
# current tag, and the script merely checks, that the current commit is
|
|
|
|
# properly tagged.
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
# * For prerelease beta versions, "v0.123.4-b.5". This version should be the
|
|
|
|
# one in the current tag, and the script merely checks, that the current
|
|
|
|
# commit is properly tagged.
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
# * For prerelease alpha versions (aka snapshots), "v0.123.4-a.6+a1b2c3d4".
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
# BUG(a.garipov): The script currently can't differentiate between beta tags and
|
|
|
|
# release tags if they are on the same commit, so the beta tag **must** be
|
|
|
|
# pushed and built **before** the release tag is pushed.
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
# TODO(a.garipov): The script currently doesn't handle release branches, so it
|
|
|
|
# must be modified once we have those.
|
|
|
|
|
|
|
|
verbose="${VERBOSE:-0}"
|
|
|
|
readonly verbose
|
2021-03-10 18:08:47 +03:00
|
|
|
|
|
|
|
if [ "$verbose" -gt '0' ]
|
2020-12-30 18:26:25 +03:00
|
|
|
then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e -f -u
|
|
|
|
|
2021-05-19 20:31:20 +03:00
|
|
|
# bump_minor is an awk program that reads a minor release version, increments
|
|
|
|
# the minor part of it, and prints the next version.
|
2021-06-10 20:09:00 +03:00
|
|
|
#
|
|
|
|
# shellcheck disable=SC2016
|
2021-05-19 20:31:20 +03:00
|
|
|
bump_minor='/^v[0-9]+\.[0-9]+\.0$/ {
|
2021-03-10 18:08:47 +03:00
|
|
|
print($1 "." $2 + 1 ".0");
|
2020-12-30 18:26:25 +03:00
|
|
|
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-03-10 18:08:47 +03:00
|
|
|
printf("invalid release version: \"%s\"\n", $0);
|
2020-12-30 18:26:25 +03:00
|
|
|
|
|
|
|
exit 1;
|
|
|
|
}'
|
2021-05-19 20:31:20 +03:00
|
|
|
readonly bump_minor
|
2020-12-30 18:26:25 +03:00
|
|
|
|
2021-03-10 18:08:47 +03:00
|
|
|
# get_last_minor_zero returns the last new minor release.
|
|
|
|
get_last_minor_zero() {
|
2021-05-19 20:31:20 +03:00
|
|
|
# List all tags. Then, select those that fit the pattern of a new minor
|
|
|
|
# release: a semver version with the patch part set to zero.
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
# Then, sort them first by the first field ("1"), starting with the
|
|
|
|
# second character to skip the "v" prefix (".2"), and only spanning the
|
|
|
|
# first field (",1"). The sort is numeric and reverse ("nr").
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
# Then, sort them by the second field ("2"), and only spanning the
|
|
|
|
# second field (",2"). The sort is also numeric and reverse ("nr").
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
|
|
|
# Finally, get the top (that is, most recent) version.
|
|
|
|
git tag\
|
|
|
|
| grep -e 'v[0-9]\+\.[0-9]\+\.0$'\
|
|
|
|
| sort -k 1.2,1nr -k 2,2nr -t '.'\
|
|
|
|
| head -n 1
|
|
|
|
}
|
2020-12-30 18:26:25 +03:00
|
|
|
|
2021-06-10 20:09:00 +03:00
|
|
|
channel="${CHANNEL:?please set CHANNEL}"
|
2021-05-19 20:31:20 +03:00
|
|
|
readonly channel
|
2021-03-10 18:08:47 +03:00
|
|
|
|
2020-12-30 18:26:25 +03:00
|
|
|
case "$channel"
|
|
|
|
in
|
|
|
|
('development')
|
2024-02-09 13:47:04 +03:00
|
|
|
# commit_number is the number of current commit within the branch.
|
|
|
|
commit_number="$( git rev-list --count master..HEAD )"
|
|
|
|
readonly commit_number
|
|
|
|
|
|
|
|
# The development builds are described with a combination of unset semantic
|
|
|
|
# version, the commit's number within the branch, and the commit hash, e.g.:
|
|
|
|
#
|
|
|
|
# v0.0.0-dev.5-a1b2c3d4
|
|
|
|
#
|
|
|
|
version="v0.0.0-dev.${commit_number}+$( git rev-parse --short HEAD )"
|
2020-12-30 18:26:25 +03:00
|
|
|
;;
|
|
|
|
('edge')
|
2021-03-10 18:08:47 +03:00
|
|
|
# last_minor_zero is the last new minor release.
|
2021-05-19 20:31:20 +03:00
|
|
|
last_minor_zero="$( get_last_minor_zero )"
|
|
|
|
readonly last_minor_zero
|
2021-03-10 18:08:47 +03:00
|
|
|
|
2021-05-19 20:31:20 +03:00
|
|
|
# num_commits_since_minor is the number of commits since the last new
|
|
|
|
# minor release. If the current commit is the new minor release,
|
|
|
|
# num_commits_since_minor is zero.
|
2022-09-21 19:21:13 +03:00
|
|
|
num_commits_since_minor="$( git rev-list --count "${last_minor_zero}..HEAD" )"
|
2021-05-19 20:31:20 +03:00
|
|
|
readonly num_commits_since_minor
|
2021-03-10 18:08:47 +03:00
|
|
|
|
|
|
|
# next_minor is the next minor release version.
|
2021-05-19 20:31:20 +03:00
|
|
|
next_minor="$( echo "$last_minor_zero" | awk -F '.' "$bump_minor" )"
|
|
|
|
readonly next_minor
|
2021-03-10 18:08:47 +03:00
|
|
|
|
2021-05-19 20:31:20 +03:00
|
|
|
# Make this commit a prerelease version for the next minor release. For
|
|
|
|
# example, if the last minor release was v0.123.0, and the current
|
|
|
|
# commit is the fifth since then, the version will look something like:
|
2021-03-10 18:08:47 +03:00
|
|
|
#
|
|
|
|
# v0.124.0-a.5+a1b2c3d4
|
|
|
|
#
|
2021-05-19 20:31:20 +03:00
|
|
|
version="${next_minor}-a.${num_commits_since_minor}+$( git rev-parse --short HEAD )"
|
2020-12-30 18:26:25 +03:00
|
|
|
;;
|
|
|
|
('beta'|'release')
|
2021-05-19 20:31:20 +03:00
|
|
|
# current_desc is the description of the current git commit. If the
|
|
|
|
# current commit is tagged, git describe will show the tag.
|
|
|
|
current_desc="$( git describe )"
|
|
|
|
readonly current_desc
|
2021-03-10 18:08:47 +03:00
|
|
|
|
|
|
|
# last_tag is the most recent git tag.
|
2021-05-19 20:31:20 +03:00
|
|
|
last_tag="$( git describe --abbrev=0 )"
|
|
|
|
readonly last_tag
|
2021-03-10 18:08:47 +03:00
|
|
|
|
|
|
|
# Require an actual tag for the beta and final releases.
|
2020-12-30 18:26:25 +03:00
|
|
|
if [ "$current_desc" != "$last_tag" ]
|
|
|
|
then
|
|
|
|
echo 'need a tag' 1>&2
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-10 18:08:47 +03:00
|
|
|
version="$last_tag"
|
2020-12-30 18:26:25 +03:00
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
echo "invalid channel '$channel', supported values are\
|
|
|
|
'development', 'edge', 'beta', and 'release'" 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2021-03-10 18:08:47 +03:00
|
|
|
|
|
|
|
# Finally, make sure that we don't output invalid versions.
|
2024-02-09 13:47:04 +03:00
|
|
|
if ! echo "$version" | grep -E -e '^v[0-9]+\.[0-9]+\.[0-9]+(-(a|b|dev)\.[0-9]+)?(\+[[:xdigit:]]+)?$' -q
|
2021-03-10 18:08:47 +03:00
|
|
|
then
|
|
|
|
echo "generated an invalid version '$version'" 1>&2
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$version"
|