Skip to content

Commit f1c1ed0

Browse files
ci: improve cache (#319)
1 parent 42c35e6 commit f1c1ed0

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,32 @@ jobs:
2929

3030
- name: Get pnpm store directory
3131
shell: bash
32-
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
32+
run: echo "PNPM_STORE=$(pnpm store path --silent)" >> $GITHUB_ENV
3333

3434
- uses: actions/cache@v3
35-
name: Setup pnpm cache
35+
name: Cache pnpm
3636
with:
37-
path: ${{ env.STORE_PATH }}
38-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39-
restore-keys: |
40-
${{ runner.os }}-pnpm-store-
37+
path: ${{ env.PNPM_STORE }}
38+
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
39+
restore-keys: ${{ runner.os }}-pnpm-
4140

4241
- name: Install dependencies
4342
run: pnpm install
4443

45-
- name: Restore Node.js versions
46-
id: cache-nodejs
47-
uses: actions/cache/restore@v3
44+
- name: Get Node.js cache directory
45+
shell: bash
46+
run: echo "NVE_CACHE=$(node -e 'console.log(require("cachedir")("nve"))')" >> $GITHUB_ENV
47+
48+
- name: Cache Node.js versions
49+
uses: actions/cache@v3
4850
with:
49-
path: /home/runner/.cache/nve
51+
path: ${{ env.NVE_CACHE }}
5052
key: ${{ runner.os }}-nodejs-${{ hashFiles('tests/index.ts') }}
53+
restore-keys: ${{ runner.os }}-nodejs-
5154

5255
- name: Test
5356
run: pnpm test
5457

55-
- name: Save Node.js versions
56-
uses: actions/cache/save@v3
57-
with:
58-
path: /home/runner/.cache/nve
59-
key: ${{ steps.cache-nodejs.outputs.cache-primary-key }}
60-
6158
- name: Type check
6259
if: ${{ matrix.os == 'ubuntu-latest' }}
6360
run: pnpm type-check

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@types/node": "^20.6.0",
5959
"@types/react": "^18.2.21",
6060
"@types/semver": "^7.5.1",
61+
"cachedir": "^2.4.0",
6162
"chokidar": "^3.5.3",
6263
"clean-pkg-json": "^1.2.0",
6364
"cleye": "^1.3.2",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/index.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
11
import { describe } from 'manten';
22
import { createFixture } from 'fs-fixture';
33
import { createNode } from './utils/tsx';
4-
5-
const isWin = process.platform === 'win32';
4+
import { nodeVersions } from './utils/node-versions';
65

76
const packageTypes = [
87
'commonjs',
98
'module',
109
] as const;
1110

12-
const nodeVersions = [
13-
'18',
14-
'20',
15-
...(
16-
(process.env.CI && !isWin)
17-
? [
18-
'12.20.0', // CJS named export detection added
19-
'12',
20-
'14',
21-
'16',
22-
'17',
23-
]
24-
: []
25-
),
26-
];
27-
2811
(async () => {
2912
for (const packageType of packageTypes) {
3013
await describe(`Package type: ${packageType}`, async ({ describe, onFinish }) => {

tests/utils/node-versions.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export const nodeVersions = [
2+
'18',
3+
'20',
4+
...(
5+
(
6+
process.env.CI
7+
&& process.platform !== 'win32'
8+
)
9+
? [
10+
'12.20.0', // CJS named export detection added
11+
'12',
12+
'14',
13+
'16',
14+
'17',
15+
] as const
16+
: [] as const
17+
),
18+
] as const;

0 commit comments

Comments
 (0)