-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtag-release.sh
More file actions
executable file
·62 lines (52 loc) · 1.62 KB
/
tag-release.sh
File metadata and controls
executable file
·62 lines (52 loc) · 1.62 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
#!/bin/bash
# Copyright (c) Codesphere Inc.
# SPDX-License-Identifier: Apache-2.0
set -eu
BRANCH=$(git branch --show-current)
if [[ "$BRANCH" != "main" ]]; then
echo "This script should only run on main branch, not $BRANCH"
exit 1
fi
TAG=$(git tag | sort -uV | tail -n 1 | xargs echo -n)
LIST="HEAD"
if [[ "$TAG" != "" ]]; then
LIST="$TAG..HEAD"
fi
echo $LIST
LOG=$(git log "$LIST" --pretty=format:%s)
BREAK=$(grep -E '!' >/dev/null <<< "$LOG"; echo $?)
FEAT=$(grep -E '^(feat|update)' >/dev/null <<< "$LOG"; echo $?)
FIX=$(grep -E '^fix' >/dev/null <<< "$LOG"; echo $?)
echo "Latest tag: $TAG"
echo "------"
echo "Relevant changes:"
echo "$LOG"
echo "------"
if [[ "$TAG" == "" ]]; then
TAG=v0.0.0
fi
NEWTAG="$TAG"
if [[ $BREAK -eq 0 ]]; then
echo "Breaking change! Increasing major."
NEWTAG=$(sed -r 's/v([0-9]+)\.[0-9]+\.[0-9]+/echo "v$((\1+1)).0.0"/e' <<< "$TAG")
elif [[ $FEAT -eq 0 ]]; then
echo "New feature! Increasing minor."
NEWTAG=$(sed -r 's/v([0-9])+\.([0-9]+)\.[0-9]+/echo "v\1.$((\2+1)).0"/e' <<< "$TAG")
elif [[ $FIX -eq 0 ]]; then
echo "New fix! Increasing patch."
NEWTAG=$(sed -r 's/v([0-9])+\.([0-9]+)\.([0-9]+)/echo "v\1.\2.$((\3+1))"/e' <<< "$TAG")
fi
if [[ $NEWTAG == $TAG ]]; then
echo "Nothing to tag."
exit 0
fi
echo "Tagging $NEWTAG"
git tag "$NEWTAG"
git push origin "$NEWTAG"
echo "Triggering release of version $NEWTAG"
go install github.com/goreleaser/goreleaser/v2@latest
goreleaser release --clean
echo "RELEASE_VERSION=$NEWTAG" >> $GITHUB_ENV
# Hash length fixed to 10 characters to get deterministic folder names
FOLDER="$(git rev-parse --short=10 HEAD)"
echo "FOLDER=$FOLDER" >> $GITHUB_ENV