-
Notifications
You must be signed in to change notification settings - Fork 30
234 lines (198 loc) · 8.41 KB
/
account-management.yml
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
name: Account Management - Build and Deploy
on:
push:
branches:
- main
paths:
- "application/*"
- "application/shared-kernel/**"
- "application/shared-webapp/**"
- "application/account-management/**"
- ".github/workflows/account-management.yml"
- ".github/workflows/_deploy-container.yml"
- "!**.md"
pull_request:
paths:
- "application/*"
- "application/shared-kernel/**"
- "application/shared-webapp/**"
- "application/account-management/**"
- ".github/workflows/account-management.yml"
- ".github/workflows/_deploy-container.yml"
- "!**.md"
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.generate_version.outputs.version }}
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: 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:
dotnet-version: 9.0.x
- 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 account-management/AccountManagement.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} &&
dotnet dotcover test account-management/AccountManagement.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 account-management/AccountManagement.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} &&
dotnet dotcover test account-management/AccountManagement.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: github.ref == 'refs/heads/main'
working-directory: application
run: npm run build
- name: Publish frontend artifacts
if: github.ref == 'refs/heads/main'
working-directory: application/account-management/WebApp
run: npm run publish
- name: Publish API build
if: github.ref == 'refs/heads/main'
working-directory: application/account-management
run: |
dotnet publish ./Api/AccountManagement.Api.csproj --no-restore --configuration Release --output ./Api/publish /p:Version=${{ steps.generate_version.outputs.version }}
- name: Save API artifacts
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: account-management-api
path: application/account-management/Api/publish/**/*
- name: Publish Worker build
if: github.ref == 'refs/heads/main'
working-directory: application/account-management
run: |
dotnet publish ./Workers/AccountManagement.Workers.csproj --no-restore --configuration Release --output ./Workers/publish /p:Version=${{ steps.generate_version.outputs.version }}
- name: Save Workers artifacts
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: account-management-workers
path: application/account-management/Workers/publish/**/*
code-style-and-linting:
name: Code Style and Linting
if: github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
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:
dotnet-version: 9.0.x
- 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 account-management/AccountManagement.slnf --no-restore
- name: Run code inspections
working-directory: application
run: |
dotnet jb inspectcode account-management/AccountManagement.slnf --no-build --output=result.json --severity=SUGGESTION
# Check if there are any issues. <Issues /> indicates no issues found.
if ! grep -q '\"results\": \[\],' result.json; then
cat result.json
echo "Code inspection issues found."
exit 1
fi
- name: Check for code formatting issues
working-directory: application
run: |
dotnet jb cleanupcode account-management/AccountManagement.slnf --no-build --profile=".NET only"
# Check for any changes made by the code formatter
git diff --exit-code || {
echo "Formatting issues detected. Please run 'dotnet jb cleanupcode account-management/AccountManagement.slnf --profile=\".NET only\"' 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/account-management/WebApp
run: npm run check
api-deploy:
name: Deploy API
if: github.ref == 'refs/heads/main'
needs: [build-and-test]
uses: ./.github/workflows/_deploy-container.yml
secrets: inherit
with:
image_name: account-management-api
version: ${{ needs.build-and-test.outputs.version }}
artifacts_name: account-management-api
artifacts_path: application/account-management/Api/publish
docker_context: ./application/account-management
docker_file: ./Api/Dockerfile
workers-deploy:
name: Deploy Workers
if: github.ref == 'refs/heads/main'
needs: [build-and-test]
uses: ./.github/workflows/_deploy-container.yml
secrets: inherit
with:
image_name: account-management-workers
version: ${{ needs.build-and-test.outputs.version }}
artifacts_name: account-management-workers
artifacts_path: application/account-management/Workers/publish
docker_context: ./application/account-management
docker_file: ./Workers/Dockerfile