Core

/bin/tag.sh (2.2 KB)

 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash

## Tags the git repo using the first argument or the incremented minor version

set -euo pipefail
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $dir/..

# uncommitted file checks
git update-index -q --ignore-submodules --refresh
err=0

if ! git diff-files --quiet --ignore-submodules --
then
echo >&2 "you have unstaged changes."
git diff-files --name-status -r --ignore-submodules -- >&2
err=1
fi

if ! git diff-index --cached --quiet HEAD --ignore-submodules --
then
echo >&2 "your index contains uncommitted changes."
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
err=1
fi

if [ $err = 1 ]
then
echo >&2 "please commit or stash them."
exit 1
fi
# end checks

git fetch --tags

TGT=${1-none}
if [[ $TGT == "none" ]]; then
TGT=$(git describe --match "v[0-9]*" --tags --abbrev=0 | sed -e 's/v//g')
TGT=$(echo ${TGT} | awk -F. -v OFS=. '{$NF++;print}')
fi
if [[ ${TGT:0:1} == "v" ]]; then
TGT="${TGT:1}"
fi

echo $TGT

pat="^[0-9]"
if [[ $TGT =~ $pat ]]; then
sed -i.bak -e "s/version = \\\"[v]*[0-9]*[0-9]\.[0-9]*[0-9]\.[0-9]*[0-9]\\\"/version = \"${TGT}\"/g" ./main.go
rm -f "./main.go.bak"{{{ if .UsesLib }}}
sed -i.bak -e "s/Version: \\\"[v]*[0-9]*[0-9]\.[0-9]*[0-9]\.[0-9]*[0-9]\\\"/Version: \"${TGT}\"/g" ./app/cmd/lib.go
rm -f ./app/cmd/lib.go.bak{{{ end }}}{{{ if .BuildNotarize }}}
sed -i.bak -e "s/\\_[v]*[0-9]*[0-9]\.[0-9]*[0-9]\.[0-9]*[0-9]_/_${TGT}\\_/g" ./tools/notarize/gon.amd64.hcl
rm -f "./tools/notarize/gon.amd64.hcl.bak"
sed -i.bak -e "s/\\_[v]*[0-9]*[0-9]\.[0-9]*[0-9]\.[0-9]*[0-9]_/_${TGT}\\_/g" ./tools/notarize/gon.arm64.hcl
rm -f "./tools/notarize/gon.arm64.hcl.bak"
sed -i.bak -e "s/\\_[v]*[0-9]*[0-9]\.[0-9]*[0-9]\.[0-9]*[0-9]_/_${TGT}\\_/g" ./tools/notarize/gon.all.hcl
rm -f "./tools/notarize/gon.all.hcl.bak"{{{ end }}}
sed -i.bak -e "s/\\\"version\\\": \\\"[v]*[0-9]*[0-9]\.[0-9]*[0-9]\.[0-9]*[0-9]\\\"/\"version\": \"${TGT}\"/g" ./.projectforge/project.json
rm -f "./.projectforge/project.json.bak"
fi

make build

git add .

if [[ $TGT =~ $pat ]]; then
git commit -m "v${TGT}" || true
git tag "v${TGT}"
else
git commit -m "${TGT}" || true
git tag "${TGT}"
fi

git push
git push --tags