@@ -7,6 +7,96 @@ GREEN='\033[0;32m'
7
7
ORANGE=' \033[0;33m'
8
8
BLUE=' \033[0;34m'
9
9
10
+ # Functions
11
+ function getArchiveETag() {
12
+ aws s3api head-object \
13
+ --bucket " $INPUT_S3_BUCKET " \
14
+ --key " $INPUT_S3_FOLDER " /" $ZIP_FILENAME " \
15
+ --query ETag --output text
16
+ }
17
+
18
+ function deployRevision() {
19
+ aws deploy create-deployment " $@ " \
20
+ --application-name " $INPUT_CODEDEPLOY_NAME " \
21
+ --deployment-group-name " $INPUT_CODEDEPLOY_GROUP " \
22
+ --description " $GITHUB_REF - $GITHUB_SHA " \
23
+ --s3-location bucket=" $INPUT_S3_BUCKET " ,bundleType=" $BUNDLE_TYPE " ,eTag=" $ZIP_ETAG " ,key=" $INPUT_S3_FOLDER " /" $ZIP_FILENAME " | jq -r ' .deploymentId'
24
+ }
25
+
26
+ function registerRevision() {
27
+ aws deploy register-application-revision \
28
+ --application-name " $INPUT_CODEDEPLOY_NAME " \
29
+ --description " $GITHUB_REF - $GITHUB_SHA " \
30
+ --s3-location bucket=" $INPUT_S3_BUCKET " ,bundleType=" $BUNDLE_TYPE " ,eTag=" $ZIP_ETAG " ,key=" $INPUT_S3_FOLDER " /" $ZIP_FILENAME " > /dev/null 2>&1
31
+ }
32
+
33
+ function getActiveDeployments() {
34
+ if ! aws deploy list-deployments \
35
+ --application-name " $INPUT_CODEDEPLOY_NAME " \
36
+ --deployment-group-name " $INPUT_CODEDEPLOY_GROUP " \
37
+ --include-only-statuses " Queued" " InProgress" | jq -r ' .deployments' ; then
38
+ echo -e " ${ORANGE} Deployment may still be executing."
39
+ echo -e " ${RED} Failed monitoring deployment (ListDeployments API call failed)."
40
+ exit 1;
41
+ fi
42
+ }
43
+
44
+ function getSpecificDeployment() {
45
+ aws deploy get-deployment \
46
+ --deployment-id " $1 " ;
47
+ }
48
+
49
+ function pollForSpecificDeployment() {
50
+ deadlockCounter=0;
51
+
52
+ while true ; do
53
+ RESPONSE=$( getSpecificDeployment " $1 " )
54
+ FAILED_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.Failed' )
55
+ IN_PROGRESS_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.InProgress' )
56
+ SKIPPED_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.Skipped' )
57
+ SUCCESS_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.Succeeded' )
58
+ PENDING_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.Pending' )
59
+ STATUS=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.status' )
60
+
61
+ echo -e " ${ORANGE} Deployment in progress. Sleeping 15 seconds. (Try $(( ++ deadlockCounter)) )" ;
62
+ echo -e " Instance Overview: ${RED} Failed ($FAILED_COUNT ), ${BLUE} In-Progress ($IN_PROGRESS_COUNT ), ${RESET_TEXT} Skipped ($SKIPPED_COUNT ), ${BLUE} Pending ($PENDING_COUNT ), ${GREEN} Succeeded ($SUCCESS_COUNT )"
63
+ echo -e " Deployment Status: $STATUS "
64
+
65
+ if [ " $FAILED_COUNT " -gt 0 ]; then
66
+ echo -e " ${RED} Failed instance detected (Failed count over zero)."
67
+ exit 1;
68
+ fi
69
+
70
+ if [ " $STATUS " = " Failed" ]; then
71
+ echo -e " ${RED} Failed deployment detected (Failed status)."
72
+ exit 1;
73
+ fi
74
+
75
+ if [ " $STATUS " = " Succeeded" ]; then
76
+ break ;
77
+ fi
78
+
79
+ if [ " $deadlockCounter " -gt " $INPUT_MAX_POLLING_ITERATIONS " ]; then
80
+ echo -e " ${RED} Max polling iterations reached (max_polling_iterations)."
81
+ exit 1;
82
+ fi
83
+ sleep 15s;
84
+ done ;
85
+ }
86
+
87
+ function pollForActiveDeployments() {
88
+ deadlockCounter=0;
89
+ while [ " $( getActiveDeployments) " != " []" ]; do
90
+ echo -e " ${ORANGE} Deployment in progress. Sleeping 15 seconds. (Try $(( ++ deadlockCounter)) )" ;
91
+
92
+ if [ " $deadlockCounter " -gt " $INPUT_MAX_POLLING_ITERATIONS " ]; then
93
+ echo -e " ${RED} Max polling iterations reached (max_polling_iterations)."
94
+ exit 1;
95
+ fi
96
+ sleep 15s;
97
+ done ;
98
+ }
99
+
10
100
# 0) Validation
11
101
if [ -z " $INPUT_CODEDEPLOY_NAME " ] && [ -z " $INPUT_DRY_RUN " ]; then
12
102
echo " ::error::codedeploy_name is required and must not be empty."
@@ -114,13 +204,6 @@ echo "::debug::Zip Archived validated."
114
204
echo " zip_filename=$ZIP_FILENAME " >> " $GITHUB_OUTPUT "
115
205
116
206
# 3) Upload the deployment to S3, drop old archive.
117
- function getArchiveETag() {
118
- aws s3api head-object \
119
- --bucket " $INPUT_S3_BUCKET " \
120
- --key " $INPUT_S3_FOLDER " /" $ZIP_FILENAME " \
121
- --query ETag --output text
122
- }
123
-
124
207
if " $INPUT_DRY_RUN " ; then
125
208
echo " ::debug::Dry Run detected. Exiting."
126
209
exit 0;
@@ -140,90 +223,9 @@ rm "$ZIP_FILENAME"
140
223
echo " ::debug::Removed old local ZIP Archive."
141
224
142
225
# 4) Start the CodeDeploy
143
- function getActiveDeployments() {
144
- if ! aws deploy list-deployments \
145
- --application-name " $INPUT_CODEDEPLOY_NAME " \
146
- --deployment-group-name " $INPUT_CODEDEPLOY_GROUP " \
147
- --include-only-statuses " Queued" " InProgress" | jq -r ' .deployments' ; then
148
- echo -e " ${ORANGE} Deployment may still be executing."
149
- echo -e " ${RED} Failed monitoring deployment (ListDeployments API call failed)."
150
- exit 1;
151
- fi
152
- }
153
-
154
- function getSpecificDeployment() {
155
- aws deploy get-deployment \
156
- --deployment-id " $1 " ;
157
- }
158
-
159
- function pollForSpecificDeployment() {
160
- deadlockCounter=0;
161
-
162
- while true ; do
163
- RESPONSE=$( getSpecificDeployment " $1 " )
164
- FAILED_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.Failed' )
165
- IN_PROGRESS_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.InProgress' )
166
- SKIPPED_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.Skipped' )
167
- SUCCESS_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.Succeeded' )
168
- PENDING_COUNT=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.deploymentOverview.Pending' )
169
- STATUS=$( echo " $RESPONSE " | jq -r ' .deploymentInfo.status' )
170
-
171
- echo -e " ${ORANGE} Deployment in progress. Sleeping 15 seconds. (Try $(( ++ deadlockCounter)) )" ;
172
- echo -e " Instance Overview: ${RED} Failed ($FAILED_COUNT ), ${BLUE} In-Progress ($IN_PROGRESS_COUNT ), ${RESET_TEXT} Skipped ($SKIPPED_COUNT ), ${BLUE} Pending ($PENDING_COUNT ), ${GREEN} Succeeded ($SUCCESS_COUNT )"
173
- echo -e " Deployment Status: $STATUS "
174
-
175
- if [ " $FAILED_COUNT " -gt 0 ]; then
176
- echo -e " ${RED} Failed instance detected (Failed count over zero)."
177
- exit 1;
178
- fi
179
-
180
- if [ " $STATUS " = " Failed" ]; then
181
- echo -e " ${RED} Failed deployment detected (Failed status)."
182
- exit 1;
183
- fi
184
-
185
- if [ " $STATUS " = " Succeeded" ]; then
186
- break ;
187
- fi
188
-
189
- if [ " $deadlockCounter " -gt " $INPUT_MAX_POLLING_ITERATIONS " ]; then
190
- echo -e " ${RED} Max polling iterations reached (max_polling_iterations)."
191
- exit 1;
192
- fi
193
- sleep 15s;
194
- done ;
195
- }
196
-
197
- function pollForActiveDeployments() {
198
- deadlockCounter=0;
199
- while [ " $( getActiveDeployments) " != " []" ]; do
200
- echo -e " ${ORANGE} Deployment in progress. Sleeping 15 seconds. (Try $(( ++ deadlockCounter)) )" ;
201
-
202
- if [ " $deadlockCounter " -gt " $INPUT_MAX_POLLING_ITERATIONS " ]; then
203
- echo -e " ${RED} Max polling iterations reached (max_polling_iterations)."
204
- exit 1;
205
- fi
206
- sleep 15s;
207
- done ;
208
- }
209
226
pollForActiveDeployments
210
227
211
228
# 5) Poll / Complete
212
- function deployRevision() {
213
- aws deploy create-deployment " $@ " \
214
- --application-name " $INPUT_CODEDEPLOY_NAME " \
215
- --deployment-group-name " $INPUT_CODEDEPLOY_GROUP " \
216
- --description " $GITHUB_REF - $GITHUB_SHA " \
217
- --s3-location bucket=" $INPUT_S3_BUCKET " ,bundleType=" $BUNDLE_TYPE " ,eTag=" $ZIP_ETAG " ,key=" $INPUT_S3_FOLDER " /" $ZIP_FILENAME " | jq -r ' .deploymentId'
218
- }
219
-
220
- function registerRevision() {
221
- aws deploy register-application-revision \
222
- --application-name " $INPUT_CODEDEPLOY_NAME " \
223
- --description " $GITHUB_REF - $GITHUB_SHA " \
224
- --s3-location bucket=" $INPUT_S3_BUCKET " ,bundleType=" $BUNDLE_TYPE " ,eTag=" $ZIP_ETAG " ,key=" $INPUT_S3_FOLDER " /" $ZIP_FILENAME " > /dev/null 2>&1
225
- }
226
-
227
229
if $INPUT_CODEDEPLOY_REGISTER_ONLY ; then
228
230
echo -e " ${BLUE} Registering deployment to ${RESET_TEXT} $INPUT_CODEDEPLOY_GROUP ." ;
229
231
registerRevision
0 commit comments