-
Notifications
You must be signed in to change notification settings - Fork 17
126 lines (113 loc) · 5.5 KB
/
pr-action.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
name: 'PR build action'
## Only builds when someone PRs against main
on:
pull_request:
branches:
- main
## Builds not be run if the following files are the ones which are
## changed in a PR
## see: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-excluding-paths
paths-ignore:
- '**/README.md'
- '**/Dockerfile'
- '**/global.json'
jobs:
build:
runs-on: ubuntu-latest
steps:
## The first thing we need to do is get the latest code out from git, otherwise
## we can't build anything
- name: Checkout the code
uses: actions/checkout@v4
with:
fetch-depth: 0
## Next we need to ensure that we have the .NET tooling installed.
- name: Install the .NET SDK
uses: actions/setup-dotnet@v4
with:
## Ensure that we install the version of the .NET SDK found in the global.json file
global-json-file: global.json
## Set a number of environment variables for the .NET tooling (these need
## to be set on our first step which uses the .NET tooling in order to take
## effect).
## We're setting these so that our logs are shorter, easier to read, and
## so that builds are around 1-2 second faster than normally.
env:
## removes logo and telemetry message from first run of dotnet cli
DOTNET_NOLOGO: 1
## opt-out of .NET tooling telemetry being sent to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: 1
## Now we need to restore any NuGet packages that we rely on in order to build
## or run the application
- name: Install code level dependencies
run: dotnet restore
working-directory: ${{env.working-directory}}
## Building is next. Note the use of both the --configuration and
## --no-restore flags.
## The first flag sets the build configuration. We want Release here as it
## will produce a smaller binary than a Debug (which is the default) build.
## When running a Release build, the compiler will optimise your code and
## remove any debugging statements that it adds in order to make debugging
## easier - note: its still possible to debug Release code.
## The second flag tells the .NET tooling not to attempt to restore any NuGet
## packages. This is a time saving operation, as we restored them in the
## previous step.
- name: Build
run: dotnet build --configuration Release --no-restore
working-directory: ${{env.working-directory}}
test:
runs-on: ubuntu-latest
needs: ["build"]
steps:
## The first thing we need to do is get the latest code out from git, otherwise
## we can't build anything
- name: Checkout the code
uses: actions/checkout@v4
with:
fetch-depth: 0
## Run all of the discovered tests for this repository, telling the dotnet
## tooling to not waste time building (--no-build), use the Release config
## (--configuration Release), and only print the normal amount of logs to
## the screen (--verbosity normal).
## We also want it to collect cross platform readable code coverage stats
## (--collect: "XPlat Code Coverage") and store them in a known location
## (-- results-directory ./coverage)
## The code coverage stats will show us how much of the code base is covered
## by our tests. This can be useful to identify which areas are NOT covered
## by our tests, and it can help us to identify where we should spend our
## personal and technical bandwidth in shoring up the test coverage.
- name: Run tests
run: dotnet test dwCheckApi.sln --configuration Release --collect:"XPlat Code Coverage" --results-directory ./coverage
#### FEB 18TH, 2024 :TEMPORARILY COMMENTED OUT THE FOLLOWING THREE STEPS AS THERE
#### ARE MULTIPLE TEST CLASSES, EACH CREATING A SEPARATE coverage.cobertura.xml
#### WILL NEED TO INVESTIGATE A WAY TO COMBINE THEM ALL INTO ONE FILE BEFORE COPYING TO
#### THE OUTPUT DIRECTORY.
# ## We are about to use a GitHub action called Code Coverage Summary to get a
# ## human readable summary of the code coverage stuff from the previous step.
# ## The Code Coverage Summary action requires the code coverage stuff to be
# ## in a predictable location, so let's copy those files right now.
# - name: Copy Coverage To Known Location
# run: cp coverage/**/coverage.cobertura.xml coverage.cobertura.xml
# ## Generate a Code Coverage report based on the code coverage we've gotten
# ## in the previous steps.
# ## This will create a file on disk, but not in the repo. So we'll need to
# ## create a PR off the back of this action to add that file to the repo.
# - name: Code Coverage Summary Report
# uses: irongut/[email protected]
# with:
# filename: coverage.cobertura.xml
# badge: true
# fail_below_min: true
# format: markdown
# hide_branch_rate: false
# hide_complexity: true
# indicators: true
# output: both
# thresholds: '0 80'
# ## Create the PR to add the Code Coverage Summary to the repo
# - 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