-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (103 loc) · 4.12 KB
/
scheduled-health-check.yaml
File metadata and controls
115 lines (103 loc) · 4.12 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
name: Scheduled API Health Check (Template)
# This is a TEMPLATE workflow for scheduled health checks.
# Customize it to monitor your API endpoints.
on:
schedule:
# Run every 6 hours (customize as needed)
- cron: '0 */6 * * *'
workflow_dispatch:
inputs:
environment:
description: 'Environment to test'
required: true
default: 'production'
type: choice
options:
- development
- staging
- production
jobs:
health-check:
name: API Health Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Postman CLI
run: curl -o- "https://dl-cli.pstmn.io/install/unix.sh" | sh
- name: Authenticate with Postman
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
run: postman login --with-api-key "$POSTMAN_API_KEY"
- name: Determine environment
id: env
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "environment=${{ inputs.environment }}" >> $GITHUB_OUTPUT
else
echo "environment=production" >> $GITHUB_OUTPUT
fi
- name: Template notice
run: |
echo "⚠️ This is a TEMPLATE workflow for scheduled health checks."
echo ""
echo "To use this workflow:"
echo " 1. Create a health check collection in postman/collections/"
echo " 2. Uncomment and configure the 'Run health check' step below"
echo " 3. Set up environment files for each environment"
echo " 4. Configure POSTMAN_API_KEY secret in GitHub Settings"
echo ""
echo "Environment: ${{ steps.env.outputs.environment }}"
# TEMPLATE: Uncomment and customize for your project
# - name: Run health check collection
# id: health-check
# continue-on-error: true
# run: |
# echo "🏥 Running health check for ${{ steps.env.outputs.environment }}..."
#
# postman collection run \
# postman/collections/health-check.postman_collection.json \
# --environment postman/environments/${{ steps.env.outputs.environment }}.postman_environment.json \
# --reporter cli,json \
# --reporter-json-export health-check-results.json
# - name: Analyze results
# if: always()
# id: analyze
# run: |
# if [ -f health-check-results.json ]; then
# TOTAL=$(jq '.run.stats.tests.total // 0' health-check-results.json)
# PASSED=$(jq '.run.stats.tests.passed // 0' health-check-results.json)
# FAILED=$(jq '.run.stats.tests.failed // 0' health-check-results.json)
#
# echo "total=$TOTAL" >> $GITHUB_OUTPUT
# echo "passed=$PASSED" >> $GITHUB_OUTPUT
# echo "failed=$FAILED" >> $GITHUB_OUTPUT
#
# if [ "$FAILED" -gt 0 ]; then
# echo "health_status=unhealthy" >> $GITHUB_OUTPUT
# exit 1
# else
# echo "health_status=healthy" >> $GITHUB_OUTPUT
# fi
# fi
# - name: Create GitHub Issue on Failure
# if: failure()
# uses: actions/github-script@v6
# with:
# script: |
# const date = new Date().toISOString();
# const env = '${{ steps.env.outputs.environment }}';
#
# await github.rest.issues.create({
# owner: context.repo.owner,
# repo: context.repo.repo,
# title: `🚨 API Health Check Failed - ${env}`,
# body: `## API Health Check Failed\n\n**Environment:** ${env}\n**Time:** ${date}\n\nView workflow: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
# labels: ['bug', 'health-check', 'automated']
# });
- name: Success
run: |
echo "✅ Template workflow completed!"
echo ""
echo "📚 Customize this workflow to monitor your API health."
echo " See docs/CI_CD.md for complete examples."