8080 ref : ${{ inputs.git_ref_to_deploy || github.sha }}
8181 - name : Get git sha
8282 id : get-git-sha
83- run : echo "git-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
83+ run : echo "git-sha=$(git rev-parse HEAD)" >> " $GITHUB_OUTPUT"
8484 build-and-push-images :
8585 permissions :
8686 id-token : write
@@ -117,11 +117,11 @@ jobs:
117117 image_tag : ${{ needs.determine-git-sha.outputs.git-sha }}
118118 run : |
119119 digest=$(aws ecr describe-images \
120- --repository-name $repository_name \
121- --image-ids imageTag=$image_tag \
120+ --repository-name " $repository_name" \
121+ --image-ids " imageTag=$image_tag" \
122122 --query 'imageDetails[0].imageDigest' \
123123 --output text)
124- echo "digest=$digest" >> $GITHUB_OUTPUT
124+ echo "digest=$digest" >> " $GITHUB_OUTPUT"
125125 - name : Populate task definition
126126 id : create-task-definition
127127 uses : aws-actions/amazon-ecs-render-task-definition@v1
@@ -195,29 +195,29 @@ jobs:
195195 run : |
196196 family_name="mavis-migration-task-definition-$environment"
197197 file_path="${{ runner.temp }}/migration-task-definition.json"
198- echo "$( jq --arg f "$family_name" '.family = $f' "${{ runner.temp }}/ops-task-definition.json") " > "$file_path"
198+ jq --arg f "$family_name" '.family = $f' "${{ runner.temp }}/ops-task-definition.json" > "$file_path"
199199 task_definition_arn=$(aws ecs register-task-definition \
200200 --cli-input-json file://$file_path \
201201 --query 'taskDefinition.taskDefinitionArn' \
202202 --output text
203203 )
204- echo "task_definition_arn=$task_definition_arn" >> $GITHUB_OUTPUT
204+ echo "task_definition_arn=$task_definition_arn" >> " $GITHUB_OUTPUT"
205205 - name : Run schema migrations
206206 id : run-schema-migrations
207207 env :
208208 SLACK_MAVIS_RELEASES_WEBHOOK_URL : ${{ secrets.SLACK_MAVIS_RELEASES_WEBHOOK_URL }}
209209 run : |
210210 TASK_DEFINITION_ARN=${{ steps.register-migration-task-definition.outputs.task_definition_arn }}
211- SUBNET_ID=$(aws ec2 describe-subnets --filters Name=tag:Name,Values=private-subnet-$environment-a --query 'Subnets[0].SubnetId' --output text)
212- SECURITY_GROUP_ID=$(aws ec2 describe-security-groups --filters Name=group-name,Values=ops-service-$environment --query 'SecurityGroups[0].GroupId' --output text)
213-
211+ SUBNET_ID=$(aws ec2 describe-subnets --filters " Name=tag:Name,Values=private-subnet-$environment-a" --query 'Subnets[0].SubnetId' --output text)
212+ SECURITY_GROUP_ID=$(aws ec2 describe-security-groups --filters " Name=group-name,Values=ops-service-$environment" --query 'SecurityGroups[0].GroupId' --output text)
213+
214214 MAX_ATTEMPTS=3
215215 ATTEMPT=1
216216
217217 while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
218218 TASK_ARN=$(aws ecs run-task \
219- --cluster $cluster_name \
220- --task-definition $TASK_DEFINITION_ARN \
219+ --cluster " $cluster_name" \
220+ --task-definition " $TASK_DEFINITION_ARN" \
221221 --launch-type FARGATE \
222222 --network-configuration "awsvpcConfiguration={subnets=[$SUBNET_ID],securityGroups=[$SECURITY_GROUP_ID]}" \
223223 --overrides '{
@@ -228,49 +228,51 @@ jobs:
228228 }' \
229229 --query 'tasks[0].taskArn' \
230230 --output text)
231-
231+
232232 echo "Waiting for task to complete: $TASK_ARN"
233- TASK_ID=$(sed 's:^.*/::' <<< $TASK_ARN)
233+
234+ # shellcheck disable=SC2001
235+ TASK_ID=$(sed 's:^.*/::' <<< "$TASK_ARN")
234236 AWS_CONSOLE_URL="https://eu-west-2.console.aws.amazon.com/ecs/v2/clusters/$cluster_name/tasks/$TASK_ID/logs"
235-
237+
236238 echo "View logs in AWS Console: $AWS_CONSOLE_URL"
237- if [ $environment = 'production' ]; then
239+ if [ " $environment" = 'production' ]; then
238240 ./.github/send_slack_notification.sh "${{ secrets.SLACK_MAVIS_RELEASES_WEBHOOK_URL }}" "$AWS_CONSOLE_URL" "Running schema migrations attempt $ATTEMPT/$MAX_ATTEMPTS"
239241 fi
240242
241243 MAX_WAIT_TIME=3600
242244 POLL_INTERVAL=10 # Poll every 10 seconds
243245 ELAPSED=0
244246
245- while [ $ELAPSED -lt $MAX_WAIT_TIME ]; do
247+ while [ " $ELAPSED" -lt " $MAX_WAIT_TIME" ]; do
246248 TASK_STATUS=$(aws ecs describe-tasks \
247- --cluster $cluster_name \
248- --tasks $TASK_ID \
249+ --cluster " $cluster_name" \
250+ --tasks " $TASK_ID" \
249251 --query 'tasks[0].lastStatus' \
250252 --output text)
251-
253+
252254 if [ "$TASK_STATUS" = "STOPPED" ]; then
253255 echo "Task has stopped"
254256 break
255257 fi
256-
257- sleep $POLL_INTERVAL
258+
259+ sleep " $POLL_INTERVAL"
258260 ELAPSED=$((ELAPSED + POLL_INTERVAL))
259261 done
260262
261- if [ $ELAPSED -ge $MAX_WAIT_TIME ]; then
263+ if [ " $ELAPSED" -ge " $MAX_WAIT_TIME" ]; then
262264 echo "ERROR: Migration task did not complete within $MAX_WAIT_TIME seconds."
263265 exit 1
264266 fi
265-
267+
266268 EXIT_CODE=$(aws ecs describe-tasks \
267- --cluster $cluster_name \
268- --tasks $TASK_ARN \
269+ --cluster " $cluster_name" \
270+ --tasks " $TASK_ARN" \
269271 --query 'tasks[0].containers[0].exitCode' \
270272 --output text)
271-
273+
272274 echo "Container exit code: $EXIT_CODE"
273-
275+
274276 if [ "$EXIT_CODE" = "0" ]; then
275277 echo "Migrations completed"
276278 break
@@ -279,7 +281,7 @@ jobs:
279281 if [ "$ATTEMPT" = "$MAX_ATTEMPTS" ]; then
280282 exit 1
281283 fi
282- ATTEMPT=$((ATTEMPT+1))
284+ ATTEMPT=$((ATTEMPT+1))
283285 fi
284286 done
285287 - name : Notify migrations completed
@@ -294,7 +296,7 @@ jobs:
294296 - type: "section"
295297 text:
296298 type: "mrkdwn"
297- text: "Schema migrations finished successfully :white_check_mark:"
299+ text: "Schema migrations finished successfully :white_check_mark:"
298300 deploy-service :
299301 name : Deploy service
300302 runs-on : ubuntu-latest
@@ -321,7 +323,7 @@ jobs:
321323 run : |
322324 file_path="${{ runner.temp }}/${{ matrix.service }}-task-definition.json"
323325 family_name="mavis-${{ matrix.service }}-task-definition-$environment"
324- echo "$( jq --arg f "$family_name" '.family = $f' "$file_path")" > "$file_path"
326+ jq --arg f "$family_name" '.family = $f' "$file_path" > tmpfile && mv tmpfile "$file_path"
325327 - name : Deploy ${{ matrix.service }} service
326328 id : ecs-deploy
327329 uses : aws-actions/amazon-ecs-deploy-task-definition@v2
@@ -333,7 +335,7 @@ jobs:
333335 wait-for-service-stability : true
334336 - name : Check if deployment was successful
335337 run : |
336- current_task_definition_arn=$(aws ecs describe-services --cluster mavis-$environment --services mavis-$environment-${{ matrix.service }} --query services[0].deployments[0].taskDefinition | jq -r ".")
338+ current_task_definition_arn=$(aws ecs describe-services --cluster " mavis-$environment" --services " mavis-$environment-${{ matrix.service }}" --query services[0].deployments[0].taskDefinition | jq -r ".")
337339 new_task_definition_arn=${{ steps.ecs-deploy.outputs.task-definition-arn }}
338340 echo "Current task definition arn: $current_task_definition_arn"
339341 echo "Expected task definition arn after deployment: $new_task_definition_arn"
@@ -348,7 +350,7 @@ jobs:
348350 if : ${{ !cancelled() && inputs.environment == 'production' }}
349351 steps :
350352 - name : Notify deployment success
351- if : ${{ needs.deploy-service.result == 'success' }}
353+ if : ${{ needs.deploy-service.result == 'success' }}
352354 uses : slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a
353355 with :
354356 webhook : ${{ secrets.SLACK_MAVIS_RELEASES_WEBHOOK_URL }}
0 commit comments