-
Notifications
You must be signed in to change notification settings - Fork 1
220 lines (210 loc) · 6.68 KB
/
continuous-integration.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
name: Continuous integration
concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}"
cancel-in-progress: true
on:
workflow_call:
outputs:
docker:
description: 'Docker images to build'
value: ${{jobs.config.outputs.docker}}
frontend:
description: 'Frontend location'
value: ${{jobs.config.outputs.frontend}}
pull_request:
workflow_dispatch:
jobs:
config:
name: Load settings
runs-on: ubuntu-20.04
outputs:
docker: ${{ steps.docker.outputs.result }}
frontend: ${{ steps.frontend.outputs.result }}
code-analysis: ${{ steps.analysis.outputs.result }}
steps:
- uses: actions/checkout@v4
- name: Load docker configuration
id: docker
uses: mikefarah/[email protected]
with:
cmd: yq '.docker' .github/CICD-Config.yml -o=json
- run: echo "Docker configuration ${{ steps.docker.outputs.result }}"
- uses: actions/checkout@v4
- name: Load Code analysis configuration
id: analysis
uses: mikefarah/[email protected]
with:
cmd: yq '.code-analysis-languages' .github/CICD-Config.yml -o=json
- run: echo "Code analysis configuration ${{ steps.analysis.outputs.result }}"
- name: Load frontend configuration
id: frontend
uses: mikefarah/[email protected]
with:
cmd: yq '.frontend-location' .github/CICD-Config.yml
- run: echo "Frontend configuration ${{ steps.frontend.outputs.result }}"
changes:
name: Change detection
runs-on: ubuntu-20.04
needs: [ config ]
permissions:
pull-requests: read
contents: read
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ github.ref_name }}
filters: |
backend:
- '**/*.cs'
- '**/*.csproj'
frontend:
- '${{ needs.config.outputs.frontend}}/**'
build-backend:
name: Build .NET solution
runs-on: ubuntu-20.04
needs: [ changes, config ]
if: ${{ needs.changes.outputs.backend == 'true' }}
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
build-frontend:
name: Build frontend
runs-on: ubuntu-20.04
needs: [ changes, config ]
if: ${{ needs.changes.outputs.frontend == 'true' }}
defaults:
run:
working-directory: '${{ needs.config.outputs.frontend }}'
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: '${{ needs.config.outputs.frontend}}/pnpm-lock.yaml'
- name: Install modules
run: pnpm install
- name: Build
run: pnpm build
lint-frontend:
name: Lint and format frontend
runs-on: ubuntu-20.04
needs: [ build-frontend, config ]
if: ${{ needs.changes.outputs.frontend == 'true' }}
defaults:
run:
working-directory: '${{ needs.config.outputs.frontend }}'
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: '${{ needs.config.outputs.frontend}}/pnpm-lock.yaml'
- name: Install modules
run: pnpm install
- name: Perform linter
run: pnpm run lint
unit-testing:
name: Unit testing
permissions:
pull-requests: write
contents: read
runs-on: ubuntu-20.04
needs: [ build-backend ]
if: ${{ needs.changes.outputs.backend == 'true' }}
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test with the dotnet CLI
run: dotnet test --no-restore --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: Code Coverage Report
uses: irongut/[email protected]
with:
filename: coverage/**/coverage.cobertura.xml
badge: true
fail_below_min: false # Set to true when tests are added to the project.
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '90 90'
- 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
build-docker:
name: Build Docker
runs-on: ubuntu-20.04
needs: [ config, changes ]
strategy:
fail-fast: false
matrix:
include: ${{fromJson(needs.config.outputs.docker)}}
steps:
- uses: actions/checkout@v4
- name: Build and push
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
push: false
file: ${{ matrix.file }}
code-analysis:
name: Code analysis
needs: [ changes, config ]
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
if: ${{ needs.config.outputs.code-analysis != 'false' }}
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ${{fromJson(needs.config.outputs.code-analysis)}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
if: ${{ matrix.language != null }}
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v3
if: ${{ matrix.language != null }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
if: ${{ matrix.language != null }}
with:
category: "/language:${{matrix.language}}"
cleanup:
runs-on: ubuntu-20.04
if: ${{ always() }}
needs: [ build-frontend, build-backend, lint-frontend, unit-testing, build-docker, code-analysis ]
steps:
- name: Checkout repository
uses: actions/checkout@v4