aboutsummaryrefslogtreecommitdiff
path: root/docs/release_script.sh
blob: 84e69c68277b8d386c4704981dabdcb29e3da0ba (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# ARG_OPTIONAL_BOOLEAN([no-check],[n],[Skip checking preconditions, such as a clean git working directory])
# ARG_HELP([Script to help creating releases])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.10.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info


die()
{
	local _ret="${2:-1}"
	test "${_PRINT_HELP:-no}" = yes && print_help >&2
	echo "$1" >&2
	exit "${_ret}"
}


begins_with_short_option()
{
	local first_option all_short_options='nh'
	first_option="${1:0:1}"
	test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}

# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_no_check="off"


print_help()
{
	printf '%s\n' "Script to help creating releases"
	printf 'Usage: %s [-n|--(no-)no-check] [-h|--help]\n' "$0"
	printf '\t%s\n' "-n, --no-check, --no-no-check: Skip checking preconditions, such as a clean git working directory (off by default)"
	printf '\t%s\n' "-h, --help: Prints help"
}


parse_commandline()
{
	while test $# -gt 0
	do
		_key="$1"
		case "$_key" in
			-n|--no-no-check|--no-check)
				_arg_no_check="on"
				test "${1:0:5}" = "--no-" && _arg_no_check="off"
				;;
			-n*)
				_arg_no_check="on"
				_next="${_key##-n}"
				if test -n "$_next" -a "$_next" != "$_key"
				then
					{ begins_with_short_option "$_next" && shift && set -- "-n" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
				fi
				;;
			-h|--help)
				print_help
				exit 0
				;;
			-h*)
				print_help
				exit 0
				;;
			*)
				_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
				;;
		esac
		shift
	done
}

parse_commandline "$@"

# OTHER STUFF GENERATED BY Argbash

### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
set -euo pipefail

REMOTE=origin
BRANCH=master

basedir="$(dirname "$(dirname "$(realpath "$0")")")"
echo "Found base directory at $basedir"

if ! [ -d "$basedir/.git" ]; then
    echo Could not find git directory.
    exit 1
fi

if [ -n "$(git status --porcelain)" ] && [ "$_arg_no_check" == off ]; then
    echo Unclean git working environment
    exit 1
fi

if ! [[ "$(git rev-parse --abbrev-ref HEAD)" = "$BRANCH" ]]; then
    echo "Not on branch $BRANCH."
    exit 1
fi

git fetch --tags "$REMOTE"

git tag --list --sort=taggerdate

oldversion="$(git tag --list --sort=taggerdate | tail -n1)"

echo "Choosing old version as $oldversion"

echo -n "Choosing next version as: "
read newversion
echo "Confirming new version as $newversion"

echo Editing gradle.properties
sed -i -E 's/(mod_version *= *).*/\1'"$newversion"'/' "$basedir"/gradle.properties
git add gradle.properties
echo Committing release commit
git commit -m 'Prepare release '"$newversion"'

[no changelog]'
echo Tagging release commit
git tag "$newversion"
mkdir -p "$basedir/.gradle"
releasenotes="$basedir/.gradle/releasenotes.md"

echo Building release notes
echo "**Full Changelog**: https://github.com/nea89o/Firmament/compare/$oldversion...$newversion" > "$releasenotes"
echo >> "$releasenotes"
git log --pretty='- %s' --grep '[no changelog]' --invert-grep --fixed-strings "$oldversion..$newversion" | tac >> "$releasenotes"
echo >> "$releasenotes"

echo Check Release notes:
echo ----------------------------------------------
cat "$releasenotes"
echo ----------------------------------------------
echo Press Enter to resume
read

echo Building JAR
"$basedir"/gradlew clean build

echo Release notes:
echo ----------------------------------------------
cat "$releasenotes"
echo ----------------------------------------------

echo Pushing to github
git push "$REMOTE" "$BRANCH" "$newversion"

if command -v gh; then
    echo Creating github release
    (set -x; gh release create -t "Firmament $newversion" "$newversion" -F "$releasenotes" "$basedir/build/libs/Firmament-$newversion.jar")
else
    echo Could not find github command utility. Opening github releases
    xdg-open "https://github.com/nea89o/firmament/releases/new"
fi

echo Opening modrinth releases
xdg-open "https://modrinth.com/mod/firmament/versions"

echo "Don't forget to upload a discord release as well:"

# ] <-- needed because of Argbash