forked from platformplatform/PlatformPlatform
-
Notifications
You must be signed in to change notification settings - Fork 0
324 lines (282 loc) · 12.7 KB
/
back-office.yml
File metadata and controls
324 lines (282 loc) · 12.7 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
name: Back Office
on:
push:
branches:
- main
paths:
- "application/*"
- "application/shared-kernel/**"
- "application/shared-webapp/**"
- "application/back-office/**"
- ".github/workflows/back-office.yml"
- ".github/workflows/_deploy-container.yml"
- ".github/workflows/_migrate-database.yml"
- ".github/workflows/_preview-migrations.yml"
- "!**.md"
pull_request:
paths:
- "application/*"
- "application/shared-kernel/**"
- "application/shared-webapp/**"
- "application/back-office/**"
- ".github/workflows/back-office.yml"
- ".github/workflows/_deploy-container.yml"
- ".github/workflows/_migrate-database.yml"
- ".github/workflows/_preview-migrations.yml"
- "!**.md"
workflow_dispatch:
permissions:
id-token: write
contents: read
pull-requests: write
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.generate_version.outputs.version }}
deploy_staging: ${{ steps.determine_deployment.outputs.deploy_staging }}
deploy_production: ${{ steps.determine_deployment.outputs.deploy_production }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Generate Version
id: generate_version
run: |
# Strip leading 0s of Hours and Minutes after midnight
MINUTE=$(printf "%s" $(date +"%-H%M") | sed 's/^0*//')
VERSION=$(date +"%Y.%-m.%-d.")$MINUTE
echo "Generated version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Determine Deployment Conditions
id: determine_deployment
run: |
deploy_staging="${{ github.ref == 'refs/heads/main' && vars.STAGING_CLUSTER_ENABLED == 'true' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'Deploy to Staging')) }}"
echo "deploy_staging=$deploy_staging" >> $GITHUB_OUTPUT
deploy_production="${{ github.ref == 'refs/heads/main' && vars.PRODUCTION_CLUSTER1_ENABLED == 'true' }}"
echo "deploy_production=$deploy_production" >> $GITHUB_OUTPUT
- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Node Modules
working-directory: application
run: npm ci
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: application/global.json
- name: Restore .NET Tools
working-directory: application
run: dotnet tool restore
- name: Restore .NET Dependencies
working-directory: application
run: dotnet restore
- name: Generate and Set User Secret for Token Signing Key
working-directory: application/shared-kernel/SharedKernel
run: |
# Extract UserSecretsId from the .csproj file
USER_SECRETS_ID=$(grep -oP '(?<=<UserSecretsId>).*?(?=</UserSecretsId>)' SharedKernel.csproj)
# Generate a 512-bit key and set it as a user secret that can be use for token signing when running tests
dotnet user-secrets set "authentication-token-signing-key" "$(openssl rand -base64 64)" --id $USER_SECRETS_ID
- name: Setup Java JDK for SonarScanner
uses: actions/setup-java@v4
with:
distribution: "microsoft"
java-version: "17"
- name: Run Tests with dotCover and SonarScanner Reporting
working-directory: application
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
if [[ "${{ vars.SONAR_PROJECT_KEY }}" == "" ]]; then
echo "SonarCloud is not enabled. Skipping SonarCloud analysis."
dotnet build back-office/BackOffice.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} &&
dotnet dotcover test back-office/BackOffice.slnf --no-build --dcOutput=coverage/dotCover.html --dcReportType=HTML --dcFilters="+:PlatformPlatform.*;-:*.Tests;-:type=*.AppHost.*"
else
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths="coverage/dotCover.html" &&
dotnet build back-office/BackOffice.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} &&
dotnet dotcover test back-office/BackOffice.slnf --no-build --dcOutput=coverage/dotCover.html --dcReportType=HTML --dcFilters="+:PlatformPlatform.*;-:*.Tests;-:type=*.AppHost.*" &&
dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}"
fi
- name: Build Frontend Artifacts
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
working-directory: application
run: npm run build
- name: Publish Frontend Artifacts
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
working-directory: application/back-office/WebApp
run: npm run publish
- name: Publish API Build
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
working-directory: application/back-office
run: |
dotnet publish ./Api/BackOffice.Api.csproj --no-restore --configuration Release --output ./Api/publish /p:Version=${{ steps.generate_version.outputs.version }}
- name: Save API Artifacts
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
uses: actions/upload-artifact@v4
with:
name: back-office-api
path: application/back-office/Api/publish/**/*
- name: Publish Workers Build
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
working-directory: application/back-office
run: |
dotnet publish ./Workers/BackOffice.Workers.csproj --no-restore --configuration Release --output ./Workers/publish /p:Version=${{ steps.generate_version.outputs.version }}
- name: Save Workers Artifacts
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
uses: actions/upload-artifact@v4
with:
name: back-office-workers
path: application/back-office/Workers/publish/**/*
code-style-and-linting:
name: Code Style and Linting
if: github.event_name == 'pull_request'
runs-on: ubuntu-24.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Node Modules
working-directory: application
run: npm ci
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: application/global.json
- name: Restore .NET Tools
working-directory: application
run: dotnet tool restore
- name: Restore .NET Dependencies
working-directory: application
run: dotnet restore
- name: Build Backend Solution
working-directory: application
run: dotnet build back-office/BackOffice.slnf --no-restore
- name: Run Code Inspections
working-directory: developer-cli
run: |
dotnet run inspect --backend --solution-name BackOffice.slnf | tee inspection-output.log
if ! grep -q "No backend issues found!" inspection-output.log; then
echo "Code inspection issues found."
exit 1
fi
- name: Check for Code Formatting Issues
working-directory: developer-cli
run: |
dotnet run format --backend --solution-name BackOffice.slnf
# Check for any changes made by the code formatter
git diff --exit-code || {
echo "Formatting issues detected. Please run 'dotnet run format --backend --solution-name BackOffice.slnf' from /developer-cli folder locally and commit the formatted code."
exit 1
}
- name: Build Frontend Artifacts
working-directory: application
run: npm run build
- name: Run Check
working-directory: application/back-office/WebApp
run: npm run check
database-migrations-stage:
name: Database Staging
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}
needs: build-and-test
uses: ./.github/workflows/_migrate-database.yml
secrets: inherit
with:
azure_environment: "stage"
cluster_location_acronym: ${{ vars.STAGING_CLUSTER_LOCATION_ACRONYM }}
service_principal_id: ${{ vars.STAGING_SERVICE_PRINCIPAL_ID }}
subscription_id: ${{ vars.STAGING_SUBSCRIPTION_ID }}
database_name: back-office
relative_project_path: back-office/Core/BackOffice.csproj
relative_startup_project: back-office/Api/BackOffice.Api.csproj
db_context: BackOfficeDbContext
apply_migrations: ${{ needs.build-and-test.outputs.deploy_staging == 'true' }}
api-stage:
name: API Staging
if: ${{ needs.build-and-test.outputs.deploy_staging == 'true' }}
needs: [build-and-test, database-migrations-stage]
uses: ./.github/workflows/_deploy-container.yml
secrets: inherit
with:
azure_environment: "stage"
cluster_location_acronym: ${{ vars.STAGING_CLUSTER_LOCATION_ACRONYM }}
service_principal_id: ${{ vars.STAGING_SERVICE_PRINCIPAL_ID }}
subscription_id: ${{ vars.STAGING_SUBSCRIPTION_ID }}
image_name: back-office-api
version: ${{ needs.build-and-test.outputs.version }}
artifacts_name: back-office-api
artifacts_path: application/back-office/Api/publish
docker_context: ./application/back-office
docker_file: ./Api/Dockerfile
workers-stage:
name: Workers Staging
if: ${{ needs.build-and-test.outputs.deploy_staging == 'true' }}
needs: [build-and-test, database-migrations-stage]
uses: ./.github/workflows/_deploy-container.yml
secrets: inherit
with:
azure_environment: "stage"
cluster_location_acronym: ${{ vars.STAGING_CLUSTER_LOCATION_ACRONYM }}
service_principal_id: ${{ vars.STAGING_SERVICE_PRINCIPAL_ID }}
subscription_id: ${{ vars.STAGING_SUBSCRIPTION_ID }}
image_name: back-office-workers
version: ${{ needs.build-and-test.outputs.version }}
artifacts_name: back-office-workers
artifacts_path: application/back-office/Workers/publish
docker_context: ./application/back-office
docker_file: ./Workers/Dockerfile
database-migrations-prod1:
name: Database Production
if: ${{ needs.build-and-test.outputs.deploy_production == 'true' }}
needs: [build-and-test, api-stage, workers-stage]
uses: ./.github/workflows/_migrate-database.yml
secrets: inherit
with:
azure_environment: "prod"
cluster_location_acronym: ${{ vars.PRODUCTION_CLUSTER1_LOCATION_ACRONYM }}
service_principal_id: ${{ vars.PRODUCTION_SERVICE_PRINCIPAL_ID }}
subscription_id: ${{ vars.PRODUCTION_SUBSCRIPTION_ID }}
database_name: back-office
relative_project_path: back-office/Core/BackOffice.csproj
relative_startup_project: back-office/Api/BackOffice.Api.csproj
db_context: BackOfficeDbContext
apply_migrations: true
api-prod1:
name: API Production
if: ${{ needs.build-and-test.outputs.deploy_production == 'true' }}
needs: [build-and-test, database-migrations-prod1]
uses: ./.github/workflows/_deploy-container.yml
secrets: inherit
with:
azure_environment: "prod"
cluster_location_acronym: ${{ vars.PRODUCTION_CLUSTER1_LOCATION_ACRONYM }}
service_principal_id: ${{ vars.PRODUCTION_SERVICE_PRINCIPAL_ID }}
subscription_id: ${{ vars.PRODUCTION_SUBSCRIPTION_ID }}
image_name: back-office-api
version: ${{ needs.build-and-test.outputs.version }}
artifacts_name: back-office-api
artifacts_path: application/back-office/Api/publish
docker_context: ./application/back-office
docker_file: ./Api/Dockerfile
workers-prod1:
name: Workers Production
if: ${{ needs.build-and-test.outputs.deploy_production == 'true' }}
needs: [build-and-test, database-migrations-prod1]
uses: ./.github/workflows/_deploy-container.yml
secrets: inherit
with:
azure_environment: "prod"
cluster_location_acronym: ${{ vars.PRODUCTION_CLUSTER1_LOCATION_ACRONYM }}
service_principal_id: ${{ vars.PRODUCTION_SERVICE_PRINCIPAL_ID }}
subscription_id: ${{ vars.PRODUCTION_SUBSCRIPTION_ID }}
image_name: back-office-workers
version: ${{ needs.build-and-test.outputs.version }}
artifacts_name: back-office-workers
artifacts_path: application/back-office/Workers/publish
docker_context: ./application/back-office
docker_file: ./Workers/Dockerfile