From 4d2ab6f32e54dea6cfd00f84e509d37c0b405734 Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Thu, 14 May 2026 18:34:46 -0400 Subject: [PATCH] Add post-deploy health checks to CD workflows Verifies stack status after deploy, prints outputs, and runs project-specific scripts/health-check.sh if present. --- .github/workflows/cd-cdk.yaml | 27 +++++++++++++++++++++++++++ .github/workflows/cd-sam.yaml | 26 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/.github/workflows/cd-cdk.yaml b/.github/workflows/cd-cdk.yaml index 65e473b..2aed4c6 100644 --- a/.github/workflows/cd-cdk.yaml +++ b/.github/workflows/cd-cdk.yaml @@ -98,3 +98,30 @@ jobs: - name: CDK deploy working-directory: ${{ inputs.cdk-dir }} run: npx -y cdk deploy --all --require-approval never + + - name: Post-deploy health check + if: ${{ inputs.stack-name != '' }} + run: | + echo "Health check: verifying stack ${{ inputs.stack-name }}..." + + STATUS=$(aws cloudformation describe-stacks \ + --stack-name "${{ inputs.stack-name }}" \ + --query 'Stacks[0].StackStatus' --output text) + if [[ "$STATUS" != *"COMPLETE" ]] || [[ "$STATUS" == *"ROLLBACK"* ]]; then + echo "::error::Stack ${{ inputs.stack-name }} ended in $STATUS after deploy." + exit 1 + fi + echo "Stack status: $STATUS" + + echo "Stack outputs:" + aws cloudformation describe-stacks \ + --stack-name "${{ inputs.stack-name }}" \ + --query 'Stacks[0].Outputs[*].[OutputKey,OutputValue]' --output table + + # Run project-specific health check if it exists + if [[ -f scripts/health-check.sh ]]; then + echo "Running project health check..." + bash scripts/health-check.sh "${{ inputs.stack-name }}" "${{ inputs.region }}" + fi + + echo "Health check passed." diff --git a/.github/workflows/cd-sam.yaml b/.github/workflows/cd-sam.yaml index 713df93..0d8f69f 100644 --- a/.github/workflows/cd-sam.yaml +++ b/.github/workflows/cd-sam.yaml @@ -94,3 +94,29 @@ jobs: --no-fail-on-empty-changeset \ --role-arn ${{ inputs.cfn-role-arn }} \ $PARAMS + + - name: Post-deploy health check + run: | + echo "Health check: verifying stack ${{ inputs.stack-name }}..." + + STATUS=$(aws cloudformation describe-stacks \ + --stack-name "${{ inputs.stack-name }}" \ + --query 'Stacks[0].StackStatus' --output text) + if [[ "$STATUS" != *"COMPLETE" ]] || [[ "$STATUS" == *"ROLLBACK"* ]]; then + echo "::error::Stack ${{ inputs.stack-name }} ended in $STATUS after deploy." + exit 1 + fi + echo "Stack status: $STATUS" + + echo "Stack outputs:" + aws cloudformation describe-stacks \ + --stack-name "${{ inputs.stack-name }}" \ + --query 'Stacks[0].Outputs[*].[OutputKey,OutputValue]' --output table + + # Run project-specific health check if it exists + if [[ -f scripts/health-check.sh ]]; then + echo "Running project health check..." + bash scripts/health-check.sh "${{ inputs.stack-name }}" "${{ inputs.region }}" + fi + + echo "Health check passed."