@@ -25,13 +25,14 @@ jobs: |
25 | 25 | name: affected packages |
26 | 26 | runs-on: blacksmith-4vcpu-ubuntu-2404 |
27 | 27 | outputs: |
28 | | - app: ${{ steps.packages.outputs.app }} |
| 28 | + e2e: ${{ steps.packages.outputs.app == 'true' && github.ref_name != 'dev' && github.head_ref != 'dev' }} |
29 | 29 | steps: |
30 | 30 | - name: Checkout repository |
31 | 31 | uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
32 | 32 | with: |
33 | 33 | token: ${{ secrets.GITHUB_TOKEN }} |
34 | | - fetch-depth: 0 |
| 34 | + # Pull requests diff against the merge's first parent; pushes diff against the previous dev head. |
| 35 | + fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} |
35 | 36 |
|
36 | 37 | - name: Setup Bun |
37 | 38 | uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 |
|
48 | 49 | echo "app=true" >> "$GITHUB_OUTPUT" |
49 | 50 | exit 0 |
50 | 51 | fi |
51 | | - bun x [email protected] ls --affected --filter=@opencode/app --output=json > affected.json |
| 52 | + # Storybook hosts the component tests, but no app package depends on it. |
| 53 | + bun x [email protected] ls --affected --filter=@opencode/app --filter=@opencode/storybook --output=json > affected.json |
52 | 54 | bun -e 'const result = await Bun.file("affected.json").json(); console.log(`app=${result.packages.count > 0}`)' >> "$GITHUB_OUTPUT" |
53 | 55 |
|
54 | 56 | unit: |
|
70 | 72 | uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
71 | 73 | with: |
72 | 74 | token: ${{ secrets.GITHUB_TOKEN }} |
73 | | - fetch-depth: 0 |
| 75 | + # Pull requests diff against the merge's first parent; pushes diff against the previous dev head. |
| 76 | + fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} |
74 | 77 |
|
75 | 78 | - name: Setup Node |
76 | 79 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
|
93 | 96 | |
94 | 97 | git config --global user.name "opencode" |
95 | 98 |
|
96 | | - - name: Cache Turbo |
97 | | - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
98 | | - with: |
99 | | - path: node_modules/.cache/turbo |
100 | | - key: turbo-${{ runner.os }}-${{ hashFiles('turbo.json', '**/package.json') }}-${{ github.sha }} |
101 | | - restore-keys: | |
102 | | - turbo-${{ runner.os }}-${{ hashFiles('turbo.json', '**/package.json') }}- |
103 | | - turbo-${{ runner.os }}- |
104 | | -
|
105 | 99 | - name: Run unit tests |
106 | 100 | timeout-minutes: 20 |
107 | 101 | run: | |
@@ -134,8 +128,42 @@ jobs: |
134 | 128 | TURBO_SCM_BASE: ${{ github.event_name == 'pull_request' && format('{0}^1', github.sha) || github.event.before }} |
135 | 129 | TURBO_SCM_HEAD: ${{ github.sha }} |
136 | 130 |
|
| 131 | + - name: Check generated client |
| 132 | + if: runner.os == 'Linux' |
| 133 | + working-directory: packages/client |
| 134 | + run: bun run check:generated |
| 135 | + |
| 136 | + - name: Check generated documentation |
| 137 | + if: runner.os == 'Linux' |
| 138 | + working-directory: services/www |
| 139 | + run: bun run check:generated |
| 140 | + |
| 141 | + build: |
| 142 | + name: build (${{ matrix.settings.name }}) |
| 143 | + strategy: |
| 144 | + fail-fast: false |
| 145 | + matrix: |
| 146 | + settings: |
| 147 | + - name: linux |
| 148 | + host: blacksmith-4vcpu-ubuntu-2404 |
| 149 | + - name: windows |
| 150 | + host: blacksmith-4vcpu-windows-2025 |
| 151 | + runs-on: ${{ matrix.settings.host }} |
| 152 | + defaults: |
| 153 | + run: |
| 154 | + shell: bash |
| 155 | + steps: |
| 156 | + - name: Checkout repository |
| 157 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 158 | + with: |
| 159 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 160 | + # Pull requests diff against the merge's first parent; pushes diff against the previous dev head. |
| 161 | + fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} |
| 162 | + |
| 163 | + - name: Setup Bun |
| 164 | + uses: ./.github/actions/setup-bun |
| 165 | + |
137 | 166 | - name: Verify compiled service lifecycle |
138 | | - if: always() |
139 | 167 | timeout-minutes: 10 |
140 | 168 | working-directory: packages/cli |
141 | 169 | env: |
@@ -144,14 +172,30 @@ jobs: |
144 | 172 | bun run script/build.ts --single --skip-install |
145 | 173 | bun run script/service-smoke.ts |
146 | 174 |
|
| 175 | + # Unit tests import workspace sources and never build the libraries they use, so this checks those builds. The |
| 176 | + # CLI and app closures hold every library a tested package depends on. The builds are tsc and Bun.build with no |
| 177 | + # platform-specific steps, and the libraries publish from Linux, so Windows skips them. |
| 178 | + - name: Build workspace libraries |
| 179 | + if: ${{ !cancelled() && runner.os == 'Linux' }} |
| 180 | + timeout-minutes: 10 |
| 181 | + run: | |
| 182 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 183 | + bun turbo build --concurrency=3 --filter='@opencode/cli^...' --filter='@opencode/app^...' |
| 184 | + exit 0 |
| 185 | + fi |
| 186 | + bun turbo build --affected --concurrency=3 --filter='@opencode/cli^...' --filter='@opencode/app^...' |
| 187 | + env: |
| 188 | + TURBO_SCM_BASE: ${{ github.event_name == 'pull_request' && format('{0}^1', github.sha) || github.event.before }} |
| 189 | + TURBO_SCM_HEAD: ${{ github.sha }} |
| 190 | + |
147 | 191 | - name: Setup Node build runtime |
148 | | - if: always() |
| 192 | + if: ${{ !cancelled() }} |
149 | 193 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
150 | 194 | with: |
151 | 195 | node-version: "26.4.0" |
152 | 196 |
|
153 | 197 | - name: Verify Node build |
154 | | - if: always() |
| 198 | + if: ${{ !cancelled() }} |
155 | 199 | timeout-minutes: 15 |
156 | 200 | working-directory: packages/cli |
157 | 201 | env: |
@@ -160,19 +204,10 @@ jobs: |
160 | 204 | bun run script/build-node.ts --single --skip-install --outdir=dist/node |
161 | 205 | bun run script/service-smoke.ts --node |
162 | 206 |
|
163 | | - - name: Check generated client |
164 | | - if: runner.os == 'Linux' |
165 | | - working-directory: packages/client |
166 | | - run: bun run check:generated |
167 | | - |
168 | | - - name: Check generated documentation |
169 | | - if: runner.os == 'Linux' |
170 | | - working-directory: services/www |
171 | | - run: bun run check:generated |
172 | | - |
173 | | - e2e: |
174 | | - name: e2e (${{ matrix.settings.name }}) |
| 207 | + e2e-suite: |
| 208 | + name: e2e (${{ matrix.settings.name }}, ${{ matrix.suite.id }}) |
175 | 209 | needs: affected |
| 210 | + if: needs.affected.outputs.e2e == 'true' |
176 | 211 | strategy: |
177 | 212 | fail-fast: false |
178 | 213 | matrix: |
@@ -181,88 +216,93 @@ jobs: |
181 | 216 | host: blacksmith-4vcpu-ubuntu-2404 |
182 | 217 | - name: windows |
183 | 218 | host: blacksmith-4vcpu-windows-2025 |
| 219 | + # Playwright splits whole spec files across shards by test count, not duration. Every app-N |
| 220 | + # entry must use the same total, and the entries must cover 1..total. The service worker suite |
| 221 | + # reuses shard 2's production build. Each component suite runs once per OS in its own leg, so the |
| 222 | + # two suites' Storybook servers and test time are not added up on one runner. |
| 223 | + suite: |
| 224 | + - id: app-1 |
| 225 | + shard: 1/2 |
| 226 | + - id: app-2 |
| 227 | + shard: 2/2 |
| 228 | + - id: session-ui-components |
| 229 | + - id: app-components |
184 | 230 | runs-on: ${{ matrix.settings.host }} |
185 | 231 | env: |
186 | | - E2E_ENABLED: ${{ needs.affected.outputs.app == 'true' && github.ref_name != 'dev' && github.head_ref != 'dev' }} |
187 | 232 | PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.playwright-browsers |
188 | 233 | defaults: |
189 | 234 | run: |
190 | 235 | shell: bash |
191 | 236 | steps: |
192 | 237 | - name: Checkout repository |
193 | | - if: env.E2E_ENABLED == 'true' |
194 | 238 | uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
195 | 239 | with: |
196 | 240 | token: ${{ secrets.GITHUB_TOKEN }} |
197 | 241 |
|
198 | 242 | - name: Setup Node |
199 | | - if: env.E2E_ENABLED == 'true' |
200 | 243 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
201 | 244 | with: |
202 | 245 | # Playwright 1.59 hangs while extracting Chromium with Node 24.16. |
203 | 246 | node-version: "24.15" |
204 | 247 |
|
205 | 248 | - name: Setup Bun |
206 | | - if: env.E2E_ENABLED == 'true' |
207 | 249 | uses: ./.github/actions/setup-bun |
208 | 250 |
|
209 | 251 | - name: Read Playwright version |
210 | | - if: env.E2E_ENABLED == 'true' |
211 | 252 | id: playwright-version |
212 | 253 | run: | |
213 | 254 | version=$(node -e 'console.log(require("./package.json").workspaces.catalog["@playwright/test"])') |
214 | 255 | echo "version=$version" >> "$GITHUB_OUTPUT" |
215 | 256 |
|
216 | 257 | - name: Cache Playwright browsers |
217 | | - if: env.E2E_ENABLED == 'true' |
218 | 258 | id: playwright-cache |
219 | 259 | uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
220 | 260 | with: |
221 | 261 | path: ${{ github.workspace }}/.playwright-browsers |
222 | 262 | key: ${{ runner.os }}-${{ runner.arch }}-playwright-${{ steps.playwright-version.outputs.version }}-chromium |
223 | 263 |
|
224 | 264 | - name: Install Playwright system dependencies |
225 | | - if: env.E2E_ENABLED == 'true' && runner.os == 'Linux' |
| 265 | + if: runner.os == 'Linux' |
226 | 266 | working-directory: packages/app |
227 | 267 | run: bunx playwright install-deps chromium |
228 | 268 |
|
229 | 269 | - name: Install Playwright browsers |
230 | | - if: env.E2E_ENABLED == 'true' && steps.playwright-cache.outputs.cache-hit != 'true' |
| 270 | + if: steps.playwright-cache.outputs.cache-hit != 'true' |
231 | 271 | working-directory: packages/app |
232 | 272 | run: bunx playwright install chromium |
233 | 273 |
|
234 | 274 | - name: Run app e2e tests against production build |
235 | | - if: env.E2E_ENABLED == 'true' |
236 | | - run: bun --cwd packages/app test:e2e:built |
| 275 | + if: matrix.suite.shard |
| 276 | + run: bun --cwd packages/app test:e2e:built --shard=${{ matrix.suite.shard }} |
237 | 277 | env: |
238 | 278 | CI: true |
239 | | - timeout-minutes: 30 |
| 279 | + timeout-minutes: 15 |
240 | 280 |
|
241 | 281 | - name: Verify service worker precaching and upgrades |
242 | | - if: env.E2E_ENABLED == 'true' |
| 282 | + if: matrix.suite.shard == '2/2' |
243 | 283 | working-directory: packages/app |
244 | 284 | run: bunx playwright test --config e2e/service-worker/playwright.config.ts |
245 | 285 | timeout-minutes: 5 |
246 | 286 |
|
247 | 287 | - name: Run session UI component tests |
248 | | - if: ${{ !cancelled() && env.E2E_ENABLED == 'true' }} |
| 288 | + if: matrix.suite.id == 'session-ui-components' |
249 | 289 | run: bun --cwd packages/session-ui test:components |
250 | 290 | env: |
251 | 291 | CI: true |
252 | 292 | timeout-minutes: 15 |
253 | 293 |
|
254 | 294 | - name: Run app component tests |
255 | | - if: ${{ !cancelled() && env.E2E_ENABLED == 'true' }} |
| 295 | + if: matrix.suite.id == 'app-components' |
256 | 296 | run: bun --cwd packages/app test:components |
257 | 297 | env: |
258 | 298 | CI: true |
259 | 299 | timeout-minutes: 15 |
260 | 300 |
|
261 | 301 | - name: Upload Playwright artifacts |
262 | | - if: always() && env.E2E_ENABLED == 'true' |
| 302 | + if: always() |
263 | 303 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
264 | 304 | with: |
265 | | - name: playwright-${{ matrix.settings.name }}-${{ github.run_attempt }} |
| 305 | + name: playwright-${{ matrix.settings.name }}-${{ matrix.suite.id }}-${{ github.run_attempt }} |
266 | 306 | if-no-files-found: ignore |
267 | 307 | retention-days: 7 |
268 | 308 | path: | |
@@ -272,3 +312,24 @@ jobs: |
272 | 312 | packages/session-ui/component-tests/playwright-report |
273 | 313 | packages/app/component-tests/test-results |
274 | 314 | packages/app/component-tests/playwright-report |
| 315 | +
|
| 316 | + # Branch rules require one e2e check per OS. These keep those names and pass only when every |
| 317 | + # leg above passed, or when no leg was needed; a failing leg on either OS fails both checks. |
| 318 | + e2e: |
| 319 | + name: e2e (${{ matrix.os }}) |
| 320 | + needs: [affected, e2e-suite] |
| 321 | + if: ${{ !cancelled() }} |
| 322 | + strategy: |
| 323 | + fail-fast: false |
| 324 | + matrix: |
| 325 | + os: [linux, windows] |
| 326 | + runs-on: blacksmith-4vcpu-ubuntu-2404 |
| 327 | + steps: |
| 328 | + - name: Check browser test results |
| 329 | + env: |
| 330 | + AFFECTED: ${{ needs.affected.result }} |
| 331 | + SUITES: ${{ needs.e2e-suite.result }} |
| 332 | + EXPECTED: ${{ needs.affected.outputs.e2e == 'true' && 'success' || 'skipped' }} |
| 333 | + run: | |
| 334 | + echo "affected packages: $AFFECTED, browser test legs: $SUITES (expected $EXPECTED)" |
| 335 | + test "$AFFECTED" = success && test "$SUITES" = "$EXPECTED" |