-
Notifications
You must be signed in to change notification settings - Fork 235
232 lines (220 loc) · 8.36 KB
/
ci.yml
File metadata and controls
232 lines (220 loc) · 8.36 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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: Tests
on:
push:
# Only run on pushes to main branches and long-lived feature branches
# PRs will trigger via pull_request event to avoid duplicate runs
branches:
- main
- v11.0.0
# Add any long-lived feature branches here
pull_request:
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
cache: npm
- run: npm ci
- name: linting
run: npm run lint
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20.x, 22.x]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- name: unit tests
shell: bash
run: |
if [ "${{ matrix.os }}" = "ubuntu-latest" ] && [ "${{ matrix.node-version }}" = "22.x" ]; then
npm run test:ci:unit:coverage
else
npm run test:ci:unit
fi
- name: Upload coverage reports
if: always() && github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest' && matrix.node-version == '22.x'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
retention-days: 30
- name: Coverage summary
if: always() && matrix.os == 'ubuntu-latest' && matrix.node-version == '22.x'
run: |
if [ -f coverage/lcov.info ]; then
echo "## 📊 Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Coverage |" >> $GITHUB_STEP_SUMMARY
echo "|--------|----------|" >> $GITHUB_STEP_SUMMARY
# Parse coverage from lcov.info
LINES_FOUND=$(grep -o "LF:[0-9]*" coverage/lcov.info | cut -d: -f2 | awk '{s+=$1} END {print s}')
LINES_HIT=$(grep -o "LH:[0-9]*" coverage/lcov.info | cut -d: -f2 | awk '{s+=$1} END {print s}')
FUNCS_FOUND=$(grep -o "FNF:[0-9]*" coverage/lcov.info | cut -d: -f2 | awk '{s+=$1} END {print s}')
FUNCS_HIT=$(grep -o "FNH:[0-9]*" coverage/lcov.info | cut -d: -f2 | awk '{s+=$1} END {print s}')
BRANCHES_FOUND=$(grep -o "BRF:[0-9]*" coverage/lcov.info | cut -d: -f2 | awk '{s+=$1} END {print s}')
BRANCHES_HIT=$(grep -o "BRH:[0-9]*" coverage/lcov.info | cut -d: -f2 | awk '{s+=$1} END {print s}')
LINES_PCT=$(awk "BEGIN {printf \"%.2f\", ($LINES_HIT/$LINES_FOUND)*100}")
FUNCS_PCT=$(awk "BEGIN {printf \"%.2f\", ($FUNCS_HIT/$FUNCS_FOUND)*100}")
BRANCHES_PCT=$(awk "BEGIN {printf \"%.2f\", ($BRANCHES_HIT/$BRANCHES_FOUND)*100}")
echo "| Lines | ${LINES_PCT}% (${LINES_HIT}/${LINES_FOUND}) |" >> $GITHUB_STEP_SUMMARY
echo "| Functions | ${FUNCS_PCT}% (${FUNCS_HIT}/${FUNCS_FOUND}) |" >> $GITHUB_STEP_SUMMARY
echo "| Branches | ${BRANCHES_PCT}% (${BRANCHES_HIT}/${BRANCHES_FOUND}) |" >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ Coverage report not found" >> $GITHUB_STEP_SUMMARY
fi
base-coverage:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
cache: npm
- name: Check if base branch uses npm
id: check_npm
run: |
if [ -f "package-lock.json" ]; then
echo "uses_npm=true" >> $GITHUB_OUTPUT
else
echo "uses_npm=false" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
if: steps.check_npm.outputs.uses_npm == 'true'
run: npm ci
- name: Run tests on base branch with full coverage
if: steps.check_npm.outputs.uses_npm == 'true'
run: |
if npm run | grep -q 'test:ci:unit:coverage$'; then
npm run test:ci:unit:coverage
elif npm run | grep -q 'test:unit:justTest:ci:coverage$'; then
npm run pretest && npm run test:unit:justTest:ci:coverage
else
echo "Coverage script not found in base branch, skipping coverage check"
mkdir -p coverage
echo "No coverage data available for base branch" > coverage/README.md
fi
- name: Create placeholder coverage for yarn-based base
if: steps.check_npm.outputs.uses_npm == 'false'
run: |
echo "Base branch uses yarn, skipping coverage generation"
mkdir -p coverage
echo "No coverage data available for base branch (uses yarn)" > coverage/README.md
- name: Upload base coverage
uses: actions/upload-artifact@v6
with:
name: coverage-base
path: coverage/
retention-days: 1
coverage-check:
runs-on: ubuntu-latest
needs: [test, base-coverage]
if: github.event_name == 'pull_request' && needs.test.result == 'success' && needs.base-coverage.result == 'success'
steps:
- uses: actions/checkout@v6
- name: Download PR coverage
uses: actions/download-artifact@v7
with:
name: coverage-report
path: coverage-pr/
- name: Download base coverage
uses: actions/download-artifact@v7
with:
name: coverage-base
path: coverage-base/
- name: Compare coverage and fail if decreased
run: |
if [ -f coverage-base/lcov.info ]; then
./scripts/ci/compare-coverage.sh coverage-pr coverage-base --fail-on-decrease
else
echo "Base coverage not available, skipping comparison"
echo "⚠️ Coverage comparison skipped - base branch does not have compatible test scripts" >> $GITHUB_STEP_SUMMARY
fi
integration:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20.x, 22.x]
os: [ubuntu-latest]
environment: AcceptanceTests
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
ENABLE_NET_CONNECT: true
steps:
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- name: Run cli package integration tests
run: npm run test:ci:integration
acceptance:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20.x, 22.x]
os: [ubuntu-latest]
environment: AcceptanceTests
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
ENABLE_NET_CONNECT: true
steps:
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
# on 'main' and 'release-' branches, these tests will be run as part of the acceptance tests.
- name: run smoke tests
if: github.ref_name != 'main' || !startsWith(github.ref_name, 'release-')
run: npm run test:ci:smoke
# only run the full suite of acceptance tests on 'main' and 'release-' branches
- name: run acceptance tests
if: github.ref_name == 'main' || startsWith(github.ref_name, 'release-')
run: npm run test:ci:acceptance
spell-check:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [22.x]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- run: npm install cspell@9.2.1
- name: Run spell check on changed files
run: |
git fetch origin main:refs/remotes/origin/main --quiet
git diff origin/main...HEAD --diff-filter=d --name-only | npm run cspell:ci
# dummy job needed to pass changeling compliance because it only watches one build
done:
runs-on: macos-latest
needs: [lint, test, integration, acceptance]
steps:
- run: echo done
working-directory: /