-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathpost-deployment-health-check.yml
More file actions
170 lines (149 loc) Β· 6.04 KB
/
Copy pathpost-deployment-health-check.yml
File metadata and controls
170 lines (149 loc) Β· 6.04 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Post-Deployment Health Check
on:
workflow_run:
workflows:
- "Build and deploy"
- "Build and deploy testing"
types:
- completed
workflow_dispatch:
inputs:
target_url:
description: 'Target URL to health check'
required: true
type: choice
options:
- https://www.pulumi.com
- https://www.pulumi-test.io
default: 'https://www.pulumi.com'
environment:
description: 'Environment name (for Slack notifications)'
required: true
type: choice
options:
- production
- testing
default: 'production'
permissions:
contents: read
env:
ESC_ACTION_OIDC_AUTH: true
ESC_ACTION_OIDC_ORGANIZATION: pulumi
ESC_ACTION_OIDC_REQUESTED_TOKEN_TYPE: urn:pulumi:token-type:access_token:organization
ESC_ACTION_ENVIRONMENT: github-secrets/pulumi-docs
ESC_ACTION_EXPORT_ENVIRONMENT_VARIABLES: false
jobs:
health-check:
name: Run post-deployment health checks
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
outputs:
url: ${{ steps.target.outputs.url }}
environment: ${{ steps.target.outputs.environment }}
slack_channel: ${{ steps.target.outputs.slack_channel }}
steps:
- name: Determine target environment
id: target
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "url=${{ inputs.target_url }}" >> $GITHUB_OUTPUT
echo "environment=${{ inputs.environment }}" >> $GITHUB_OUTPUT
if [[ "${{ inputs.environment }}" == "production" ]]; then
echo "slack_channel=docs-ops" >> $GITHUB_OUTPUT
else
echo "slack_channel=docs-ops-test" >> $GITHUB_OUTPUT
fi
elif [[ "${{ github.event.workflow_run.name }}" == "Build and deploy" ]]; then
echo "url=https://www.pulumi.com" >> $GITHUB_OUTPUT
echo "environment=production" >> $GITHUB_OUTPUT
echo "slack_channel=docs-ops" >> $GITHUB_OUTPUT
else
echo "url=https://www.pulumi-test.io" >> $GITHUB_OUTPUT
echo "environment=testing" >> $GITHUB_OUTPUT
echo "slack_channel=docs-ops-test" >> $GITHUB_OUTPUT
fi
- name: Run health checks
run: |
#!/bin/bash
set -e
BASE_URL="${{ steps.target.outputs.url }}"
FAILED=0
echo "π₯ Post-Deployment Health Check"
echo "Target: $BASE_URL"
echo ""
# Function to check endpoint returns 200
check_endpoint() {
local path="$1"
local name="$2"
local url="${BASE_URL}${path}"
status=$(curl -s -o /dev/null -w "%{http_code}" -L "$url")
if [[ "$status" == "200" ]]; then
echo "β
$name: $status"
else
echo "β $name: Expected 200, got $status"
FAILED=1
fi
}
# Function to check redirect
check_redirect() {
local path="$1"
local expected_location="$2"
local name="$3"
local url="${BASE_URL}${path}"
# Get status and location without following redirects
response=$(curl -s -o /dev/null -w "%{http_code}|%{redirect_url}" "$url")
status="${response%%|*}"
location="${response##*|}"
if [[ "$status" == "301" ]] && [[ "$location" =~ $expected_location ]]; then
echo "β
$name: $status β $location"
else
echo "β $name: Expected 301 to match '$expected_location', got $status β $location"
FAILED=1
fi
}
echo "Testing endpoints..."
check_endpoint "/" "Homepage"
check_endpoint "/docs" "Docs landing"
check_endpoint "/registry" "Registry landing"
check_endpoint "/docs/reference/pkg/nodejs/pulumi/pulumi/" "Node.js SDK"
check_endpoint "/docs/reference/pkg/python/pulumi/" "Python SDK"
check_endpoint "/docs/reference/pkg/dotnet/pulumi/pulumi.html" ".NET SDK"
check_endpoint "/docs/reference/pkg/java/" "Java SDK"
check_endpoint "/docs/iac/get-started/" "Getting started"
check_endpoint "/docs/cli/commands/" "CLI reference"
echo ""
echo "Testing Lambda@Edge redirects..."
check_redirect "/docs/intro/cloud-providers/aws/" "/registry/packages/aws/" "Cloud provider redirect"
check_redirect "/docs/reference/pkg/nodejs/pulumi/aws/" "/docs/reference/pkg/aws/\\?language=nodejs" "Node.js SDK redirect"
echo ""
echo "=================================================="
if [[ $FAILED -eq 0 ]]; then
echo "β
All health checks passed!"
exit 0
else
echo "β Some health checks failed!"
exit 1
fi
notify:
name: Send Slack notification on failure
runs-on: ubuntu-latest
needs: [health-check]
if: failure()
steps:
- name: Fetch secrets from ESC
id: esc-secrets
uses: pulumi/esc-action@v3
- name: Send Slack notification
uses: docker://sholung/action-slack-notify:v2.3.0
env:
SLACK_CHANNEL: ${{ needs.health-check.outputs.slack_channel || 'docs-ops' }}
SLACK_COLOR: "#F54242"
SLACK_MESSAGE: |
π¨ Post-deployment health check failed for ${{ needs.health-check.outputs.environment || 'production' }}
Workflow: ${{ github.event.workflow_run.html_url }}
Deployment: ${{ github.event.workflow_run.name }}
Commit: ${{ github.event.workflow_run.head_sha }}
Check the workflow logs for details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SLACK_USERNAME: docsbot
SLACK_WEBHOOK: ${{ steps.esc-secrets.outputs.SLACK_WEBHOOK_URL }}
SLACK_ICON: https://www.pulumi.com/logos/brand/avatar-on-white.png