-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (184 loc) · 5.19 KB
/
Copy pathci-cd.yml
File metadata and controls
194 lines (184 loc) · 5.19 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
paths-ignore:
- '**/*.md'
- '**/*.txt'
pull_request:
branches: [ main, develop ]
schedule:
- cron: '0 0 * * 0' # Run at midnight UTC every Sunday
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'test'
type: choice
options:
- test
- staging
env:
NODE_VERSION: '20.x'
TERRAFORM_VERSION: '1.5.7'
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
RESOURCE_GROUP: 'optima-core-${{ github.run_id }}'
LOCATION: 'eastus'
BUDGET_AMOUNT: 50 # USD
BUDGET_ALERT_EMAILS: 'devops@example.com'
defaults:
run:
shell: bash
working-directory: ./infrastructure
jobs:
lint:
name: Lint and Validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- run: npm ci
- run: npm run lint
- run: npm run typecheck
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- run: npm ci
- name: Generate documentation
run: npm run docs
- name: Validate documentation
run: npm run docs:validate
- name: Upload documentation artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: documentation
path: |
docs/**/*.md
!docs/node_modules/**/*.md
unit-test:
name: Unit Tests
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- run: npm ci
- run: npm test -- --coverage
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage/lcov.info
deploy-testbed:
name: Deploy Test Environment
needs: unit-test
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment || 'test' }}
env:
TF_VAR_environment: ${{ github.event.inputs.environment || 'test' }}
TF_VAR_github_sha: ${{ github.sha }}
TF_VAR_github_run_id: ${{ github.run_id }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- run: npm ci
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- run: az group create --name $RESOURCE_GROUP --location $LOCATION
- run: terraform init
- run: terraform validate
- run: terraform plan -out=tfplan
- run: terraform apply -auto-approve tfplan
- name: Setup budget alert
run: |
az consumption budget create \
--amount $BUDGET_AMOUNT \
--name "optima-core-budget" \
--category cost \
--time-grain monthly \
--start-date $(date +%Y-%m-01) \
--end-date 2099-12-31 \
--notifications '{
"Actual_GreaterThan_50_Percent": {
"enabled": true,
"operator": "GreaterThan",
"threshold": 50,
"contact_emails": ["'$BUDGET_ALERT_EMAILS'"]
}
}'
run-benchmark:
name: Run Performance Benchmark
needs: deploy-testbed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- run: npm ci
- name: Run benchmarks
run: |
API_URL=${{ needs.deploy-testbed.outputs.api_url }} \
npm run benchmark
- name: Upload benchmark results
uses: actions/upload-artifact@v3
with:
name: benchmark-results
path: results/benchmark-*.json
retention-days: 7
upload-results:
name: Upload Results
needs: run-benchmark
runs-on: ubuntu-latest
if: always()
steps:
- uses: actions/download-artifact@v3
with:
name: benchmark-results
path: results
- name: Process and upload results
run: |
node scripts/process-results.js
- name: Generate report
run: |
npm run generate-report
- uses: actions/upload-artifact@v3
with:
name: benchmark-report
path: results/report-*.html
retention-days: 30
teardown:
name: Teardown Resources
if: always()
needs: [deploy-testbed, upload-results]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Teardown resources
run: |
node scripts/teardown.js teardown
- name: Clean up old resources
run: |
node scripts/teardown.js cleanup