-
Notifications
You must be signed in to change notification settings - Fork 0
179 lines (156 loc) · 6.4 KB
/
backend-ci.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
name: "Backend CI"
on:
workflow_dispatch:
push:
branches:
- dev
tags:
- "v*"
paths:
- "src/backend/**"
- "tests/backend/**"
pull_request:
branches:
- main
- test
- dev
paths:
- "src/backend/**"
- "tests/backend/**"
- ".github/workflows/backend-ci.yml"
types: [opened, reopened, labeled, synchronize, ready_for_review]
# Sets permissions of the GITHUB_TOKEN to allow creating checks and updating PR
permissions:
contents: read
checks: write
pull-requests: write
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true
env:
DOTNET_VERSION: "8.0.x"
BACKEND_SOLUTION_PATH: "src/backend"
WORKFLOW_SHORT_NAME: "backend-ci"
WORKFLOW_AGENT_PATH: "/home/runner/work/test/test/"
jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.draft == false }}
defaults:
run:
working-directory: ${{ env.BACKEND_SOLUTION_PATH }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # used by GitVersion to find the most recent tag outside of this branch
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- uses: actions/cache@v4
id: nuget-cache
with:
path: ~/.nuget/packages
key: nuget-${{ hashFiles('**/packages.lock.json') }}
- name: dotnet restore
run: dotnet restore --locked-mode
- name: dotnet tool restore
run: dotnet tool restore
- name: Build
id: dotnet-build
run: |
dotnet build -c Release --no-restore --nologo -consoleLoggerParameters:NoSummary -verbosity:quiet 1>build.out 2>&1 || (exit 0)
grep "): error " build.out > build.err || (exit 0)
if [ ! -s build.err ]
then
echo "## ✅ Build successful" > build.md
else
# Reformat error output as github error annotations
error_regex="(.+)\(([0-9]+),([0-9]+)\): error (.+) \[(.+)\]"
# Capture groups: 1=file path 2=line 3=character 4=warn: message 5=project path
cat build.err | while read line
do
if [[ $line =~ $error_regex ]]; then
echo "::error file=${BASH_REMATCH[1]},line=${BASH_REMATCH[2]}::${BASH_REMATCH[4]}"
fi
done
cat build.err | sed 's|${{ env.WORKFLOW_AGENT_PATH }}|| ; s|${{ env.WORKFLOW_AGENT_PATH }}||' > build.md
sed -i '/^$/d' build.md # removes empty lines
sed -i -e 's/^/- ❌ /' build.md # prefix with markdown list item and cross mark emoji
echo "## ❌ The following build issues should be fixed:" | cat - build.md > build.md.temp && mv build.md.temp build.md
fi
echo "result<<EOF"$'\n'"$(cat build.md)"$'\n'EOF >> $GITHUB_OUTPUT
cat build.md >> $GITHUB_STEP_SUMMARY
if [ -s build.err ]
then
exit 1
fi
- name: "Create or Update PR Comment"
uses: im-open/[email protected]
if: ${{ always() && github.event_name == 'pull_request' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-identifier: "${{ env.WORKFLOW_SHORT_NAME }}-build-results"
comment-content: ${{ steps.dotnet-build.outputs.result }}
- name: WebApi Tests
run: dotnet test ../../tests/backend/WebApi.Tests --no-restore --collect:"XPlat Code Coverage" --logger "trx;LogFileName=test-results.trx" /p:CollectCoverage=true /p:CoverletOutput="../../tests/backend/WebApi.Tests/TestResults/" /p:CoverletOutputFormat=cobertura
- uses: dorny/test-reporter@v1
with:
name: "WebApi Tests"
path: "tests/backend/WebApi.Tests/TestResults/test-results.trx"
reporter: dotnet-trx
fail-on-error: true
- name: Generate report for all tests
id: reportgenerator
run: |
dotnet reportgenerator -reports:"../../tests/backend/**/TestResults/**/coverage.cobertura.xml" -targetdir:"../../tests/backend/CoverageReport" -reporttypes:"Html;Cobertura;MarkdownSummaryGithub;Badges"
cat ../../tests/backend/CoverageReport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
echo "markdown<<EOF" >> $GITHUB_OUTPUT
cat ../../tests/backend/CoverageReport/SummaryGithub.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# TODO: commit the badges for README.md
- name: "Create or Update PR Comment"
uses: im-open/[email protected]
if: ${{ always() && github.event_name == 'pull_request' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-identifier: "${{ env.WORKFLOW_SHORT_NAME }}-reportgenerator"
comment-content: ${{ steps.reportgenerator.outputs.markdown }}
- name: Code Coverage Report
uses: irongut/[email protected]
with:
filename: "tests/backend/CoverageReport/Cobertura.xml"
badge: true
fail_below_min: false
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: "60 80"
- name: Create output variable
id: code-coverage-summary
run: |
cat ../../code-coverage-results.md >> $GITHUB_STEP_SUMMARY
echo "markdown<<EOF" >> $GITHUB_OUTPUT
cat ../../code-coverage-results.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: "Create or Update PR Comment"
uses: im-open/[email protected]
if: ${{ always() && github.event_name == 'pull_request' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-identifier: "${{ env.WORKFLOW_SHORT_NAME }}-CodeCoverageSummary"
comment-content: ${{ steps.code-coverage-summary.outputs.markdown }}
- name: Inspect code
uses: muno92/resharper_inspectcode@v1
if: ${{ github.event_name == 'pull_request' }}
with:
workingDirectory: ${{ env.BACKEND_SOLUTION_PATH }}
solutionPath: Backend.sln
dotnetVersion: ${{ env.DOTNET_VERSION }}
failOnIssue: false
include: |
**.cs