-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrelease.sh
executable file
·84 lines (72 loc) · 2.41 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
# Describe this script
echo This script releases a feature branch by merging the current branch into
echo master, tagging a new version, and pushing master up to origin.
echo
# Grab the current version number
CURRENT=`tail -1 version.txt`
NEXT=`tail -1 version.txt | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}'`
FEAT=`git rev-parse --abbrev-ref HEAD`
# Show additional detail and wait for confirmation
echo Current version: $CURRENT
echo
echo To change the major or minor version number:
echo " echo x.x.0 >> version.txt"
echo
echo Releasing $FEAT branch as v$NEXT
echo
read -p "Press Enter to continue or Ctrl-C to stop"
# Verify we aren't on master
if [ "$FEAT" != "master" ]; then
# Verify we don't have uncommitted changes
if [[ -n $(git status -s) ]]; then
echo Error: There are uncommitted changes.
exit 1
fi
# Append an incremented version number to the version.txt file
echo $NEXT >> version.txt
# Append commit messages to the CHANGELOG file
echo $NEXT >> CHANGELOG.txt
git log v$CURRENT..HEAD --pretty=" - %s" --no-merges >> CHANGELOG.txt
echo >> CHANGELOG.txt
# Copy the css files to the docs file (for GH Pages)
cp neat.css ./docs/
cp custom.css ./docs/
cp neat.html ./docs
cp neat.html ./docs/index.html
echo "<script src=\"https://counter.joeldare.com/counter.js\" async></script>" >> ./docs/index.html
# Commit the changes above
if ! git add .; then
echo ERROR: Unable to add version and css files.
exit 1
fi
if ! git commit -m "docs: update version number and docs css"; then
echo ERROR: Unable to commit version and css files.
exit 1
fi
# Create a release tag and push it to GitHub
if ! git checkout master; then
echo ERROR: Failed to checkout master.
exit 1
fi
if ! git merge $FEAT; then
echo ERROR: Failed to merge the feature branch.
exit 1
fi
if ! git tag -a v$NEXT -m "release: v$NEXT"; then
echo ERROR: Failed to tag the new version.
exit 1
fi
if ! git push; then
echo ERROR: Failed to push all commited changes.
exit 1
fi
if ! git push --tags; then
echo ERROR: Failed to push the new tag.
exit 1
fi
# Exit with a successful code
exit 0
fi
# Exit with an error code
echo "You should be on a feature branch."
exit 1