-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (138 loc) · 4.54 KB
/
code-quality.yml
File metadata and controls
157 lines (138 loc) · 4.54 KB
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
name: Code Quality
on:
pull_request:
branches: [main]
types: [opened, reopened, synchronize]
paths:
- 'src/**'
- 'test/**'
- 'package.json'
- 'tsconfig*'
- 'vitest*'
- '.eslint*'
- 'eslint*'
- '.prettier*'
- '.markdownlint*'
- '.github/workflows/code-quality.yml'
workflow_dispatch:
jobs:
quality:
name: Lint and test
# The linting and testing pipeline should never take more than 15 minutes.
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
submodules: false
- name: Get changed code quality workflow
id: changed-code-quality
uses: tj-actions/changed-files@v41
with:
files: |
.github/workflows/code-quality.yml
- name: Get changed markdown files
id: changed-markdown
uses: tj-actions/changed-files@v41
with:
files: |
.markdownlint*
**/*.md
- name: Get changed JavaScript project files
id: changed-js-project
uses: tj-actions/changed-files@v41
with:
files: |
.eslint*
eslint*
.prettier*
package.json
package-lock.json
tsconfig*
vitest*
src/**
test/**
- name: Should lint documentation
id: lint-docs
run: |
run=false
if [ "${{ steps.changed-markdown.outputs.any_modified }}" == 'true' ] || [ "${{ steps.changed-code-quality.outputs.any_modified }}" == 'true' ] || [ "${{ github.event.action }}" == 'workflow_dispatch' ]; then
run=true
fi
echo "run=${run}" >> $GITHUB_OUTPUT
shell: bash
- name: Should run unit tests
id: check-js
run: |
run=false
if [ "${{ steps.changed-js-project.outputs.any_modified }}" == 'true' ] || [ "${{ steps.changed-code-quality.outputs.any_modified }}" == 'true' ] || [ "${{ github.event.action }}" == 'workflow_dispatch' ]; then
run=true
fi
echo "run=${run}" >> $GITHUB_OUTPUT
shell: bash
- name: Lint all documentation
if: steps.lint-docs.outputs.run == 'true'
uses: DavidAnson/markdownlint-cli2-action@v22
with:
globs: |
**/*.md
- name: Setup Node JS
if: steps.check-js.outputs.run == 'true'
uses: actions/setup-node@v6
with:
node-version-file: .tool-versions
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Install dependencies
if: steps.check-js.outputs.run == 'true'
run: npm ci
shell: bash
- name: Build project
if: steps.check-js.outputs.run == 'true'
run: npm run build
shell: bash
- name: Check formatting
if: steps.check-js.outputs.run == 'true'
run: npm run format:check
shell: bash
- name: Lint project
if: steps.check-js.outputs.run == 'true'
run: npm run lint:project
shell: bash
- name: Run unit tests
if: steps.check-js.outputs.run == 'true'
id: run-unit-tests
run: npm run test:coverage
continue-on-error: true
shell: bash
- name: Get the coverage file
if: steps.check-js.outputs.run == 'true'
run: |
branch="${{ github.head_ref }}"
coverage_branch="${branch//[\":<>|*?\\\/]/-}"
coverage_dir="coverage-${coverage_branch}"
mkdir -p "${coverage_dir}" && sudo cp -r coverage "${coverage_dir}"
echo "coverage_branch=${coverage_branch}" >> $GITHUB_OUTPUT
echo "coverage_dir=${coverage_dir}" >> $GITHUB_OUTPUT
shell: bash
id: coverage
- name: Upload the coverage as an artifact
if: steps.check-js.outputs.run == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.coverage.outputs.coverage_branch }}-test-coverage
path: ${{ steps.coverage.outputs.coverage_dir }}
retention-days: 30
- name: Check if unit tests failed
if: steps.check-js.outputs.run == 'true'
run: |
if [ "${{ steps.run-unit-tests.outcome }}" == "failure" ]; then
echo "Unit tests failed."
exit 1
fi
shell: bash
- name: Default job success
if: steps.lint-docs.outputs.run == 'false' && steps.check-js.outputs.run == 'false'
run: exit 0