-
Notifications
You must be signed in to change notification settings - Fork 3
185 lines (152 loc) · 5.49 KB
/
code-pr-check.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
name: Code PR Check
on:
push:
branches: ["main", "development"]
paths:
- 'src/**'
- 'tests/**'
pull_request:
branches: ["main", "development"]
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/code-pr-check.yml'
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
env:
DOTNET_VERSION: ${{ vars.DOTNET_VERSION }}
jobs:
get-src-dir-list:
name: Get Directories for Linting
runs-on: ubuntu-22.04
if: ${{ github.event_name == 'pull_request' }}
outputs:
directories: ${{ steps.list-dir.outputs.directories }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Get Directories
id: list-dir
uses: ./.github/actions/list-directory
with:
source: ./src/
lint-code:
name: Lint & Commit
runs-on: ubuntu-22.04
if: ${{ github.event_name == 'pull_request' }}
needs: [get-src-dir-list]
strategy:
max-parallel: 1
fail-fast: true
matrix:
workspace: ${{ fromJson(needs.get-src-dir-list.outputs.directories) }}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
cache: false
env:
DOTNET_INSTALL_DIR: "/usr/share/dotnet"
DOTNET_CLI_TELEMETRY_OPTOUT: true
- name: Run Linter
uses: wearerequired/lint-action@v2
with:
dotnet_format: true
dotnet_format_dir: ./src/${{ matrix.workspace }}
git_email: "41898282+github-actions[bot]@users.noreply.github.com"
git_name: "github-actions[bot]"
commit_message: "Linted Code in ${{ matrix.workspace }}"
auto_fix: true
commit: true
github_token: ${{ secrets.GITHUB_TOKEN }}
build-test-web-app:
name: Build and run unit tests
runs-on: ubuntu-22.04
if: ${{ always() && ( github.event_name == 'pull_request' && needs.lint-code.result == 'success' ) || ( github.event_name == 'push' && needs.lint-code.result == 'skipped' ) }}
needs: [lint-code]
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Install dotnet coverage
run: dotnet tool install --global dotnet-coverage --version 17.9.3
- name: Install SonarCloud scanners
run: dotnet tool install --global dotnet-sonarscanner
- name: Install latest JDK
uses: actions/setup-java@v3
with:
distribution: 'microsoft'
java-version: '17'
- name: Start SonarCloud scanner
run: |
dotnet-sonarscanner begin \
/k:"DFE-Digital_plan-technology-for-your-school" \
/o:"dfe-digital" \
/d:sonar.login="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \
/d:sonar.coverage.exclusions=src/**/Program.cs,src/Dfe.PlanTech.Web/gulpfile.js,src/Dfe.PlanTech.Web/wwwroot/** \
/d:sonar.issue.ignore.multicriteria=e1 \
/d:sonar.issue.ignore.multicriteria.e1.ruleKey=csharpsquid:S6602 \
/d:sonar.issue.ignore.multicriteria.e1.resourceKey=src/**/*.cs
- name: Build web app
uses: ./.github/actions/build-dotnet-app
with:
dotnet_version: ${{ env.DOTNET_VERSION }}
solution_filename: plan-technology-for-your-school.sln
- name: Run unit tests
uses: ./.github/actions/run-unit-tests
with:
solution_filename: plan-technology-for-your-school.sln
- name: Merge test results
run: dotnet-coverage merge -f xml -o "coverage.xml" -s "coverage.settings.xml" -r coverage.cobertura.xml
- name: End SonarCloud Scanner
run: dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: coverage.xml
build-database-upgrader:
name: Build database upgrader
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Build database upgrader
uses: ./.github/actions/build-dotnet-app
with:
dotnet_version: ${{ env.DOTNET_VERSION }}
solution_filename: Dfe.PlanTech.DatabaseUpgrader.sln
run-javascript-tests:
runs-on: ubuntu-22.04
name: Run javascript tests
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "latest"
- name: Install Dependencies
run: npm install
- name: Run the tests
run: npm test
- name: Test report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: JEST Tests # Name of the check run which will be created
path: ./junit.xml # Path to test results
reporter: jest-junit # Format of test results