-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease.sh
executable file
·68 lines (56 loc) · 2.08 KB
/
release.sh
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
#!/usr/bin/env bash
# offical semver regex from https://regex101.com/r/Ly7O1x/3/
semver_pattern="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-((0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$"
# shellcheck disable=SC2125
cabalfile=onchain/*.cabal
hsfiles=$(find onchain/src -type f -name "*.hs")
if [[ -z $IN_NIX_SHELL ]]; then
echo "The release script must be run from inside a nix shell"
echo " run 'nix develop' first"
exit 1
fi
if [[ ($# -eq 0) || $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: $0 <semver>"
exit 1
fi
# check if there are any modified files (based on https://stackoverflow.com/a/3879077)
git update-index --refresh &> /dev/null
git diff-index --quiet HEAD --
if [[ ($? -eq 1) ]]; then
echo "Release script can only run on a clean repo. Please stash your changes."
exit 1
fi
if [[ $(git rev-parse --abbrev-ref HEAD) != "master" ]]; then
echo "WARNING: you are trying to cut a release from a branch other than master!"
read -r -n1 -p "Do you wish to continue? [y/n]" yesno
printf "\n"
if [[ "$yesno" =~ ^[^Yy]$ ]]; then
echo "Aborting..."
exit 1
fi
fi
if [[ "$1" =~ $semver_pattern ]]; then
next_version=$1
else
echo "ERROR: provided version ($1) is not valid semver"
fi
# if we didn't set next_version above we exit
if [ -z "${next_version+x}" ]; then exit 1; fi
# we check if release tag already exists
if git show-ref --tags "v$next_version" --quiet; then
echo "ERROR: tag already exists for version!"
exit 1
fi
echo "Making release changes for new release $next_version"
# shellcheck disable=SC2086
changie batch $next_version
changie merge
# shellcheck disable=SC2086
sed -i -r "s/^version:(\s*)\S+$/version:\1$next_version/" $cabalfile
# shellcheck disable=SC2086
sed -i -r "s/@since (U|u)nreleased/@since v$next_version/" $hsfiles
# shellcheck disable=SC2086
cargo set-version --manifest-path raw-scripts/Cargo.toml $next_version
git checkout -b "release-v$next_version"
git add .
git commit -m "chore: bump version to v$next_version"