-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.sh
executable file
·88 lines (77 loc) · 2.97 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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-]+)*))?$"
packagejson=offchain/package.json
current_version=$(cat $packagejson | jq -r ".version")
# 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 [next-major|next-minor|next-patch|<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
case $1 in
next-major | next-minor | next-patch)
if [[ "$current_version" =~ $semver_pattern ]]; then
case $1 in
next-major) next_version="$((BASH_REMATCH[1]+1)).0.0" ;;
next-minor) next_version="${BASH_REMATCH[1]}.$((BASH_REMATCH[2]+1)).0" ;;
next-patch) next_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((BASH_REMATCH[3]+1))" ;;
esac
else
echo "FATAL: version number in $packagejson is not valid semver!"
fi
;;
*)
if [[ "$1" =~ $semver_pattern ]]; then
next_version=$1
else
echo "ERROR: provided version ($1) is not valid semver"
fi
;;
esac
# 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 (last version: $current_version)"
cat $packagejson | jq ".version=\"$next_version\"" | sponge $packagejson
pushd offchain > /dev/null || exit
npm install --package-lock-only
popd > /dev/null || exit
# 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"