Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 69 additions & 76 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ name: CI
# The gate every change goes through, on every push and every pull request, so a branch that cannot
# merge says so before anybody reviews it.
#
# Two stages. Build compiles every package something else depends on, exactly once, and saves what
# turbo produced. Lint, typecheck and every test job then restore that and run against it. The
# `^build` each of their tasks depends on is answered from the cache rather than compiled again, so
# nothing after the build stage rebuilds anything.
#
# One build job rather than one per package, deliberately. The packages form a chain — contracts,
# then core, then client, then screens — and a job per link would wait on the link before it, paying
# a runner's checkout and install at every step of a graph that compiles end to end in seconds. Each
# package's build is still its own turbo task with its own block in the log; they share a runner
# because splitting them would cost minutes to save seconds.
# One stage. Every job starts as soon as the changes are known, rather than waiting on a build job
# first: each restores the newest turbo cache an earlier run left, and the `^build` its tasks depend
# on is answered from it for every package that has not changed, so a job builds only what this
# change touched — seconds, where waiting on a build job of its own cost the whole run a minute and a
# half. Lint and typecheck build every package anyway, so that job leaves this commit's builds in the
# cache for the runs after it.
#
# The large suites are sharded, each shard on a runner of its own: @valence/screens six ways,
# @valence/server four and @valence/client three, with @valence/ui as a single shard in the same
# matrix. The small packages share one runner, two at a time, because each of
# them spends longer installing than testing and a runner apiece queued the large shards behind
# them. Two at a time rather than all at once: turbo and vitest each size their worker pool to the
# machine's CPU count, and every package at once on a handful of cores thrashes.
# @valence/server four and @valence/client three, with @valence/ui, @valence/mobile and @valence/tv
# as single shards in the same matrix. The phone and the television are not split further: most of
# their time is Babel compiling React Native, which a second shard would only do again, so instead
# Jest's compiled files are kept between runs. The small packages share two runners, two at a
# time, because each of them spends longer installing than testing: @valence/landing, the slowest of
# them, with the quick ones, and the rest on the other. Two at a time rather than all at once: turbo
# and vitest each size their worker pool to the machine's CPU count, and every package at once on a
# handful of cores thrashes. The split keeps a full run within the twenty jobs GitHub runs at once,
# so no shard waits for a runner.
#
# Test results outlive the run. Turbo already caches a passing test task by its inputs, and each
# test job keeps those results in the Actions cache and restores them next time, so a package or a
Expand Down Expand Up @@ -56,7 +56,9 @@ jobs:
# The workspace answers which packages are affected, counting the ones that depend on a changed
# one, so this file holds no list of who depends on whom to keep in step with the packages. It
# needs the history to compare against but not an install, which is what makes it cheap enough
# to be worth asking. A change to a file at the root, other than the notes and the workflows that
# to be worth asking. The history comes without the contents of any file: which files changed is
# read from the trees alone, and a full clone spent most of this job's time fetching blobs it never
# read. A change to a file at the root, other than the notes and the workflows that
# belong to other pipelines, reads as touching the workspace itself, and that runs everything.
changes:
name: Detect changed areas
Expand All @@ -73,6 +75,7 @@ jobs:
with:
persist-credentials: false
fetch-depth: 0
filter: blob:none

- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10

Expand Down Expand Up @@ -148,60 +151,28 @@ jobs:
fi

# The large suites, each split into the shards its size calls for, and the rest for the
# one runner the small packages share.
# two runners the small packages share: the slowest of them with the quick ones, and the
# others together.
sharded='{"@valence/server":4,"@valence/client":3,"@valence/ui":1,"@valence/mobile":1,"@valence/tv":1}'
beside_landing='["@valence/landing","@valence/web","@valence/brand","@valence/lint","@valence/plugin-sdk","@valence/i18n","@valence/transcoder"]'
{
echo "light=$(echo "$packages" | jq -c --argjson sharded "$sharded" '[.[] | select(. as $name | $sharded | has($name) | not)]')"
echo "light=$(echo "$packages" | jq -c --argjson sharded "$sharded" --argjson beside "$beside_landing" '
[.[] | select(. as $name | $sharded | has($name) | not)] as $light
| [ {group: "landing", packages: [$light[] | select(. as $name | $beside | index($name))]},
{group: "rest", packages: [$light[] | select(. as $name | $beside | index($name) | not)]} ]
| map(select(.packages | length > 0))')"
echo "shards=$(echo "$packages" | jq -c --argjson sharded "$sharded" --arg screens "$screens" '
[ (.[] | select(. as $name | $sharded | has($name)) | . as $name | range(1; $sharded[$name] + 1) | {package: $name, shard: ., of: $sharded[$name]}),
(if $screens == "true" then range(1; 7) | {package: "@valence/screens", shard: ., of: 6} else empty end) ]')"
} >> "$GITHUB_OUTPUT"

build:
name: Build shared packages
needs: changes
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10

- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
cache: pnpm

- run: pnpm install --frozen-lockfile

# Every package some other package's typecheck or test task needs as a `^build` dependency.
# Never a leaf app: nothing depends on one, and building one here would be waste (for
# `apps/web` today it would also surface a real but unrelated strictness gap between its own
# build and its typecheck script, worth its own fix).
- run: >-
pnpm turbo run build
--filter=@valence/i18n
--filter=@valence/contracts
--filter=@valence/core
--filter=@valence/plugin-sdk
--filter=@valence/ui
--filter=@valence/client
--filter=@valence/screens

# Keyed on the commit rather than on source hashes: this cache only has to outlive the jobs in
# this one run, every one of which wants exactly what this commit built.
- uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}

# Lint and typecheck share a runner. Lint needs no build and could start sooner, but a runner of
# its own held a slot through the minute the test shards all want one at once.
# its own held a slot through the minute the test shards all want one at once. Typecheck builds
# every package, so this job is also the one that leaves this commit's builds in the cache.
typecheck:
name: Lint, typecheck and migration check
needs: [changes, build]
needs: changes
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -221,7 +192,7 @@ jobs:
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}
fail-on-cache-miss: true
restore-keys: turbo-build-

- run: pnpm lint

Expand All @@ -233,14 +204,25 @@ jobs:

- run: pnpm typecheck

# Every small package on one runner, two at a time.
# Keyed on the commit: the next run on this branch, or on a branch cut from it, restores the
# newest of these and rebuilds only what changed since.
- uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}

# The small packages on two runners, two at a time on each.
test:
name: Test the smaller packages
needs: [changes, build]
name: Test the smaller packages (${{ matrix.group }})
needs: changes
if: needs.changes.outputs.light != '[]'
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.changes.outputs.light) }}
env:
PACKAGES: ${{ needs.changes.outputs.light }}
PACKAGES: ${{ toJSON(matrix.packages) }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -259,13 +241,13 @@ jobs:
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}
fail-on-cache-miss: true
restore-keys: turbo-build-

- uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/test-results
key: turbo-tests-light-${{ github.sha }}
restore-keys: turbo-tests-light-
key: turbo-tests-light-${{ matrix.group }}-${{ github.sha }}
restore-keys: turbo-tests-light-${{ matrix.group }}-

- run: cp -n .turbo/test-results/* .turbo/cache/ 2>/dev/null || true

Expand All @@ -283,15 +265,15 @@ jobs:
- uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/test-results
key: turbo-tests-light-${{ github.sha }}
key: turbo-tests-light-${{ matrix.group }}-${{ github.sha }}

# Each shard is its own turbo task, told which shard it is through VITEST_SHARD, which turbo
# folds into that task's hash alone. Passing the shard as an argument instead put it into the
# hash of every build the test depended on, and each runner rebuilt them all rather than taking
# them from the build job's cache.
test-shards:
name: Test ${{ matrix.package }} (${{ matrix.shard }} of ${{ matrix.of }})
needs: [changes, build]
needs: changes
if: needs.changes.outputs.shards != '[]'
runs-on: ubuntu-24.04
strategy:
Expand All @@ -318,7 +300,7 @@ jobs:
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}
fail-on-cache-miss: true
restore-keys: turbo-build-

- uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
Expand All @@ -328,6 +310,15 @@ jobs:

- run: cp -n .turbo/test-results/* .turbo/cache/ 2>/dev/null || true

# What Babel made of React Native and the rest of node_modules, which is most of what the
# phone's and the television's Jest spend their time on. Keyed on what decides it, so it is
# made once per lockfile and read by every run after.
- if: matrix.package == '@valence/mobile' || matrix.package == '@valence/tv'
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: apps/${{ matrix.package == '@valence/mobile' && 'mobile' || 'tv' }}/.jest-cache
key: jest-${{ matrix.package }}-${{ hashFiles('pnpm-lock.yaml', 'apps/mobile/jest.config.ts', 'apps/tv/jest.config.ts') }}

- run: pnpm turbo run test:shard --filter=${{ matrix.package }}

- name: Keep the test results
Expand Down Expand Up @@ -462,7 +453,7 @@ jobs:
# on the pull requests that could change them. Every config plugin runs, so a broken one fails here
# in review rather than on a macOS runner at release. Linux only: nothing is compiled.
expo-prebuild:
name: Native config of the ${{ matrix.name }} (${{ matrix.platform }})
name: Native config of the ${{ matrix.name }}
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.expo == 'true'
Expand All @@ -472,7 +463,6 @@ jobs:
fail-fast: false
matrix:
name: [phone app, television app]
platform: [ios, android]
include:
- name: phone app
app: mobile
Expand All @@ -494,10 +484,13 @@ jobs:

- run: pnpm install --frozen-lockfile

- name: Generate the native project
# Both platforms on one runner: generating each takes seconds, and a runner apiece spent a
# minute installing for every one of them while the test shards waited for a slot.
- name: Generate the native projects
working-directory: apps/${{ matrix.app }}
run: npx expo prebuild --platform "$PLATFORM" --no-install --clean
run: |
npx expo prebuild --platform ios --no-install --clean
npx expo prebuild --platform android --no-install --clean
env:
PLATFORM: ${{ matrix.platform }}
EXPO_TV: ${{ matrix.tv }}
CI: '1'
6 changes: 4 additions & 2 deletions .github/workflows/metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ jobs:
org.opencontainers.image.description=The public statistics site at metrics.getvalence.app
org.opencontainers.image.licenses=MIT
org.opencontainers.image.source=https://github.com/${{ github.repository }}
cache-from: type=gha,scope=valence-metrics
cache-to: type=gha,mode=max,scope=valence-metrics
# Kept in the registry beside the image rather than in the Actions cache, which every
# workflow shares and which this image's layers crowded the CI's dependencies out of.
cache-from: type=registry,ref=ghcr.io/valenceoss/valence-metrics:buildcache
cache-to: type=registry,ref=ghcr.io/valenceoss/valence-metrics:buildcache,mode=max,image-manifest=true,oci-mediatypes=true
provenance: false

deploy:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
dist/
coverage/
.turbo/
.jest-cache/
*.tsbuildinfo

target/
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/src/components/DocsSearch/DocsSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('DocsSearch', () => {
});

it('opens a palette listing every page from the button', async () => {
const user = userEvent.setup();
const user = userEvent.setup({ delay: null });

await renderInDocsRouter(() => (
<DocsSearch pages={[page('/install/a', 'Alpha'), page('/install/b', 'Beta')]} sources={{}} />
Expand All @@ -36,7 +36,7 @@ describe('DocsSearch', () => {
});

it('opens from Ctrl and K', async () => {
const user = userEvent.setup();
const user = userEvent.setup({ delay: null });

await renderInDocsRouter(() => (
<DocsSearch pages={[page('/install/a', 'Alpha')]} sources={{}} />
Expand All @@ -48,7 +48,7 @@ describe('DocsSearch', () => {

it('reads the pages on first use and finds a match in their text', async () => {
const read = vi.fn(() => Promise.resolve('---\ntitle: X\n---\nPut nginx in front of it.'));
const user = userEvent.setup();
const user = userEvent.setup({ delay: null });

await renderInDocsRouter(() => (
<DocsSearch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('UiLibraryPage', () => {

const [search] = await screen.findAllByRole('searchbox', { name: 'Find a component' });

await userEvent.type(search ?? document.body, 'spinn');
await userEvent.type(search ?? document.body, 'spinn', { delay: null });

const [list] = screen.getAllByRole('navigation', { name: 'Components' });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ describe('UiLibrarySidebar', () => {
<UiLibrarySidebar groups={GROUPS} selected={null} query="" onQueryChange={onQueryChange} />
));

await userEvent.type(screen.getByRole('searchbox', { name: 'Find a component' }), 'b');
await userEvent.type(screen.getByRole('searchbox', { name: 'Find a component' }), 'b', {
delay: null,
});

expect(onQueryChange).toHaveBeenCalledWith('b');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ describe('CommandPaletteDemo', () => {
render(<CommandPaletteDemo />);

await userEvent.click(screen.getByRole('button', { name: 'Open the command palette' }));
await userEvent.type(await screen.findByPlaceholderText('Search commands'), 'scan');
await userEvent.type(await screen.findByPlaceholderText('Search commands'), 'scan', {
delay: null,
});

expect(await screen.findByText('Scan every library')).toBeInTheDocument();
expect(screen.queryByText('Films')).not.toBeInTheDocument();
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const config: Config = {
'<rootDir>/../../packages/native/src/**/*.test.tsx',
],
testTimeout: 20_000,
cacheDirectory: '<rootDir>/.jest-cache',
coverageReporters: ['text', 'json-summary'],
};

Expand Down
1 change: 1 addition & 0 deletions apps/tv/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const whatNeedsCompiling = (): string[] =>
);

const EACH_TELEVISION: Config = {
cacheDirectory: '<rootDir>/.jest-cache',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'mjs', 'json', 'node'],
transform: {
'^.+\\.[jt]sx?$': ['babel-jest', { presets: ['babel-preset-expo'] }],
Expand Down
1 change: 1 addition & 0 deletions packages/client/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default defineConfig({
resolve: { tsconfigPaths: true },
test: {
environment: 'jsdom',
pool: 'threads',
setupFiles: ['./vitest.setup.ts'],
sequence: { hooks: 'list' },
testTimeout: 20_000,
Expand Down
Loading
Loading