-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathrelease
executable file
·87 lines (67 loc) · 2.2 KB
/
release
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
#!/bin/bash
# Get the current version from the Cargo.toml file
if [[ ! -f Cargo.toml ]]; then
echo "Could not find Cargo.toml file"
echo "Run release from project root"
exit 1
fi
CVER=$(grep -E '^version' Cargo.toml | head -1 | sed -E 's/version\ =\ "(.+)"/\1/')
if [[ -z $1 ]]; then
echo
echo " Current Version: $CVER"
echo
echo " Usage: ./release <VERSION>"
echo
exit 1
fi
set -euo pipefail
if [[ $(git rev-parse --abbrev-ref HEAD) != "master" ]]; then
echo "not ok - Must release on 'master' branch"
exit 1
fi
if [[ $(git status -s | wc -l | awk '{print $1}') -gt 0 ]]; then
echo "not ok - Please commit all changes before releasing"
exit 1
fi
NVER=$1
if [[ ! $(grep "v${NVER}" CHANGELOG.md | wc -l | awk '{print $1}') -eq 1 ]]; then
echo "not ok - Add version to CHANGELOG.md before releasing"
exit 1
fi
sed -i.bak "s/\"$CVER\"/\"$NVER\"/" ./Cargo.toml
rm ./Cargo.toml.bak
echo "ok - Updated Cargo.toml"
if [[ ! $(git diff Cargo.toml | grep '^+' | wc -l | awk '{print $1}') -eq 2 ]]; then
echo "not ok - Failed to update Cargo.toml"
exit 1
fi
sed -i.bak "s/\"$CVER\"/\"$NVER\"/" ./src/lib.rs
rm -f ./src/lib.rs.bak
echo "ok - Updated src/lib.rs"
if [[ ! $(git diff ./src/lib.rs | grep '^+' | wc -l | awk '{print $1}') -eq 2 ]]; then
echo "not ok - Failed to update src/lib.rs"
exit 1
fi
sed -i.bak "s/$CVER/$NVER/" ./src/cli.yml
rm -f ./src/cli.yml.bak
echo "ok - Updated src/cli.yml"
if [[ ! $(git diff ./src/cli.yml | grep '^+' | wc -l | awk '{print $1}') -eq 2 ]]; then
echo "not ok - Failed to update src/cli.yml"
exit 1
fi
# Get CHANGELOG INFO
CHANGE_START=$(echo $(grep -n "## v${NVER}" CHANGELOG.md | grep -Eo '^[0-9]+') + 1 | bc)
CHANGE_END=$(echo $(grep -n "## v${CVER}" CHANGELOG.md | grep -Eo '^[0-9]+') - 1 | bc)
CHANGE="$(sed -n "${CHANGE_START},${CHANGE_END}p" CHANGELOG.md)"
# Ensure that a release can be built and Cargo.lock is updated
cargo build --release
git commit -am "v${NVER}"
git tag "v${NVER}"
git push
git push --tags
echo "ok - $CVER => $NVER"
echo "ok - release pushed!"
echo
echo "${CHANGE}"
echo
echo "ok - your release will be available here once CI is complete - https://github.com/mapbox/Hecate/releases"