-
Notifications
You must be signed in to change notification settings - Fork 0
260 lines (230 loc) · 10.3 KB
/
ci-cd.yml
File metadata and controls
260 lines (230 loc) · 10.3 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
---
name: CI/CD Pipeline
"on":
push:
branches: [master, develop]
workflow_dispatch:
inputs:
deploy_infrastructure:
description: 'Deploy infrastructure to dev'
required: false
default: true
type: boolean
cleanup_after_test:
description: 'Cleanup dev resources after deployment test'
required: false
default: false
type: boolean
permissions:
contents: read
deployments: write
statuses: write
env:
DOTNET_VERSION: '10.0.x'
AZURE_RESOURCE_GROUP_DEV: 'meajudaai-dev'
AZURE_LOCATION: 'brazilsouth'
jobs:
# Job 1: Build and Test
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:16-3.4
env:
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD || 'test123' }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER || 'postgres' }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB || 'meajudaai_test' }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 🔧 Restore dependencies
run: dotnet restore MeAjudaAi.sln --force-evaluate --locked-mode
- name: Build solution
run: dotnet build MeAjudaAi.sln --configuration Release --no-restore
- name: Setup PostgreSQL connection
id: db
uses: ./.github/actions/setup-postgres-connection
with:
postgres-host: localhost
postgres-port: 5432
postgres-db: ${{ secrets.POSTGRES_DB || 'meajudaai_test' }}
postgres-user: ${{ secrets.POSTGRES_USER || 'postgres' }}
postgres-password: ${{ secrets.POSTGRES_PASSWORD || 'test123' }}
- name: Run tests
env:
ASPNETCORE_ENVIRONMENT: Testing
# Map connection strings to .NET configuration using double underscore
ConnectionStrings__DefaultConnection: ${{ steps.db.outputs.connection-string }}
ConnectionStrings__Users: ${{ steps.db.outputs.connection-string }}
ConnectionStrings__Search: ${{ steps.db.outputs.connection-string }}
ConnectionStrings__meajudaai-db: ${{ steps.db.outputs.connection-string }}
run: |
echo "🧪 Executando todos os testes..."
# Executar testes unitários e de arquitetura
dotnet test tests/MeAjudaAi.Shared.Tests/MeAjudaAi.Shared.Tests.csproj \
--configuration Release --no-build --verbosity normal \
--collect:"XPlat Code Coverage" --results-directory TestResults/Shared
dotnet test tests/MeAjudaAi.Architecture.Tests/MeAjudaAi.Architecture.Tests.csproj \
--configuration Release --no-build --verbosity normal \
--collect:"XPlat Code Coverage" --results-directory TestResults/Architecture
# Executar testes de integração
dotnet test tests/MeAjudaAi.Integration.Tests/MeAjudaAi.Integration.Tests.csproj \
--configuration Release --no-build --verbosity normal \
--collect:"XPlat Code Coverage" --results-directory TestResults/Integration
# Executar testes de módulos
echo "🧪 Executando testes de módulos..."
dotnet test src/Modules/Users/Tests/MeAjudaAi.Modules.Users.Tests.csproj \
--configuration Release --no-build --verbosity normal \
--collect:"XPlat Code Coverage" --results-directory TestResults/Users
dotnet test src/Modules/Documents/Tests/MeAjudaAi.Modules.Documents.Tests.csproj \
--configuration Release --no-build --verbosity normal \
--collect:"XPlat Code Coverage" --results-directory TestResults/Documents
dotnet test src/Modules/Providers/Tests/MeAjudaAi.Modules.Providers.Tests.csproj \
--configuration Release --no-build --verbosity normal \
--collect:"XPlat Code Coverage" --results-directory TestResults/Providers
dotnet test src/Modules/ServiceCatalogs/Tests/MeAjudaAi.Modules.ServiceCatalogs.Tests.csproj \
--configuration Release --no-build --verbosity normal \
--collect:"XPlat Code Coverage" --results-directory TestResults/ServiceCatalogs
# Executar testes E2E
echo "🔍 Executando testes E2E..."
dotnet test tests/MeAjudaAi.E2E.Tests/MeAjudaAi.E2E.Tests.csproj \
--configuration Release --no-build --verbosity normal \
--collect:"XPlat Code Coverage" --results-directory TestResults/E2E
echo "✅ Todos os testes executados com sucesso"
- name: Install ReportGenerator
run: dotnet tool install -g dotnet-reportgenerator-globaltool
- name: Generate Code Coverage Report
run: |
reportgenerator \
-reports:"TestResults/**/coverage.cobertura.xml" \
-targetdir:"TestResults/Coverage" \
-reporttypes:"Html;Cobertura;JsonSummary" \
-assemblyfilters:"-*.Tests*" \
-classfilters:"-*.Migrations*"
- name: Upload code coverage
uses: actions/upload-artifact@v4
if: always()
with:
name: code-coverage
path: "TestResults/Coverage/**/*"
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: "**/TestResults/**/*"
# Job 2: Markdown Link Validation
markdown-link-check:
name: Validate Markdown Links
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check markdown links with lychee
uses: lycheeverse/lychee-action@v1.10.0
with:
# Check all markdown files in the repository using config file
args: --config config/lychee.toml --verbose --no-progress "**/*.md"
# Fail the job if broken links are found
fail: true
# Generate job summary
jobSummary: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Job 3: Infrastructure Validation (Optional)
validate-infrastructure:
name: Validate Infrastructure
runs-on: ubuntu-latest
needs: build-and-test
if: false # Disabled until Azure credentials are configured
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Azure
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Validate Bicep templates
run: |
az bicep build --file infrastructure/main.bicep
# Validate Bicep only if the resource group exists
if az group exists --name ${{ env.AZURE_RESOURCE_GROUP_DEV }} --output tsv | grep true; then
az deployment group validate \
--resource-group ${{ env.AZURE_RESOURCE_GROUP_DEV }} \
--template-file infrastructure/main.bicep \
--parameters environmentName=dev location=${{ env.AZURE_LOCATION }}
else
echo "Resource group '${{ env.AZURE_RESOURCE_GROUP_DEV }}' does not exist, skipping Bicep validation"
fi
# Job 4: Deploy to Development (Optional)
deploy-dev:
name: Deploy to Development
runs-on: ubuntu-latest
needs: [build-and-test, validate-infrastructure]
if: false # Disabled until Azure credentials and environment are configured
# environment: development
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Azure
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Create Resource Group
if: github.event.inputs.deploy_infrastructure == 'true' || github.event.inputs.deploy_infrastructure == ''
run: |
az group create \
--name ${{ env.AZURE_RESOURCE_GROUP_DEV }} \
--location ${{ env.AZURE_LOCATION }}
- name: Deploy Infrastructure
if: github.event.inputs.deploy_infrastructure == 'true' || github.event.inputs.deploy_infrastructure == ''
run: |
DEPLOYMENT_NAME="meajudaai-dev-$(date +%s)"
az deployment group create \
--name "$DEPLOYMENT_NAME" \
--resource-group ${{ env.AZURE_RESOURCE_GROUP_DEV }} \
--template-file infrastructure/main.bicep \
--parameters environmentName=dev location=${{ env.AZURE_LOCATION }}
# Export infrastructure outputs for reference
az deployment group show \
--name "$DEPLOYMENT_NAME" \
--resource-group ${{ env.AZURE_RESOURCE_GROUP_DEV }} \
--query "properties.outputs" > infrastructure-outputs.json
echo "Infrastructure outputs:"
cat infrastructure-outputs.json
# Get connection string for development use
SERVICE_BUS_NAMESPACE=$(jq -r '.serviceBusNamespace.value' infrastructure-outputs.json)
MANAGEMENT_POLICY_NAME=$(jq -r '.managementPolicyName.value' infrastructure-outputs.json)
CONNECTION_STRING=$(az servicebus namespace authorization-rule keys list \
--resource-group ${{ env.AZURE_RESOURCE_GROUP_DEV }} \
--namespace-name "$SERVICE_BUS_NAMESPACE" \
--name "$MANAGEMENT_POLICY_NAME" \
--query "primaryConnectionString" \
--output tsv)
echo "✅ Infrastructure deployed successfully!"
echo "🔗 Service Bus Namespace: $SERVICE_BUS_NAMESPACE"
echo "💡 To use locally, set: export Messaging__ServiceBus__ConnectionString='[CONNECTION_STRING]'"
- name: Upload infrastructure outputs
if: github.event.inputs.deploy_infrastructure == 'true' || github.event.inputs.deploy_infrastructure == ''
uses: actions/upload-artifact@v4
with:
name: infrastructure-outputs-dev
path: infrastructure-outputs.json
- name: Cleanup after test (if requested)
if: github.event.inputs.cleanup_after_test == 'true'
run: |
echo "🧹 Cleaning up dev resources as requested..."
az group delete --name ${{ env.AZURE_RESOURCE_GROUP_DEV }} --yes --no-wait
echo "✅ Cleanup initiated (resources will be deleted in a few minutes)"