mirror of
https://github.com/owncloud/ocis.git
synced 2026-10-23 23:29:02 +03:00
feat(web): adopt Nx as task orchestrator for web/ Introduces Nx on top of the existing pnpm workspace, so lint/typecheck/ test can be scoped to only the projects affected by a change instead of running against the whole monorepo on every PR. - Phase 0: add nx (^23.2.1) as a workspace devDependency, nx.json with a targetDefaults entry for test:unit (cache: true), ignore .nx/cache and .nx/workspace-data. No behavior change to any existing script. - Phase 1: register @nx/vitest's inference plugin so every package with a vitest.config.ts gets a real, cached "test" target read directly from its own config, not just the packages that happened to already declare a "test:unit" npm script. Excludes vite.config.common.ts, the root vite.config.ts and vite.cern.config.ts from the plugin's default glob - none of them are test configs, and loading them as one aborts the whole project graph. defaultBase: "master" (bare `nx affected` defaults to a branch named "main"). testMode: "run" so `nx run <project>:test` doesn't default to vitest's watch mode locally. - Phase 2a: register @nx/eslint/plugin for a per-project "lint" target on every project (root `lint` script untouched). - Phase 2b: register @nx/vite/plugin's typecheckTargetName for a per-project "typecheck" target on projects with their own real vite.config.ts (design-system, web-client, web-pkg, web-test-helpers). The ~20 web-app-*/web-runtime projects only have a vitest.config.ts and aren't covered; root `pnpm run check:types` (whole-repo vue-tsc) stays the one check that covers everything. - Phase 3 (CI): adds a `full-run` output to detect-web-changes - true for push to master/stable-* or a `[full-ci]` PR title (unchanged behavior), false for a normal PR, which instead runs `nx affected -t lint` / `nx affected -t test --base=<PR base sha>`. Added fetch-depth: 0 to web-build-test's checkout, needed for `nx affected --base=<sha>` to find that commit. Check types and the full-run unit-test path deliberately stay whole-repo (see inline comments for why). Also: - removes design-system's broken "lint": "lint:stylelint" alias (needed the "lint" name free for the new per-project target; it was never callable as written - "lint:stylelint" isn't a binary - and nothing called it). - makes the design system's webfontloader import fire-and-forget so an in-flight rejection at test teardown doesn't surface as an unhandled rejection under vitest's per-project runs. - pin `typescript` via `pnpm.overrides`. Adding nx's own devDependencies makes pnpm re-resolve the workspace's peer graph, and today's registry now has a typescript 6.x that some peer ranges accept - without the pin, half the vue-peer-dependent packages (pinia, vue-router, vue3-gettext, focus-trap-vue, ...) fork into a second, incompatible module instance. Same pin as the dependency-cycle fix, for an unrelated reason; needed independently here since this branch changes package.json on its own. nx's `dependsOn: ["^target"]` errors outright on a circular task graph, so this only works once the pre-existing web-pkg/design-system/ web-test-helpers dependency cycle is fixed - see fix(web): break web-pkg/design-system/web-test-helpers dependency cycle, which this PR targets rather than master. Verified: nx run-many -t test / lint / typecheck succeed for all projects; nx show projects --affected --files=... resolves correctly for shared config changes; nx affected -t lint --base=<sha> matches pnpm lint; root pnpm lint/check:types/check:format/test:unit/build all still pass unchanged (380 files / 3128 tests).
140 lines
4.4 KiB
YAML
140 lines
4.4 KiB
YAML
name: Web Tests
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches: [master, stable-*]
|
|
|
|
jobs:
|
|
detect-web-changes:
|
|
name: detect-web-changes
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
outputs:
|
|
web-changed: ${{ steps.check.outputs.web-changed }}
|
|
full-run: ${{ steps.check.outputs.full-run }}
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Check if web/ changed
|
|
id: check
|
|
env:
|
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
|
run: |
|
|
# full-run: push to master/stable-* or an explicit [full-ci] request always run
|
|
# everything, unscoped - same as before Nx. A normal PR gets the affected-scoped
|
|
# path instead (see web-build-test), since only those two cases actually need every
|
|
# project checked.
|
|
if [[ "${{ github.event_name }}" == "push" ]]; then
|
|
echo "web-changed=true" >> "$GITHUB_OUTPUT"
|
|
echo "full-run=true" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
if echo "$PR_TITLE" | grep -qi "\[full-ci\]"; then
|
|
echo "web-changed=true" >> "$GITHUB_OUTPUT"
|
|
echo "full-run=true" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
echo "full-run=false" >> "$GITHUB_OUTPUT"
|
|
|
|
CHANGED_FILES=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}" 2>/dev/null || git diff --name-only HEAD~1)
|
|
|
|
WEB_CHANGED=false
|
|
while IFS= read -r file; do
|
|
case "$file" in
|
|
web/*) WEB_CHANGED=true; break ;;
|
|
.github/workflows/web-tests.yml) WEB_CHANGED=true; break ;;
|
|
esac
|
|
done <<< "$CHANGED_FILES"
|
|
|
|
echo "web-changed=$WEB_CHANGED" >> "$GITHUB_OUTPUT"
|
|
echo "web/ changed: $WEB_CHANGED"
|
|
|
|
web-build-test:
|
|
name: web-build-test
|
|
needs: [detect-web-changes]
|
|
if: needs.detect-web-changes.outputs.web-changed == 'true'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 60
|
|
defaults:
|
|
run:
|
|
working-directory: web
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
# nx affected --base=<pr-base-sha> (used below) needs that commit present locally
|
|
fetch-depth: 0
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
|
with:
|
|
version: 10.33.3
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
|
with:
|
|
node-version: 24.15.0
|
|
cache: pnpm
|
|
cache-dependency-path: web/pnpm-lock.yaml
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install
|
|
|
|
- name: Check licenses
|
|
run: pnpm licenses:check
|
|
|
|
- name: Save licenses
|
|
run: pnpm licenses:csv && pnpm licenses:save
|
|
|
|
- name: Check types
|
|
# Whole-repo, unconditional: only 5/27 projects have a per-project typecheck target
|
|
# (nx/vite's typecheck inference needs a project's own vite.config.ts, which most
|
|
# web-app-* packages don't have), so `nx affected -t typecheck` can't safely stand
|
|
# in for this yet.
|
|
run: pnpm check:types
|
|
|
|
- name: Check format
|
|
run: pnpm check:format
|
|
|
|
- name: Lint
|
|
env:
|
|
FULL_RUN: ${{ needs.detect-web-changes.outputs.full-run }}
|
|
run: |
|
|
if [[ "$FULL_RUN" == "true" ]]; then
|
|
pnpm lint
|
|
else
|
|
pnpm exec nx affected -t lint --base="${{ github.event.pull_request.base.sha }}"
|
|
fi
|
|
|
|
- name: Run unit tests
|
|
env:
|
|
FULL_RUN: ${{ needs.detect-web-changes.outputs.full-run }}
|
|
run: |
|
|
if [[ "$FULL_RUN" == "true" ]]; then
|
|
pnpm test:unit --coverage
|
|
else
|
|
pnpm exec nx affected -t test --base="${{ github.event.pull_request.base.sha }}"
|
|
fi
|
|
|
|
- name: Build
|
|
run: pnpm build
|
|
|
|
web-tests-passed:
|
|
name: web-tests-passed
|
|
needs: [detect-web-changes, web-build-test]
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
if: always()
|
|
steps:
|
|
- name: Check web-build-test passed or was skipped
|
|
run: |
|
|
if [[ "${{ needs.web-build-test.result }}" == "failure" || "${{ needs.web-build-test.result }}" == "cancelled" ]]; then
|
|
exit 1
|
|
fi
|