Pull request: scripts: imp version
Merge in DNS/adguard-home from 2412-versions to master
Squashed commit of the following:
commit 8c7f11cd2d8987c611a4e828482ba039a55ef677
Merge: 43cd0374 1789c96c
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Wed Mar 10 17:05:58 2021 +0300
Merge branch 'master' into 2412-versions
commit 43cd0374b7c200fdc45e153781e94ca23cf46b7d
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Mar 5 15:27:13 2021 +0300
scripts: imp version
This commit is contained in:
parent
1789c96c7f
commit
2d7042425e
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -10,9 +10,17 @@ and this project adheres to
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
## [v0.106.0] - 2021-04-26
|
## [v0.106.0] - 2021-05-01
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- New, more correct versioning scheme ([#2412]).
|
||||||
|
|
||||||
|
[#2412]: https://github.com/AdguardTeam/AdGuardHome/issues/2412
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [v0.105.2] - 2021-03-10
|
## [v0.105.2] - 2021-03-10
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -123,7 +123,7 @@ directly, or use the commands through `make` (for example, `make go-lint`).
|
||||||
Optional environment:
|
Optional environment:
|
||||||
* `GO`: set an alternarive name for the Go compiler.
|
* `GO`: set an alternarive name for the Go compiler.
|
||||||
|
|
||||||
### `version.sh`: Print The Current Version
|
### `version.sh`: Generate And Print The Current Version
|
||||||
|
|
||||||
Required environment:
|
Required environment:
|
||||||
* `CHANNEL`: release channel, see above.
|
* `CHANNEL`: release channel, see above.
|
||||||
|
|
|
@ -1,47 +1,110 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# AdGuard Home Version Generation Script
|
||||||
|
#
|
||||||
|
# This script generates versions based on the current git tree state.
|
||||||
|
# The valid output formats are:
|
||||||
|
#
|
||||||
|
# * 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.
|
||||||
|
#
|
||||||
|
# * 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.
|
||||||
|
#
|
||||||
|
# * For prerelease alpha versions (aka snapshots),
|
||||||
|
# "v0.123.4-a.6+a1b2c3d4".
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# TODO(a.garipov): The script currently doesn't handle release branches,
|
||||||
|
# so it must be modified once we have those.
|
||||||
|
|
||||||
readonly verbose="${VERBOSE:-0}"
|
readonly verbose="${VERBOSE:-0}"
|
||||||
if [ "$verbose" -gt '1' ]
|
if [ "$verbose" -gt '0' ]
|
||||||
then
|
then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
readonly awk_program='/^v[0-9]+\.[0-9]+\.[0-9]+.*$/ {
|
# bump_minor is an awk program that reads a minor release version,
|
||||||
if (!$4) {
|
# increments the minor part of it, and prints the next version.
|
||||||
# The last tag is a full release version, so bump the
|
readonly bump_minor='/^v[0-9]+\.[0-9]+\.0$/ {
|
||||||
# minor release number and zero the patch release number
|
print($1 "." $2 + 1 ".0");
|
||||||
# to get the next release.
|
|
||||||
$2++;
|
|
||||||
$3 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
print($1 "." $2 "." $3);
|
|
||||||
|
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
printf("invalid version: \"%s\"\n", $0);
|
printf("invalid release version: \"%s\"\n", $0);
|
||||||
|
|
||||||
exit 1;
|
exit 1;
|
||||||
}'
|
}'
|
||||||
|
|
||||||
readonly last_tag="$(git describe --abbrev=0)"
|
# get_last_minor_zero returns the last new minor release.
|
||||||
readonly current_desc="$(git describe)"
|
get_last_minor_zero() {
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# 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").
|
||||||
|
#
|
||||||
|
# Then, sort them by the second field ("2"), and only spanning
|
||||||
|
# the second field (",2"). The sort is also numeric and reverse
|
||||||
|
# ("nr").
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
readonly channel="$CHANNEL"
|
readonly channel="$CHANNEL"
|
||||||
|
|
||||||
case "$channel"
|
case "$channel"
|
||||||
in
|
in
|
||||||
('development')
|
('development')
|
||||||
echo 'v0.0.0'
|
# Use the dummy version for development builds.
|
||||||
|
version='v0.0.0'
|
||||||
;;
|
;;
|
||||||
('edge')
|
('edge')
|
||||||
next=$(echo $last_tag | awk -F '[.+-]' "$awk_program")
|
# last_minor_zero is the last new minor release.
|
||||||
echo "${next}-SNAPSHOT-$(git rev-parse --short HEAD)"
|
readonly last_minor_zero="$(get_last_minor_zero)"
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
readonly num_commits_since_minor="$(git rev-list "${last_minor_zero}..HEAD" | wc -l)"
|
||||||
|
|
||||||
|
# next_minor is the next minor release version.
|
||||||
|
readonly next_minor="$(echo "$last_minor_zero" | awk -F '.' "$bump_minor")"
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
#
|
||||||
|
# v0.124.0-a.5+a1b2c3d4
|
||||||
|
#
|
||||||
|
version="${next_minor}-a.${num_commits_since_minor}+$(git rev-parse --short HEAD)"
|
||||||
;;
|
;;
|
||||||
('beta'|'release')
|
('beta'|'release')
|
||||||
|
# current_desc is the description of the current git commit. If
|
||||||
|
# the current commit is tagged, git describe will show the tag.
|
||||||
|
readonly current_desc="$(git describe)"
|
||||||
|
|
||||||
|
# last_tag is the most recent git tag.
|
||||||
|
readonly last_tag="$(git describe --abbrev=0)"
|
||||||
|
|
||||||
|
# Require an actual tag for the beta and final releases.
|
||||||
if [ "$current_desc" != "$last_tag" ]
|
if [ "$current_desc" != "$last_tag" ]
|
||||||
then
|
then
|
||||||
echo 'need a tag' 1>&2
|
echo 'need a tag' 1>&2
|
||||||
|
@ -49,7 +112,7 @@ in
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$last_tag"
|
version="$last_tag"
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
echo "invalid channel '$channel', supported values are\
|
echo "invalid channel '$channel', supported values are\
|
||||||
|
@ -57,3 +120,13 @@ in
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Finally, make sure that we don't output invalid versions.
|
||||||
|
if ! echo "$version" | grep -E -e '^v[0-9]+\.[0-9]+\.[0-9]+(-[ab]\.[0-9]+)?(\+[[:xdigit:]]+)?' -q
|
||||||
|
then
|
||||||
|
echo "generated an invalid version '$version'" 1>&2
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$version"
|
||||||
|
|
Loading…
Reference in New Issue