forked from andrewjsaid/builderbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (141 loc) · 5.82 KB
/
test.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
name: "Run tests"
env:
# Only merge code coverage results if 1
USE_MERGE: 0
on:
push:
pull_request:
permissions:
contents: write
pull-requests: write
# https://www.meziantou.net/how-to-cancel-github-workflows-when-pushing-new-commits-on-a-branch.htm
concurrency:
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
test:
name: test-${{matrix.os}}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
matrix:
os: [ubuntu-latest]
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4.2.2
# https://github.com/adamralph/minver?tab=readme-ov-file#why-is-the-default-version-sometimes-used-in-github-actions-azure-pipelines-and-travis-ci-when-a-version-tag-exists-in-the-history
with:
fetch-depth: 0
filter: tree:0
- name: "Check for changed files"
uses: dorny/paths-filter@v3
id: filter
with:
filters: .github/filter.yml
- name: Set environment variable
id: set-env
run: |
if [ "${{ steps.filter.outputs.code }}" == "true" ] || [ "${{ steps.filter.outputs.test }}" == "true" ]; then
echo "ENABLED=1" >> $GITHUB_ENV
else
echo "ENABLED=0" >> $GITHUB_ENV
fi
- name: Setup .NET Core
uses: actions/setup-dotnet@v4.3.0
if: env.ENABLED == '1'
with:
global-json-file: global.json
cache: true
cache-dependency-path: "**/packages.lock.json"
- name: Install dotnet-coverage tool
if: env.ENABLED == '1'
run: dotnet tool install -g dotnet-coverage
- name: Check if PR for current commit
if: env.ENABLED == '1'
uses: 8BitJonny/gh-get-current-pr@3.0.0
with:
# This will work no matter the trigger event and no matter if it is the first PR commit or not.
sha: ${{ github.event.pull_request.head.sha }}
# By default it returns PRs in any state.
filterOutClosed: true
# By default it returns PRs in any state.
filterOutDraft: true
id: pr-check
- name: Install dependencies
if: env.ENABLED == '1' && steps.pr-check.outputs.pr_found == 'true'
run: |
dotnet restore --force-evaluate && git add .
- id: commit
if: env.ENABLED == '1' && steps.pr-check.outputs.pr_found == 'true'
uses: qoomon/actions--create-commit@v1
with:
message: "Committing changes to lock files [skip ci]"
allow-empty: false
skip-empty: true
- if: env.ENABLED == '1' && steps.pr-check.outputs.pr_found == 'true' && steps.commit.outputs.commit != null
run: git push origin HEAD:${{ github.head_ref || github.ref_name }}
- name: Install dependencies
if: env.ENABLED == '1' && steps.pr-check.outputs.pr_found == 'false'
run: |
dotnet restore --locked-mode
- name: Build
if: env.ENABLED == '1'
run: dotnet build --configuration Release --no-restore --tl
- name: Test
if: env.ENABLED == '1'
run: dotnet test -s ./cicd.runsettings --configuration Release --no-build --verbosity quiet --logger "GitHubActions;summary.includeNotFoundTests=false" -- --coverage --coverage-output-format xml --coverage-output coverage.cobertura.xml
- name: ReportGenerator
if: env.ENABLED == '1'
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.3
with:
reports: '**/TestResults/**/coverage.cobertura.xml'
targetdir: '${{ github.workspace }}/coveragereport'
reporttypes: 'MarkdownSummaryGithub;MarkdownAssembliesSummary'
classfilters: '-System.*;-Microsoft.*;-Newtonsoft.*;-System.Text.RegularExpressions.*;-xunit.*;-NUnit.*'
- name: Upload code coverage results to codecov
if: env.ENABLED == '1'
uses: codecov/codecov-action@v5.3.1
with:
flags: unittests
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# https://github.com/danielpalme/ReportGenerator/issues/431
- name: Publish PR coverage summary
uses: marocchino/sticky-pull-request-comment@v2
if: steps.pr-check.outputs.pr_found == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
hide: true # Hide previous comment
hide_classify: "OUTDATED"
skip_unchanged: true
number: ${{ steps.pr-check.outputs.number }}
path: coveragereport/Summary.md
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: "Code coverage"
- name: Publish coverage in build summary
if: env.ENABLED == '1'
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
shell: bash
- name: Merge code coverage results
if: env.USE_MERGE == 1 && env.ENABLED == '1'
run: dotnet-coverage merge **/*/*.cobertura.xml -f cobertura -o ./cobertura.xml
shell: bash
# In v4, Artifacts are immutable (unless deleted). So you must change
# each of the uploaded Artifacts to have a different name and filter the
# downloads by name to achieve the same effect
- name: Archive results
# https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md
uses: actions/upload-artifact@v4
if: env.ENABLED == '1'
with:
name: code-coverage-report-${{ matrix.os }}
path: |
**/TestResults/**/coverage.cobertura.xml
coveragereport/*.md