Skip to content

Commit d08094c

Browse files
committed
chore: yarn
1 parent 47974e5 commit d08094c

File tree

9 files changed

+125
-3
lines changed

9 files changed

+125
-3
lines changed

.github/actions/cache-builder/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,5 @@ dist
176176

177177
# caches
178178
data/npm
179+
data/yarn
180+
data/yarn_tmp
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"crawlee": [
3+
"3.13.1",
4+
"3.13.2",
5+
"3.13.3",
6+
"3.13.4",
7+
"3.13.5"
8+
],
9+
"apify": [
10+
"3.3.1",
11+
"3.3.2",
12+
"3.4.0",
13+
"3.4.1",
14+
"3.4.2"
15+
],
16+
"playwright": [
17+
"1.50.0",
18+
"1.50.1",
19+
"1.51.0",
20+
"1.51.1",
21+
"1.52.0"
22+
],
23+
"puppeteer": [
24+
"24.8.0",
25+
"24.8.1",
26+
"24.8.2",
27+
"24.9.0",
28+
"24.10.0"
29+
],
30+
"typescript": [
31+
"5.6.3",
32+
"5.7.2",
33+
"5.7.3",
34+
"5.8.2",
35+
"5.8.3"
36+
]
37+
}

.github/actions/cache-builder/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"scripts": {
66
"node:npm": "node src/caches/npm.ts",
7+
"node:yarn": "node src/caches/yarn.ts",
78
"fmt": "biome format --write ./src",
89
"typecheck": "tsc --noEmit"
910
},
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { mkdir, rm, writeFile } from 'node:fs/promises';
2+
import { getCachePath, packagesToPrecache } from '../shared/constants.ts';
3+
import { fetchPackageVersions } from '../shared/npm.ts';
4+
import spawn from 'nano-spawn';
5+
6+
const environmentVariable = 'YARN_CACHE_FOLDER';
7+
const globalEnvironmentVariable = 'YARN_GLOBAL_FOLDER';
8+
const cachePath = getCachePath('yarn');
9+
10+
console.log(`Cache location: ${cachePath}`);
11+
12+
const cacheState: Record<string, string[]> = {};
13+
14+
const tmpDir = new URL('../../data/yarn_tmp/', import.meta.url);
15+
16+
{
17+
// Warm up the temp directory
18+
await mkdir(tmpDir, { recursive: true });
19+
20+
await writeFile(new URL('package.json', tmpDir), JSON.stringify({ private: true }));
21+
await writeFile(new URL('yarn.lock', tmpDir), '');
22+
23+
await spawn('yarn', 'config set enableGlobalCache true'.split(' '), {
24+
cwd: tmpDir,
25+
});
26+
27+
await spawn('yarn', 'config set nodeLinker node-modules'.split(' '), {
28+
cwd: tmpDir,
29+
});
30+
31+
await spawn('yarn', 'set version stable --yarn-path'.split(' '), {
32+
cwd: tmpDir,
33+
});
34+
}
35+
36+
for (const packageName of packagesToPrecache) {
37+
const lastFiveVersions = (await fetchPackageVersions(packageName)).slice(-5);
38+
cacheState[packageName] = lastFiveVersions;
39+
40+
for (const version of lastFiveVersions) {
41+
console.log(`Fetching ${packageName}@${version}`);
42+
43+
try {
44+
await spawn('yarn', ['add', `${packageName}@${version}`], {
45+
env: {
46+
[environmentVariable]: cachePath,
47+
[globalEnvironmentVariable]: cachePath,
48+
YARN_ENABLE_GLOBAL_CACHE: 'true',
49+
},
50+
cwd: tmpDir,
51+
});
52+
} catch (error) {
53+
console.error(`Failed to fetch ${packageName}@${version}:`, error);
54+
} finally {
55+
console.log(`Done fetching ${packageName}@${version}`);
56+
}
57+
}
58+
}
59+
60+
await writeFile(new URL('../../data/yarn_state.json', import.meta.url), JSON.stringify(cacheState, null, '\t'));
61+
62+
await rm(tmpDir, { recursive: true });

.github/actions/cache-builder/src/shared/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { fileURLToPath } from 'node:url';
2+
13
export const packagesToPrecache = [
24
//
35
'crawlee',
@@ -6,3 +8,7 @@ export const packagesToPrecache = [
68
'puppeteer',
79
'typescript',
810
];
11+
12+
export function getCachePath(pm: string) {
13+
return fileURLToPath(new URL(`../../data/${pm}/`, import.meta.url));
14+
}

.github/actions/cache-builder/src/shared/npm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { fileURLToPath } from 'node:url';
21
import { compare } from 'semver';
2+
import { getCachePath } from './constants.ts';
33

44
const npmPackageInfoRoute = (pkg: string) => `https://registry.npmjs.org/${pkg}`;
55

@@ -36,7 +36,7 @@ export async function fetchPackageVersions(packageName: string) {
3636

3737
export function getCachePathData() {
3838
return {
39-
path: fileURLToPath(new URL('../../data/npm/', import.meta.url)),
39+
path: getCachePath('npm'),
4040
environmentVariable: 'npm_config_cache',
4141
};
4242
}

.github/workflows/cache-node.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,30 @@ jobs:
3434
- run: yarn node:npm
3535
working-directory: .github/actions/cache-builder
3636

37+
- run: yarn node:yarn
38+
working-directory: .github/actions/cache-builder
39+
3740
- name: Print npm state
3841
run: |
3942
cat .github/actions/cache-builder/data/npm_state.json
4043
44+
- name: Print yarn state
45+
run: |
46+
cat .github/actions/cache-builder/data/yarn_state.json
47+
4148
- name: Store npm output
4249
uses: actions/cache/save@v4
4350
with:
4451
path: .github/actions/cache-builder/data/npm/*
4552
key: node-npm-${{ hashFiles('.github/actions/cache-builder/data/npm_state.json') }}
4653

47-
- name: Push updated matrix
54+
- name: Store yarn output
55+
uses: actions/cache/save@v4
56+
with:
57+
path: .github/actions/cache-builder/data/yarn/*
58+
key: node-yarn-${{ hashFiles('.github/actions/cache-builder/data/yarn_state.json') }}
59+
60+
- name: Push updated states
4861
if: github.event_name != 'pull_request'
4962
run: |
5063
# Setup git user

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ npm-debug.log
33
node_modules
44
.DS_Store
55
.turbo
6+
.yarn/install-state.gz

.yarn/install-state.gz

-9.35 KB
Binary file not shown.

0 commit comments

Comments
 (0)