Skip to content
File

Blob: .github/workflows/test.yml

yaml256 lines
1name: Tests
2 
3on:
4 pull_request:
5 merge_group:
6 push:
7 branches:
8 - main
9 
10concurrency:
11 # Cancel existing builds for the same PR.
12 # Otherwise, all other builds will be allowed to run through.
13 group: test.yml-${{ github.event.pull_request.number || github.run_id }}
14 cancel-in-progress: true
15 
16permissions:
17 # Read repo
18 contents: read
19 # Read/write artifacts
20 actions: write
21 # Required for adding comments to PR.
22 # Specifically for sticky-pull-request-comment workflow action.
23 pull-requests: write
24jobs:
25 fixup:
26 if: github.event_name == 'pull_request'
27 uses: ./.github/workflows/fixup.yml
28 labels:
29 if: github.event_name == 'pull_request'
30 uses: ./.github/workflows/labels.yml
31 test:
32 strategy:
33 matrix:
34 os:
35 [
36 { name: linux, arch: X64, image: ubuntu-22.04-16core },
37 { name: linux-arm, arch: ARM64, image: ubuntu-22.04-arm-16core },
38 { name: macOS, arch: ARM64, image: macos-15-xlarge, use_lld: true },
39 { name: windows, arch: X64, image: windows-2025-16core },
40 ]
41 config: [
42 # Default build: no suffix or additional bazel arguments
43 { suffix: '' },
44 # Debug build
45 { suffix: -debug },
46 ]
47 include:
48 # Add an Address Sanitizer (ASAN) build on Linux for additional checking.
49 - os: { name: linux, arch: X64, image: ubuntu-22.04-16core }
50 config: { suffix: -asan }
51 # TODO (later): The custom Windows-debug configuration consistently runs out of disk
52 # space on CI, disable it for now. Once https://github.com/bazelbuild/bazel/issues/21615
53 # has been resolved we can likely re-enable it and possibly fold up the custom
54 # configurations, as we can more easily disable PDB file generation.
55 # - os: { name : windows, image : windows-2025 }
56 # config: { suffix: -debug, bazel-args: --config=windows_dbg }
57 exclude:
58 - os: { name: windows, arch: X64, image: windows-2025-16core }
59 config: { suffix: -debug }
60 # due to resource constraints, exclude the macOS and x64 Linux debug runners for now.
61 # linux-asan and arm64 linux-debug should provide sufficient coverage for building in the
62 # debug configuration.
63 - os: { name: macOS, arch: ARM64, image: macos-15-xlarge }
64 config: { suffix: -debug }
65 - os: { name: linux, arch: X64, image: ubuntu-22.04-16core }
66 config: { suffix: -debug }
67 # linux release is handled by separate test-linux job
68 - os: { name: linux, arch: X64, image: ubuntu-22.04-16core }
69 config: { suffix: '' }
70 fail-fast: false
71 name: test (${{ matrix.os.name }}, ${{ matrix.os.image}}${{matrix.config.suffix != '' && format(', {0}', matrix.config.suffix) || ''}})
72 uses: ./.github/workflows/_bazel.yml
73 with:
74 image: ${{ matrix.os.image }}
75 os_name: ${{ matrix.os.name }}
76 arch_name: ${{ matrix.os.arch }}
77 suffix: ${{ matrix.config.suffix }}
78 extra_bazel_args: '--config=ci-test --config=ci-${{matrix.os.name}}${{matrix.config.suffix}}'
79 macos_use_lld: ${{ matrix.os.use_lld || false }}
80 secrets:
81 BAZEL_CACHE_KEY: ${{ secrets.BAZEL_CACHE_KEY }}
82 WORKERS_MIRROR_URL: ${{ secrets.WORKERS_MIRROR_URL }}
83 GOOGLESOURCE_COOKIE: ${{ secrets.GOOGLESOURCE_COOKIE }}
84 
85 # Handled separately from `test` to speed up execution of workers-sdk-test which depends on it.
86 test-linux:
87 uses: ./.github/workflows/_bazel.yml
88 with:
89 image: ubuntu-22.04-16core
90 os_name: linux
91 arch_name: 'X64'
92 suffix: ''
93 extra_bazel_args: '--config=ci-test --config=ci-linux --config=wpt-report'
94 upload_test_logs: true
95 upload_binary: true
96 build_container_images: true
97 secrets:
98 BAZEL_CACHE_KEY: ${{ secrets.BAZEL_CACHE_KEY }}
99 WORKERS_MIRROR_URL: ${{ secrets.WORKERS_MIRROR_URL }}
100 GOOGLESOURCE_COOKIE: ${{ secrets.GOOGLESOURCE_COOKIE }}
101 
102 lint:
103 uses: ./.github/workflows/_bazel.yml
104 with:
105 extra_bazel_args: '--config=lint --config=clang-tidy --config=ci-test --config=ci-linux-common'
106 run_tests: false
107 parse_headers: true
108 secrets:
109 BAZEL_CACHE_KEY: ${{ secrets.BAZEL_CACHE_KEY }}
110 WORKERS_MIRROR_URL: ${{ secrets.WORKERS_MIRROR_URL }}
111 GOOGLESOURCE_COOKIE: ${{ secrets.GOOGLESOURCE_COOKIE }}
112 
113 check-snapshot:
114 runs-on: ubuntu-22.04-16core
115 steps:
116 - uses: actions/checkout@v6
117 with:
118 show-progress: false
119 - name: Cache
120 id: cache
121 uses: actions/cache@v5
122 # Use same cache and build configuration as release build, this allows us to keep download
123 # sizes small and generate types with optimization enabled, should be slightly faster.
124 with:
125 path: ~/bazel-disk-cache
126 key: bazel-disk-cache-release-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bazelversion', '.bazelrc', 'MODULE.bazel') }}
127 - name: Setup Runner
128 uses: ./.github/actions/setup-runner
129 with:
130 GOOGLESOURCE_COOKIE: ${{ secrets.GOOGLESOURCE_COOKIE }}
131 - name: build types
132 run: |
133 bazel build --strip=always --remote_cache=https://bazel:${{ secrets.BAZEL_CACHE_KEY }}@bazel-remote-cache.devprod.cloudflare.dev --config=ci --config=release_linux //types
134 - name: Check snapshot diff
135 run: |
136 diff -r types/generated-snapshot/latest bazel-bin/types/definitions/latest > types.diff
137 diff -r types/generated-snapshot/experimental bazel-bin/types/definitions/experimental >> types.diff
138 - name: 'Put diff on the environment'
139 if: failure()
140 id: types_diff
141 run: |
142 {
143 echo 'TYPES_DIFF<<EOF'
144 cat types.diff
145 echo EOF
146 } >> "$GITHUB_ENV"
147 - uses: actions/upload-artifact@v7
148 id: artifact-upload-step
149 with:
150 name: generated-snapshot
151 path: bazel-bin/types/definitions/
152 - name: 'Comment on PR with error details'
153 if: failure()
154 uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728
155 with:
156 message: |
157 The generated output of `@cloudflare/workers-types` has been changed by this PR. If this is intentional, run `just generate-types` to update the snapshot. Alternatively, you can download the full generated types: ${{ steps.artifact-upload-step.outputs.artifact-url }}
158
159 <details>
160 <summary>Full Type Diff</summary>
161 
162 ```diff
163 ${{ env.TYPES_DIFF }}
164 ```
165 
166 </details>
167 - name: 'Comment on PR with error details'
168 if: success()
169 uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728
170 with:
171 only_update: true
172 message: |
173 The generated output of `@cloudflare/workers-types` matches the snapshot in `types/generated-snapshot` :tada:
174
175 workers-sdk-test:
176 needs: [test-linux, check-snapshot]
177 name: Run workers-sdk tests
178 runs-on: ubuntu-22.04-16core
179 steps:
180 - name: Checkout workers-sdk
181 uses: actions/checkout@v6
182 with:
183 repository: cloudflare/workers-sdk
184 
185 - name: Install pnpm
186 uses: pnpm/action-setup@v5
187 - name: Use Node.js
188 uses: actions/setup-node@v6
189 with:
190 # Match workers-sdk node version
191 node-version: 22
192 cache: 'pnpm'
193 - name: Install workers-sdk dependencies
194 run: pnpm install
195 
196 - name: Download workerd binary
197 uses: actions/download-artifact@v8
198 with:
199 name: linux-X64-binary
200 path: /tmp
201 
202 - name: Make workerd binary executable
203 run: chmod +x /tmp/workerd
204 
205 - name: Download generated types
206 uses: actions/download-artifact@v8
207 with:
208 name: generated-snapshot
209 path: /tmp/test-types
210 
211 - name: Create and install workers-types package
212 run: |
213 cp /tmp/test-types/oldest/* /tmp/test-types
214 cat > /tmp/test-types/package.json << EOF
215 {
216 "name": "@cloudflare/workers-types"
217 }
218 EOF
219 pnpm add /tmp/test-types -w
220
221 - name: Run Wrangler unit tests
222 # Run all the wrangler unit tests besides the ConfigController ones since those
223 # are currently very flaky (the ANT team will look into stabilizing them and
224 # re-enabling them here as soon as possible, ref: https://jira.cfdata.org/browse/DEVX-2309)
225 run: pnpm test:ci --filter wrangler -- -t '^((?!(ConfigController)).)*$'
226 env:
227 MINIFLARE_WORKERD_PATH: /tmp/workerd
228 
229 - name: Run Miniflare unit tests
230 run: pnpm test:ci --filter miniflare
231 env:
232 MINIFLARE_WORKERD_PATH: /tmp/workerd
233 
234 - name: Run Vite unit tests
235 run: pnpm test:ci --filter @cloudflare/vite-plugin
236 env:
237 MINIFLARE_WORKERD_PATH: /tmp/workerd
238 
239 - name: Run Vitest unit tests
240 run: pnpm test:ci --filter="./fixtures/vitest-pool-workers-examples"
241 env:
242 MINIFLARE_WORKERD_PATH: /tmp/workerd
243 
244 - name: Run Wrangler Node.js e2e tests
245 run: pnpm test:e2e --filter wrangler -- unenv-preset
246 env:
247 MINIFLARE_WORKERD_PATH: /tmp/workerd
248 
249 wpt-report:
250 needs: [test-linux]
251 uses: ./.github/workflows/_wpt.yml
252 with:
253 image: 'ubuntu-22.04-16core'
254 logs_artifact: 'test-logs-linux-X64.zip'
255 report_artifact: 'wpt-report-linux-X64.json'