-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
101 lines (85 loc) · 2.57 KB
/
deploy.sh
File metadata and controls
101 lines (85 loc) · 2.57 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# get own directory (i.e. the directory, this script resides in)
OWNDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# parse options, create a test versiontag as default
prefix=tv
while [[ $# ]]; do
case $1 in
-t | --test)
prefix=tv
shift
;;
-r | --release)
prefix=rv
shift
;;
*)
# first non-option argument
break
esac
done
# test if pyproject.toml exists
PYPROJECTFILEcandidate=$OWNDIR/pyproject.toml
if [[ ! -f "$PYPROJECTFILEcandidate" ]]; then
PYPROJECTFILE=NOT_FOUND
versiontag=NOT_FOUND
else
# extract version from pyproject.toml
PYPROJECTFILE=$PYPROJECTFILEcandidate
versiontag=${prefix}$( grep "version" $PYPROJECTFILE | grep -o '".*"' | sed 's/"//g' )
fi
# display info
echo ""
echo "Project file: $PYPROJECTFILE"
echo "Version tag : $versiontag"
echo ""
# display help if called without arguments
if [[ $1 = --help ]] || [[ $1 = help ]]; then
echo ""
echo "Usage: deploy [option] [gitremote]"
echo " [option] --> One of the following two options:"
echo " * -r or --release for release tag (rv*)"
echo " * -t or --test for test-release tag (tv*)"
echo " [gitremote] --> git remote to be used (default is used if not specified)"
echo ""
echo "NOTES:"
echo " * If no option is given, a test-release tag is created."
echo " * You can delete the tag from github using the following command:"
echo " git push --delete gitremotename $versiontag "
echo " * Local repository tag can be deleted by invoking:"
echo " git tag -d $versiontag"
echo ""
exit 0
fi
# if no version tag is found, error
if [[ "$versiontag" = "NOT_FOUND" ]]; then
echo "Could not find project file."
echo "Expected location: $PYPROJECTFILEcandidate"
exit 1
fi
# first argument (if available): remote
if [[ "$1" = "" ]]; then
gitremote=$( git remote | head -n 1 )
else
gitremote=$1
fi
# set working directory
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$parent_path"
# get HEAD's git commit id
commit_hash=$(git rev-parse HEAD)
# commands to be executed
gitUPDATEREF=(git update-ref refs/tags/$versiontag $commit_hash)
gitPUSH=(git push $gitremote $versiontag)
# display commands
echo ""
echo "Invoking following commands:"
echo " ${gitUPDATEREF[@]}"
echo " ${gitPUSH[@]}"
echo ""
echo "Press Ctrl-C to abort, enter to continue."
read -n 1 -s
# push invokes Package ci-cd workflow on github, jobs build and deploy
# run the commands
"${gitUPDATEREF[@]}"
"${gitPUSH[@]}"