Skip to content

Commit 1e0f1c5

Browse files
authored
feat: add modernjs to rslib ecosystem ci (#19)
1 parent 916bf27 commit 1e0f1c5

5 files changed

Lines changed: 63 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ jobs:
5555
os: ubuntu-latest
5656
- suite: rsdoctor
5757
os: ubuntu-latest
58+
- suite: modernjs
59+
os: ubuntu-latest
5860
fail-fast: false
5961
runs-on: ${{ matrix.os }}
6062
name: rslib (${{ matrix.suite }})

.github/workflows/rslib-ecosystem-ci-from-commit.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ on:
2929
- rstest
3030
- rspress
3131
- rsdoctor
32+
- modernjs
3233
suiteRefType:
3334
description: "type of suite ref to use"
3435
required: true
@@ -85,6 +86,8 @@ jobs:
8586
os: ubuntu-latest
8687
- suite: rsdoctor
8788
os: ubuntu-latest
89+
- suite: modernjs
90+
os: ubuntu-latest
8891
fail-fast: false
8992
runs-on: ${{ matrix.os }}
9093
name: execute-all (${{ matrix.suite }})

.github/workflows/rslib-ecosystem-ci-from-pr.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ on:
3434
- rstest
3535
- rspress
3636
- rsdoctor
37+
- modernjs
3738
suiteRefType:
3839
description: "type of suite ref to use"
3940
required: true
@@ -85,6 +86,8 @@ jobs:
8586
os: ubuntu-latest
8687
- suite: rsdoctor
8788
os: ubuntu-latest
89+
- suite: modernjs
90+
os: ubuntu-latest
8891
fail-fast: false
8992
runs-on: ${{ matrix.os }}
9093
name: execute-all (${{ matrix.suite }})

.github/workflows/rslib-ecosystem-ci-selected.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ on:
4040
- rstest
4141
- rspress
4242
- rsdoctor
43+
- modernjs
4344
suiteRefType:
4445
description: "type of suite ref to use"
4546
required: true
@@ -91,6 +92,8 @@ jobs:
9192
os: ubuntu-latest
9293
- suite: rsdoctor
9394
os: ubuntu-latest
95+
- suite: modernjs
96+
os: ubuntu-latest
9497
fail-fast: false
9598
runs-on: ${{ matrix.os }}
9699
name: execute-all (${{ matrix.suite }})

tests/rslib/modernjs.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { join } from 'node:path';
2+
import cache from '@actions/cache';
3+
import type { RunOptions } from '../../types';
4+
import { $, cd, runInRepo } from '../../utils';
5+
6+
const isGitHubActions = !!process.env.GITHUB_ACTIONS;
7+
8+
export async function test(options: RunOptions) {
9+
let nxCachePath: string;
10+
let nxCacheKey: string;
11+
12+
await runInRepo({
13+
...options,
14+
repo: 'web-infra-dev/modern.js',
15+
branch: process.env.MODERN_REF ?? 'main',
16+
beforeInstall: async () => {
17+
if (isGitHubActions) {
18+
const modernJsDir = join(process.cwd(), 'workspace/modernjs/modern.js');
19+
nxCachePath = join(modernJsDir, '.nx/cache');
20+
const sha = await $`git rev-parse HEAD`;
21+
nxCacheKey = `modernjs-nx-${sha.trim()}`;
22+
const restoreKeys = ['modernjs-nx-'];
23+
const cacheHitKey = await cache.restoreCache(
24+
[nxCachePath],
25+
nxCacheKey,
26+
restoreKeys,
27+
);
28+
if (cacheHitKey) {
29+
console.log(`Cache hit for key: ${cacheHitKey}`);
30+
await $`ls -lah .nx/cache`;
31+
} else {
32+
console.log(
33+
`Cache miss for key: ${nxCacheKey}, proceeding without cache.`,
34+
);
35+
}
36+
}
37+
},
38+
afterInstall: async () => {
39+
if (isGitHubActions) {
40+
console.log('Caching `.nx/cache` directory for future builds.');
41+
await $`ls -lah .nx/cache`;
42+
await cache.saveCache([nxCachePath], nxCacheKey);
43+
}
44+
},
45+
beforeTest: async () => {
46+
cd('tests/e2e/builder');
47+
await $`pnpm playwright install chromium`;
48+
cd('../../../');
49+
},
50+
test: ['test:ut', 'test:framework', 'test:builder'],
51+
});
52+
}

0 commit comments

Comments
 (0)