-
Notifications
You must be signed in to change notification settings - Fork 3
216 lines (179 loc) · 6.77 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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"
- ".github/actions/build-dotnet-app/action.yml"
- ".github/actions/run-unit-tests/action.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:
lint-code:
name: Lint & Commit
runs-on: ubuntu-22.04
if: ${{ github.event_name == 'pull_request' }}
permissions:
contents: write
pull-requests: write
checks: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
cache: false
- name: Lint plan-technology-for-your-school.sln solution
run: dotnet format plan-technology-for-your-school.sln
- name: Commit and push changes if necessary
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
if [[ `git status --porcelain` ]]; then
git add src/*
git add tests/*
git commit -m "chore: Linted code for plan-technology-for-your-school.sln solution"
git push
else
echo 'No linting changes'
fi
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@v4
- name: Cache SonarCloud packages
uses: actions/cache@v4
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@v4
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=**/Program.cs,**/gulpfile.js,**/wwwroot/**,**/Dfe.PlanTech.Web.SeedTestData/** \
/d:sonar.issue.ignore.multicriteria=e1 \
/d:sonar.issue.ignore.multicriteria.e1.ruleKey=csharpsquid:S6602 \
/d:sonar.issue.ignore.multicriteria.e1.resourceKey=src/**/*.cs \
/d:sonar.scanner.scanAll=false
- 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@v4
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@v4
- 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@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "latest"
- name: Install Dependencies
working-directory: ./tests/Dfe.PlanTech.Web.Node.UnitTests/
run: npm install
- name: Run the tests
working-directory: ./tests/Dfe.PlanTech.Web.Node.UnitTests/
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: ./tests/Dfe.PlanTech.Web.Node.UnitTests/junit.xml # Path to test results
reporter: jest-junit # Format of test results
run-contentful-jest-tests:
name: Run Jest Tests for Contentful
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if contentful files changed
id: contentful-check
run: |
git fetch origin ${{ github.base_ref }} --depth=1
if git diff --name-only HEAD^ HEAD | grep '^contentful/'; then
echo "contentful_changes=true" >> $GITHUB_ENV
echo "::set-output name=changed::true"
else
echo "contentful_changes=false" >> $GITHUB_ENV
echo "::set-output name=changed::false"
fi
- name: Setup Node.js
if: steps.contentful-check.outputs.changed == 'true'
uses: actions/setup-node@v4
with:
node-version: "latest"
- name: Install Dependencies
if: steps.contentful-check.outputs.changed == 'true'
working-directory: ./contentful
run: npm install
- name: Run Jest Tests
if: steps.contentful-check.outputs.changed == 'true'
working-directory: ./contentful/tests
run: npm test -- --ci --reporters=default --reporters=jest-junit
- name: Test Report
if: steps.contentful-check.outputs.changed == 'true' && (success() || failure())
uses: dorny/test-reporter@v1
with:
name: Contentful Jest Tests
path: ./contentful/junit.xml
reporter: jest-junit