forked from bcgov/PSP
-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (154 loc) · 6.13 KB
/
api-dotnetcore.yml
File metadata and controls
168 lines (154 loc) · 6.13 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
name: API (.NET 8)
on:
push:
branches: [master, dev, test]
pull_request:
branches: [master, dev, test]
merge_group:
types: [checks_requested]
jobs:
# JOB to run change detection
check-changes:
runs-on: ubuntu-22.04
# Set job outputs to values from filter step
outputs:
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- uses: dorny/paths-filter@7267a8516b6f92bdb098633497bad573efdbf271 # v2.12.0
id: filter
with:
filters: |
backend:
- 'source/backend/**'
build-backend:
needs: check-changes
runs-on: ubuntu-22.04
if: ${{ needs.check-changes.outputs.backend == 'true' }}
strategy:
matrix:
services:
[
{ directory: ./source/backend/api, solution: "Pims.Api.csproj" },
{
directory: ./source/backend/proxy,
solution: "Pims.Proxy.csproj",
},
{
directory: ./source/backend/scheduler,
solution: "Pims.Scheduler.csproj",
},
{ directory: ./source/backend/tests, solution: "PimsUnitTest.sln" },
]
env:
working-directory: ${{ matrix.services.directory }}
solution-name: ${{ matrix.services.solution }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_BRANCH: "${{ github.ref }}"
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Extract Branch Name
shell: bash
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
id: extract_branch
- name: Setup .NET 8
uses: actions/setup-dotnet@871f041373faaad213a635d9afb62905ec029bbb # v1
with:
dotnet-version: "8.0.x"
- name: Install dependencies
run: dotnet restore ${{env.solution-name}}
working-directory: ${{env.working-directory}}
- name: Build
run: dotnet build ${{env.solution-name}} --configuration Release --no-restore
working-directory: ${{env.working-directory}}
- name: Install coverlet for code coverage
if: ${{ env.solution-name == 'PimsUnitTest.sln' }}
run: dotnet tool install -g coverlet.console --version 1.7.2
working-directory: ${{env.working-directory}}
- name: Test
if: ${{ env.solution-name == 'PimsUnitTest.sln' }}
run: dotnet test PimsUnitTest.sln --no-restore --verbosity normal
working-directory: ${{env.working-directory}}
# For future reference, if we have N test projects the flow of events would be:
#
# **Pre-conditions:**
# - All projects export their individual coverage percents in JSON and OpenCover format
# - There's no way to merge OpenCover xmls together (that I could find)
# - Common folder "../TestResults" is git ignored so nothing gets in source control
#
# **Steps:**
#
# - Test-project 1
# - generate coverage files (without merging)
# - copy results to common folder "../TestResults"
# - Test-project 2
# - generate coverage files merging with previous `coverage.json`
# - the previous `coverage.opencoverage.xml` is ignored
# - copy results to common folder "../TestResults"
# ...
# - Test-project N
# - generate coverage files merging with previous `coverage.json`
# - the previous `coverage.opencoverage.xml` is ignored
# - copy results to common folder "../TestResults"
#
# The final `coverage.opencover.xml` is the one we want
- name: Generate code coverage
if: ${{ env.solution-name == 'PimsUnitTest.sln' }}
working-directory: ${{env.working-directory}}
run: |
pwd
mkdir -p TestResults
rm -rf api/TestResults
rm -rf dal/TestResults
rm -rf mockdal/TestResults
rm -rf scheduler/TestResults
cd api
dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings --no-restore
mv TestResults/*/* ../TestResults/
cd ..
cd dal
dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings --no-restore
mv TestResults/*/* ../TestResults/
cd ..
cd mockdal
dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings --no-restore
mv TestResults/*/* ../TestResults/
cd ..
cd scheduler
dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings --no-restore
mv TestResults/*/* ../TestResults/
cd ..
echo "TestResults folder"
ls TestResults
head TestResults/coverage.opencover.xml
- name: Save PR number and scan results
if: ${{ env.solution-name == 'PimsUnitTest.sln' }}
run: |
mkdir -p ./pr
echo ${{ github.event.pull_request.number }} > ./pr/NR
cp ${{env.working-directory}}/TestResults/coverage.opencover.xml ./pr
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
if: ${{ env.solution-name == 'PimsUnitTest.sln' }}
with:
name: pr-codecov
path: pr/
post-build:
needs: build-backend
runs-on: ubuntu-22.04
env:
working-directory: ./source/backend
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_BRANCH: "${{github.ref}}"
steps:
# Send notifications only if MS_TEAMS_NOTIFY_URL secret has been set
- name: Failure notification to Teams Channel
env:
MS_TEAMS_NOTIFY_URL: ${{ secrets.MS_TEAMS_NOTIFY_URL }}
if: env.MS_TEAMS_NOTIFY_URL != '' && failure()
uses: dragos-cojocari/ms-teams-notification@bdee8c5584729d6a2dcaad8fc21ecfd40d1418ab # v1.0.2
with:
github-token: ${{ github.token }}
ms-teams-webhook-uri: ${{ env.MS_TEAMS_NOTIFY_URL }}
notification-summary: PIMS API FAILED in ${{env.GIT_BRANCH}} environment
notification-color: ff0000
timezone: America/Los_Angeles