-
Notifications
You must be signed in to change notification settings - Fork 5
/
push-tags.sh
executable file
·62 lines (55 loc) · 1.85 KB
/
push-tags.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
#!/bin/bash
TRAVIS_BRANCH="${TRAVIS_BRANCH:?Missing variable}"
TRAVIS_PULL_REQUEST="${TRAVIS_PULL_REQUEST:?Missing variable}"
NEW_VERSION_TAG="${NEW_VERSION_TAG:?Missing variable}"
NEW_VERSION_DESCRIPTION="${NEW_VERSION_DESCRIPTION:?Missing variable}"
GIT_USER_NAME="${GIT_USER_NAME:?Missing variable}"
GIT_ACCESS_TOKEN="${GIT_ACCESS_TOKEN:?Missing variable}"
# TRAVIS_PULL_REQUEST is false when the source of the pipeline is NOT a pull request
# if the source of the pipeline is a pull request (a non-false answer), set branch to dev
# and deviate to a dry run
if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then
TRAVIS_BRANCH="dev"
fi
git_configure() {
git config --global user.email "[email protected]"
git config --global user.name "Travis CI"
}
git_push_tags() {
if git checkout -f main; then
echo "Checked out latest version of main branch"
else
echo "git checkout process failed - exiting!"
exit 1
fi
if git tag "${NEW_VERSION_TAG}" -a -m "${NEW_VERSION_DESCRIPTION}"; then
echo "Tagged with version ${NEW_VERSION_TAG}"
else
echo "git tag process failed - exiting!"
exit 1
fi
if git push -q https://"${GIT_USER_NAME}":"${GIT_ACCESS_TOKEN}"@github.com/"${TRAVIS_REPO_SLUG}".git --tags; then
echo "Release pushed to git successfully"
else
echo "git push failed - exiting!"
exit 1
fi
}
case $TRAVIS_BRANCH in
"develop" | "dev")
# Dry run for debug
echo "Dry run push for version ${NEW_VERSION_TAG} with description ${NEW_VERSION_DESCRIPTION}"
git_configure
git status
;;
"main")
# Push tags to git
git_configure
git_push_tags
;;
*)
# Error due to invalid branch
echo "Invalid branch. Current value of TRAVIS_BRANCH: $TRAVIS_BRANCH"
exit 1
;;
esac