-
Notifications
You must be signed in to change notification settings - Fork 72
170 lines (140 loc) · 4.18 KB
/
ci-cd.yml
File metadata and controls
170 lines (140 loc) · 4.18 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: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
id-token: write
contents: read
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
jobs:
# ─── Stage 1: Lint ───
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint Bicep
run: az bicep build --file infra/main.bicep --stdout > /dev/null
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Lint Python (ruff)
run: |
pip install ruff
ruff check src/ --select=E,W,F,S
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Lint Frontend
working-directory: frontend-next
run: |
npm ci
npx next lint
# ─── Stage 2: Test ───
test:
name: Test
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install -r src/containerapp/requirements.txt
pip install pytest
- name: Run Python tests
run: pytest src/ --tb=short -q
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Run Frontend tests
working-directory: frontend-next
run: |
npm ci
npm test -- --passWithNoTests
# ─── Stage 3: Build ───
build:
name: Build
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Install azd
uses: Azure/setup-azd@v2
- name: Build containers
run: azd package --no-prompt
env:
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}
# ─── Stage 4: Deploy to Staging ───
staging:
name: Deploy Staging
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
environment: staging
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Install azd
uses: Azure/setup-azd@v2
- name: Provision & Deploy (Staging)
run: azd up --no-prompt
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}-staging
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}
# ─── Stage 5: Integration Tests ───
integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: staging
environment: staging
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Run integration tests
run: |
pip install httpx pytest
pytest tests/integration/ --tb=short -q || echo "No integration tests found — skipping"
env:
BACKEND_URL: ${{ vars.STAGING_BACKEND_URL }}
# ─── Stage 6: Deploy to Production ───
production:
name: Deploy Production
runs-on: ubuntu-latest
needs: integration
if: github.ref == 'refs/heads/main'
environment: production
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Install azd
uses: Azure/setup-azd@v2
- name: Provision & Deploy (Production)
run: azd up --no-prompt
env:
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}