-
Notifications
You must be signed in to change notification settings - Fork 1
/
githubDeployment.sh
executable file
·94 lines (85 loc) · 2.22 KB
/
githubDeployment.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
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
TGT_URL='https://api.github.com/repos/code4nara/covid19/deployments'
#TGT_URL='https://api.github.com/repos/yasushiIS/covid19/deployments'
TGT_REF="development" # master
TGT_ENV="development" # production
BATCH_FLAG=0
DRYRUN_FLAG=0
####
# Start Massege / Usage
####
usage_exit() {
echo
echo " Execute Github Action Scrpit" 1>&2
echo " Usage: $0 [-b] [-e environment]" 1>&2
echo " -b Execute batch mode, no confirmation." 1>&2
echo " -u url GitHub URL, default is ${TGT_URL} ." 1>&2
echo " -r reffer Set Deploy Reffer, default is ${TGT_ERF} ." 1>&2
echo " -e Environment Set Deploy Environment, default is ${TGT_ENV} ." 1>&2
exit 1
}
####
# Yes/no check
####
YN_CHECK()
{
while true; do
read -p ' Continue? [Y/n] ' Answer
case $Answer in
'' | [Yy]* )
break;
;;
[Nn]* )
echo " CANCELed."
exit;
;;
* )
echo Please answer YES or NO.
esac
done
}
####
# Main
####
# GitHub Token
if [ "${GITHUB_TOKEN}" = "" ] ; then
echo '=---------------------------------------------------------------------='
echo ' GITHUB_TOKEN not Found'
echo ' Set your Github token to environment variable "GITHUB_TOKEN"'
echo '=---------------------------------------------------------------------='
usage_exit
fi
# Option Check
while getopts "hbdu:r:e:" OPT
do
case $OPT in
h) usage_exit ;;
b) BATCH_FLAG=1 ;;
d) DRYRUN_FLAG=1 ;;
u) TGT_URL=$OPTARG ;;
e) TGT_ENV=$OPTARG ;;
r) TGT_REF=$OPTARG ;;
esac
done
# Option Check
if [ ${BATCH_FLAG} == 0 ] ; then
echo " TGT_URL: ${TGT_URL} TGT_Reffer: ${TGT_REF} TGT_Environment: ${TGT_ENV}"
YN_CHECK
echo
fi
JSON='{"ref":"'${TGT_REF}'", "environment":"'${TGT_ENV}'", "auto_merge":false}'
CMD="curl -X POST -H \"Authorization: token ${GITHUB_TOKEN}\" -H \"Content-Type: application/json\" ${TGT_URL} --data '${JSON}'"
if [ ${DRYRUN_FLAG} == 1 ] ; then
# RRYRUN for debug
echo " mode DRYRUN"
echo " cmd: "${CMD}
else
# Exec Command
eval "${CMD}"
fi
####
# End Massege
####
echo
echo " Finished"