forked from ambientlight/amplify-cli-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·120 lines (97 loc) · 3.29 KB
/
entrypoint.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash -l
set -e
if [ -z "$AWS_ACCESS_KEY_ID" ] && [ -z "$AWS_SECRET_ACCESS_KEY" ] ; then
echo "You must provide the action with both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables in order to deploy"
exit 1
fi
if [ -z "$AWS_REGION" ] ; then
echo "You must provide AWS_REGION environment variable in order to deploy"
exit 1
fi
if [ -z "$5" ] ; then
echo "You must provide amplify_command input parameter in order to deploy"
exit 1
fi
if [ -z "$6" ] ; then
echo "You must provide amplify_env input parameter in order to deploy"
exit 1
fi
# cd to project_dir if custom subfolder is specified
if [ -n "$1" ] ; then
cd "$1"
fi
# if amplify if available at path and custom amplify version is unspecified, do nothing,
# otherwise install globally latest npm version
# FIXME: weird: using local dep amplify-cli bugs with awscloudformation provider: with using provider underfined
if [ -z $(which amplify) ] || [ -n "$8" ] ; then
echo "Installing amplify globaly"
npm install -g @aws-amplify/cli@${8}
# elif [ ! -f ./node_modules/.bin/amplify ] ; then
else
echo "using amplify available at PATH"
# else
# echo "using local project dependency amplify"
# PATH="$PATH:$(pwd)/node_modules/.bin"
fi
which amplify
echo "amplify version $(amplify --version)"
case $5 in
push)
amplify push $9 --yes
;;
publish)
amplify publish $9 --yes
;;
status)
amplify status $9
;;
configure)
echo '{"projectPath": "'"$(pwd)"'","defaultEditor":"code","envName":"'$6'"}' > ./amplify/.config/local-env-info.json
# if environment doesn't exist fail explicitly
if [ -z "$(amplify env get --name $6 | grep 'No environment found')" ] ; then
echo "found existing environment $6"
amplify env pull --yes $9
else
echo "$6 environment does not exist, consider using add_env command instead";
exit 1
fi
amplify status
;;
add_env)
AMPLIFY="{\
\"envName\":\"$6\"\
}"
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":false,\
\"accessKeyId\":\"$AWS_ACCESS_KEY_ID\",\
\"secretAccessKey\":\"$AWS_SECRET_ACCESS_KEY\",\
\"region\":\"$AWS_REGION\"\
}"
PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"
amplify env add $9 --amplify "$AMPLIFY" --providers "$PROVIDERS" --yes
amplify status
;;
delete_env)
# ACCIDENTAL DELETION PROTECTION #0: delete_lock
if [ "$7" = true ] ; then
echo "ACCIDENTAL DELETION PROTECTION: You must unset delete_lock input parameter for delete to work"
exit 1
fi
# ACCIDENTAL DELETION PROTECTION #1: environment to be deleted cannot contain prod/release/master in its name
if [[ ${6,,} =~ prod|release|master ]] ; then
echo "ACCIDENTAL DELETION PROTECTION: delete command is unsupported for environments that contain prod/release/master in its name"
exit 1
fi
# fill in dummy env in local-env-info so we delete current environment
# without switch to another one (amplify restriction)
echo '{"projectPath": "'"$(pwd)"'","defaultEditor":"code","envName":"dummyenvfordeletecurrentowork"}' > ./amplify/.config/local-env-info.json
echo "Y" | amplify env remove "$6" $9
;;
*)
echo "amplify command $5 is invalid or not supported"
exit 1
;;
esac