mirror of
https://github.com/pnpm/action-setup.git
synced 2026-11-03 20:40:57 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c62bfa5094 | ||
|
|
e59b578e06 |
@@ -21,6 +21,13 @@ jobs:
|
||||
run_install: true
|
||||
version: 11
|
||||
|
||||
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
|
||||
with:
|
||||
node-version: 24
|
||||
|
||||
- name: Test
|
||||
run: pnpm test
|
||||
|
||||
- name: Update dist/index.js
|
||||
run: pnpm run build
|
||||
|
||||
|
||||
Vendored
+111
-111
File diff suppressed because one or more lines are too long
+2
-1
@@ -4,7 +4,8 @@
|
||||
"build:bundle": "esbuild src/index.ts --bundle --platform=node --target=node24 --format=cjs --minify --outfile=dist/index.js --loader:.json=json",
|
||||
"build": "pnpm run build:bundle",
|
||||
"start": "pnpm run build && sh ./run.sh",
|
||||
"update-bootstrap": "node scripts/update-bootstrap.mjs"
|
||||
"update-bootstrap": "node scripts/update-bootstrap.mjs",
|
||||
"test": "node --experimental-test-module-mocks --test test/*.test.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/cache": "^4.1.0",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { saveCache } from '@actions/cache'
|
||||
import { getState, info } from '@actions/core'
|
||||
import { access } from 'fs/promises'
|
||||
|
||||
export async function runSaveCache() {
|
||||
const state = getState('cache_restored_key')
|
||||
@@ -11,6 +12,17 @@ export async function runSaveCache() {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await access(cachePath)
|
||||
} catch (error) {
|
||||
if (!(error instanceof Error)) throw error
|
||||
if (!('code' in error)) throw error
|
||||
if (error.code !== 'ENOENT') throw error
|
||||
|
||||
info(`Cache path ${cachePath} does not exist, not saving cache.`)
|
||||
return
|
||||
}
|
||||
|
||||
const cacheId = await saveCache([cachePath], primaryKey)
|
||||
if (cacheId == -1) return
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { mkdtemp, rm, access } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { after, beforeEach, mock, test } from 'node:test'
|
||||
|
||||
const directory = await mkdtemp(join(tmpdir(), 'pnpm-cache-save-'))
|
||||
after(() => rm(directory, { recursive: true, force: true }))
|
||||
let state
|
||||
let checkAccess
|
||||
const saveCache = mock.fn(async () => 1)
|
||||
mock.module('@actions/cache', { namedExports: { saveCache } })
|
||||
mock.module('@actions/core', {
|
||||
namedExports: { getState: name => state[name], info: () => {} },
|
||||
})
|
||||
mock.module('fs/promises', { namedExports: { access: path => checkAccess(path) } })
|
||||
const { runSaveCache } = await import('../src/cache-save/run.ts')
|
||||
|
||||
beforeEach(() => {
|
||||
state = { cache_restored_key: 'old', cache_primary_key: 'new', cache_path: directory }
|
||||
checkAccess = access
|
||||
saveCache.mock.resetCalls()
|
||||
})
|
||||
|
||||
test('skips saving a missing directory', async () => {
|
||||
state.cache_path = join(directory, 'missing')
|
||||
await runSaveCache()
|
||||
assert.equal(saveCache.mock.callCount(), 0)
|
||||
})
|
||||
|
||||
test('saves an existing directory with the primary key', async () => {
|
||||
await runSaveCache()
|
||||
assert.deepEqual(saveCache.mock.calls[0].arguments, [[directory], 'new'])
|
||||
})
|
||||
|
||||
test('skips saving a primary-key cache hit', async () => {
|
||||
state.cache_restored_key = 'new'
|
||||
await runSaveCache()
|
||||
assert.equal(saveCache.mock.callCount(), 0)
|
||||
})
|
||||
|
||||
test('propagates unexpected filesystem errors', async () => {
|
||||
const error = Object.assign(new Error('access denied'), { code: 'EACCES' })
|
||||
checkAccess = async () => { throw error }
|
||||
await assert.rejects(runSaveCache(), error)
|
||||
assert.equal(saveCache.mock.callCount(), 0)
|
||||
})
|
||||
Reference in New Issue
Block a user