-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.sh
70 lines (59 loc) · 2.28 KB
/
deploy.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
#!/bin/bash
# Calculate new version, based on already existing git tags
# Sets the new version to the NEW_VERSION variable
function get_new_version() {
release_type=$(echo $1 | tr A-Z a-z)
if [[ ${release_type} != "major" && ${release_type} != "minor" && ${release_type} != "patch" ]]; then
echo "Wrong release type: ${release_type}! Run the command as such: ./new_version.sh <release_type>"
echo "Release type can be: major, minor, patch"
exit 1
fi
tags=($(git ls-remote --tags --refs origin | tr -d 'refs/tags/' | cut -f2)) # () -> convert to array
num_tags=${#tags[@]}
if [[ ${num_tags} == 0 ]]; then
NEW_VERSION="0.0.1"
return 0
fi
latest_version=${tags[${#tags[@]}-1]} # alphabetical order, could cause problems: e.g. 1.1.0, 1.10.0, 1.2.0
version_numbers=($(echo ${latest_version} | tr -d 'v' | tr '.' ' '))
major_version=${version_numbers[0]}
minor_version=${version_numbers[1]}
patch_version=${version_numbers[2]}
case ${release_type} in
major)
echo "Bumping up major version..."
major_version=$((major_version + 1))
NEW_VERSION="${major_version}.0.0"
;;
minor)
echo "Bumping up minor version..."
minor_version=$((minor_version + 1))
NEW_VERSION="${major_version}.${minor_version}.0"
;;
patch)
echo "Bumping up patch version..."
patch_version=$((patch_version + 1))
NEW_VERSION="${major_version}.${minor_version}.${patch_version}"
;;
esac
return 0
}
echo "Calculating new version..."
get_new_version ${RELEASE_TYPE}
echo "New version is: ${NEW_VERSION}"
echo "Installing Heroku CLI"
curl https://cli-assets.heroku.com/install.sh | sh
./mvnw versions:set -DnewVersion="${NEW_VERSION}" --no-transfer-progress
echo "Logging into Heroku container registry"
heroku container:login
# Build and push docker image
echo "Building and pushing docker image with JIB"
./mvnw compile jib:build --no-transfer-progress
echo "Deploying..."
heroku container:release web --app $HEROKU_APP
echo "Deployment successful. Tagging release"
git status
git restore pom.xml mvnw
git checkout ${TRAVIS_BRANCH}
git tag -a v${NEW_VERSION} -m "Release v${NEW_VERSION}"
git push --tags https://${GITHUB_TOKEN}@github.com/${GITHUB_USER}/JobPortalBE.git ${TRAVIS_BRANCH}