Skip to content

Commit dd95471

Browse files
authored
Merge pull request #107 from Jskobos/deploy-script
Deploy script
2 parents a0fe41b + 8171f3f commit dd95471

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

bin/deploy

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
3+
git_tag=""
4+
version=""
5+
version_regex="[0-9]+\.[0-9]+\.[0-9]"
6+
7+
help_text () {
8+
echo
9+
echo "Usage: deploy VERSION"
10+
echo
11+
}
12+
13+
# check for required version to deploy
14+
if [ -z ${1+x} ]; then
15+
help_text
16+
echo "Error: VERSION is required"
17+
exit 1
18+
fi
19+
20+
if [[ "$1" =~ ^${version_regex}$ ]]; then
21+
version="${1}"
22+
git_tag="v${version}"
23+
else
24+
help_text
25+
echo "Error: VERSION must be a valid semantic version (major.minor.patch)"
26+
exit 1
27+
fi
28+
29+
# let's get some permission before making changes
30+
echo
31+
echo "The following changes are about to be made:"
32+
echo " - the development branch will be checked out"
33+
echo " - a new release branch for ${version} will be created at release-${version}"
34+
echo " - the version will be updated to ${version} in openapi.yaml"
35+
echo " - these changes will be commited and tagged ${git_tag}"
36+
echo
37+
read -p "Do you want to continue? " -n 1 -r
38+
echo
39+
40+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
41+
exit 1
42+
fi
43+
44+
# if we have made it this far, we are ready to make changes
45+
echo "Deploying version ${version}"
46+
47+
echo "Checking out development branch"
48+
git checkout development
49+
50+
# ensure no local changes to openapi.yaml
51+
git diff-index --quiet HEAD -- openapi.yaml
52+
53+
exit_status=$?
54+
if [ $exit_status -ne 0 ]; then
55+
echo
56+
echo "Error: Local changes have been made to openapi.yaml."
57+
echo " Please commit those changes before proceeding."
58+
exit 1
59+
fi
60+
61+
echo "Creating a release branch release-${version}"
62+
git checkout -b "release-${version}"
63+
64+
echo "Updating openapi.yaml with the new version number"
65+
sed -E -i.bak "s|version: ${version_regex}|version: ${version}|" openapi.yaml \
66+
&& rm openapi.yaml.bak
67+
68+
echo "Committing the version bump"
69+
git add openapi.yaml
70+
git commit -m "Bump version to ${version}"
71+
72+
echo "Tagging the version commit with the version number"
73+
git tag "${git_tag}"
74+
75+
echo "Running some final checks"
76+
echo
77+
78+
exit_status=0
79+
80+
if grep -Fxq " version: ${version}" openapi.yaml; then
81+
echo "OK - version ${version} is present in openapi.yaml"
82+
else
83+
echo "ERROR - version ${version} is not present in openapi.yaml"
84+
exit_status=1
85+
fi
86+
87+
if git tag | grep -Fxq "${git_tag}"; then
88+
echo "OK - ${git_tag} is present in git tags"
89+
else
90+
echo "ERROR - ${git_tag} is not present in git tags"
91+
exit_status=1
92+
fi
93+
94+
if [ $exit_status -ne 0 ]; then
95+
echo
96+
echo "Please resolve the ERRORs above."
97+
exit 1
98+
else
99+
echo
100+
echo "Release process is complete."
101+
echo
102+
echo "Once confirmed changes are verified, you can:"
103+
echo " git push release-${version}"
104+
echo " git push ${git_tag}"
105+
fi

openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
openapi: 3.0.1
22
info:
3-
version: DEVELOPMENT
3+
version: 4.3.1
44
title: Linode API
55
x-logo: {
66
url: '/api/v4/linode-logo.svg',

0 commit comments

Comments
 (0)