-
-
Notifications
You must be signed in to change notification settings - Fork 516
293 lines (230 loc) · 9.86 KB
/
build.yaml
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
name: Build
on:
push:
branches: [main]
tags: ['v*']
pull_request:
env:
TERM: xterm
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_NOLOGO: true
MSBUILDTERMINALLOGGER: auto
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
jobs:
version:
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Reason
env:
GITHUB_EVENT: ${{ toJson(github) }}
run: "echo ref: ${{github.ref}} event: ${{github.event_name}}"
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.*
dotnet-quality: preview
- name: Version
id: version
run: |
dotnet tool install --global minver-cli --version 6.0.0
version=$(minver --tag-prefix v)
echo "version=$version" >> $GITHUB_OUTPUT
echo "### $version" >> $GITHUB_STEP_SUMMARY
test-api:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.*
dotnet-quality: preview
- name: Start Services
working-directory: docker
run: docker compose up -d elasticsearch &
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
nuget-${{ runner.os }}-
- name: Nuget Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Wait for Elasticsearch
working-directory: docker
run: docker compose up --wait elasticsearch
- name: Run .NET Tests
run: dotnet test --no-restore --no-build --configuration Release --collect:"XPlat Code Coverage" -m:1 --logger trx --results-directory coverage --logger GitHubActions
- name: Copy Coverage to Predictable Location
run: cp coverage/*/coverage.cobertura.xml coverage/coverage.cobertura.xml
- name: Code Coverage Summary Report
uses: irongut/[email protected]
with:
filename: coverage/coverage.cobertura.xml
badge: true
format: "markdown"
output: "both"
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
- name: Write Coverage to Job Summary
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
test-client:
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
working-directory: src/Exceptionless.Web/ClientApp
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
uses: actions/cache@v4
id: cache-node-modules
with:
path: src/Exceptionless.Web/ClientApp/node_modules
key: node-modules-${{ hashFiles('src/Exceptionless.Web/ClientApp/package-lock.json') }}
- name: Install Npm Packages
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
- name: Lint Client
run: npm run lint
- name: Check
run: npm run check
- name: Build
run: npm run build
- name: Run Unit Tests
run: echo "npm run test:unit"
- name: Run Integration Tests
run: echo "npm run test:integration"
build-and-push-docker:
runs-on: ubuntu-latest
needs: [version]
timeout-minutes: 30
env:
VERSION: ${{needs.version.outputs.version}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
if: "${{ env.DOCKER_USERNAME != '' }}"
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64
- name: Build api docker image
run: |
echo "::remove-matcher owner=csc::"
docker buildx build . --target api --platform linux/amd64 --tag exceptionless/api-ci:latest --cache-from type=gha --cache-to type=gha,mode=max --load
- name: Build job docker image
run: |
echo "::remove-matcher owner=csc::"
docker buildx build . --target job --platform linux/amd64 --tag exceptionless/job-ci:latest --cache-from type=gha --cache-to type=gha,mode=max --load
- name: Build app docker image
run: |
echo "::remove-matcher owner=csc::"
docker buildx build . --target app --platform linux/amd64 --tag exceptionless/app-ci:latest --cache-from type=gha --cache-to type=gha,mode=max --load
- name: Build all-in-one docker image
run: |
echo "::remove-matcher owner=csc::"
docker buildx build . --target exceptionless --platform linux/amd64 --tag exceptionless/exceptionless-ci:latest --cache-from type=gha --cache-to type=gha,mode=max --load
- name: Build all-in-one Elasticsearch 7 docker image
if: "${{ env.DOCKER_USERNAME != '' && startsWith(github.ref, 'refs/tags/v') && github.event_name != 'pull_request' }}"
run: |
echo "::remove-matcher owner=csc::"
docker buildx build . --target exceptionless7 --platform linux/amd64 --tag exceptionless/exceptionless:latest-elasticsearch7 --cache-from type=gha --cache-to type=gha,mode=max --load
- name: Login to GitHub Container Registry
if: "${{ env.DOCKER_USERNAME != '' }}"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
if: "${{ env.DOCKER_USERNAME != '' }}"
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Wait for test jobs # doing it this way so we don't have to copy artifacts between jobs
uses: yogeshlonkar/wait-for-jobs@v0
with:
jobs: 'test-api,test-client'
interval: '2500'
ttl: '10'
- name: Publish CI Packages
if: "${{ env.DOCKER_USERNAME != '' }}"
run: |
echo "::remove-matcher owner=csc::"
# tag and push docker images
for image in {"api","job","app","exceptionless"}; do
docker image tag exceptionless/$image-ci:latest exceptionless/$image-ci:$VERSION
docker image tag exceptionless/$image-ci:latest ghcr.io/exceptionless/exceptionless/$image-ci:$VERSION
docker image tag exceptionless/$image-ci:latest ghcr.io/exceptionless/exceptionless/$image-ci:latest
docker image push --all-tags exceptionless/$image-ci
done
- name: Publish Release Packages
if: "${{ env.DOCKER_USERNAME != '' && startsWith(github.ref, 'refs/tags/v') && github.event_name != 'pull_request' }}"
run: |
echo "::remove-matcher owner=csc::"
# tag and push docker images
# only build elasticsearch 7 all-in-one image for release builds
docker image tag exceptionless/exceptionless:latest-elasticsearch7 exceptionless/exceptionless:$VERSION-elasticsearch7
for image in {"api","job","app","exceptionless"}; do
docker image tag exceptionless/$image-ci:latest exceptionless/$image:$VERSION
docker image tag exceptionless/$image-ci:latest exceptionless/$image:latest
docker image push --all-tags exceptionless/$image
done
deploy:
if: "${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.event_name != 'pull_request' }}"
needs: [version,build-and-push-docker]
runs-on: ubuntu-latest
timeout-minutes: 30
env:
VERSION: ${{needs.version.outputs.version}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Helm
if: "${{ env.DOCKER_USERNAME != '' && github.event_name != 'pull_request' }}"
uses: azure/setup-helm@v4
- name: Deploy Changes to Development Environment
if: "${{ env.DOCKER_USERNAME != '' && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }}"
run: |
az login --service-principal --username ${{ secrets.AZ_USERNAME }} --password ${{ secrets.AZ_PASSWORD }} --tenant ${{ secrets.AZ_TENANT }} --output none
az aks get-credentials --resource-group exceptionless-v6 --name ex-k8s-v6
sed -i "s/^appVersion:.*$/appVersion: '${VERSION}'/" ./k8s/exceptionless/Chart.yaml
helm upgrade --set "version=${VERSION}" --reuse-values --values ./k8s/ex-dev-values.yaml ex-dev --namespace ex-dev ./k8s/exceptionless
- name: Deploy Changes to Production Environment
if: "${{ env.DOCKER_USERNAME != '' && startsWith(github.ref, 'refs/tags/v') && github.event_name != 'pull_request' }}"
run: |
az login --service-principal --username ${{ secrets.AZ_USERNAME }} --password ${{ secrets.AZ_PASSWORD }} --tenant ${{ secrets.AZ_TENANT }} --output none
az aks get-credentials --resource-group exceptionless-v6 --name ex-k8s-v6
sed -i "s/^appVersion:.*$/appVersion: '${VERSION}'/" ./k8s/exceptionless/Chart.yaml
helm upgrade --set "version=${VERSION}" --reuse-values --values ./k8s/ex-prod-values.yaml ex-prod --namespace ex-prod ./k8s/exceptionless