-
Notifications
You must be signed in to change notification settings - Fork 1
205 lines (178 loc) · 6.66 KB
/
Copy pathci.yml
File metadata and controls
205 lines (178 loc) · 6.66 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
name: ci
on:
push:
branches: [main]
pull_request:
merge_group:
workflow_dispatch:
permissions:
contents: read
pull-requests: read # for dorny/paths-filter in changes job
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
changes:
# Detect whether source code changed. On non-PR events the job is skipped
# (result == 'skipped'), causing downstream jobs to run via the condition below.
# This pattern is used successfully in patchloom and attune-io/attune.
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
code: ${{ steps.filter.outputs.code }}
steps:
- uses: dorny/paths-filter@7b450fff21473bca461d4b92ce414b9d0420d706 # v4.0.2
id: filter
with:
filters: |
code:
- 'src/**'
- 'test/**'
- 'scripts/**'
- 'package.json'
- 'package-lock.json'
- 'tsconfig*.json'
- '.nvmrc'
- '.github/actions/**'
- '.github/workflows/**' # any workflow change is "code" (fixes auto-approve.yml etc. being skipped)
unit-test:
needs: [changes]
if: always() && (needs.changes.result == 'skipped' || needs.changes.outputs.code == 'true')
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- name: Harden runner
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: Run tests
run: npm test
- name: Check code coverage
if: matrix.os == 'ubuntu-latest'
id: coverage
run: |
output=$(npm run test:coverage 2>&1)
echo "$output"
pct=$(echo "$output" | grep 'all files' | head -1 | awk -F'|' '{gsub(/[[:space:]]/, "", $2); print $2}')
echo "percentage=$pct" >> "$GITHUB_OUTPUT"
- name: Determine badge color
if: matrix.os == 'ubuntu-latest'
id: color
run: |
pct="${{ steps.coverage.outputs.percentage }}"
int_pct=${pct%.*}
if [ "$int_pct" -ge 90 ]; then
echo "color=brightgreen" >> "$GITHUB_OUTPUT"
elif [ "$int_pct" -ge 80 ]; then
echo "color=green" >> "$GITHUB_OUTPUT"
elif [ "$int_pct" -ge 70 ]; then
echo "color=yellowgreen" >> "$GITHUB_OUTPUT"
elif [ "$int_pct" -ge 60 ]; then
echo "color=yellow" >> "$GITHUB_OUTPUT"
else
echo "color=red" >> "$GITHUB_OUTPUT"
fi
- name: Update coverage badge
if: matrix.os == 'ubuntu-latest' && github.event_name == 'push' && github.ref == 'refs/heads/main'
continue-on-error: true
uses: schneegans/dynamic-badges-action@0e50b8bad39e7e1afd3e4e9c2b7dd145fad07501 # v1.8.0
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: d01e4551b744b77e2927555e43a4b935
filename: coverage.json
label: coverage
message: ${{ steps.coverage.outputs.percentage }}%
color: ${{ steps.color.outputs.color }}
build:
needs: [changes]
if: always() && (needs.changes.result == 'skipped' || needs.changes.outputs.code == 'true')
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Harden runner
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: Compile
run: npm run compile
- name: Package extension
run: npm run package
integration-test:
needs: [changes, unit-test, build]
if: always() && (needs.changes.result == 'skipped' || needs.changes.outputs.code == 'true')
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- name: Harden runner
if: runner.os == 'Linux'
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: Compile extension and tests
run: npm run compile && npm run compile-tests
- name: Run extension integration tests (Linux)
if: runner.os == 'Linux'
run: xvfb-run -a npm run test:extension
- name: Run extension integration tests
if: runner.os != 'Linux'
run: npm run test:extension
- name: Setup UI test VS Code
run: npx extest setup-tests --code_version max --extensions_dir .vscode-test/extensions
- name: Patch test VS Code to run as background app
run: bash scripts/hide-test-vscode.sh
- name: Run UI tests (Linux)
if: runner.os == 'Linux'
run: xvfb-run -a npx extest run-tests './out-uitest/test/ui/*.test.js' --extensions_dir .vscode-test/extensions
- name: Run UI tests
if: runner.os != 'Linux'
run: npx extest run-tests './out-uitest/test/ui/*.test.js' --extensions_dir .vscode-test/extensions
ci:
# Final gate job (if: always()). This is the recommended pattern (see patchloom
# and attune) so that individual matrix jobs can use the changes filter without
# breaking required status checks or Scorecard parsing.
if: always()
needs:
- unit-test
- build
- integration-test
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: All CI jobs passed (or were correctly skipped for docs-only change)
run: |
results=("${{ needs.unit-test.result }}" "${{ needs.build.result }}" "${{ needs.integration-test.result }}")
for r in "${results[@]}"; do
if [[ "$r" != "success" && "$r" != "skipped" ]]; then
echo "FAILED: dependency reported '$r'"
exit 1
fi
done
echo "CI gate passed."