mirror of
https://github.com/pnpm/action-setup.git
synced 2026-11-03 12:30:58 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ffc0dd5c2 | ||
|
|
b107c3fa68 | ||
|
|
0f2613b027 |
@@ -21,13 +21,6 @@ jobs:
|
|||||||
run_install: true
|
run_install: true
|
||||||
version: 11
|
version: 11
|
||||||
|
|
||||||
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
|
|
||||||
with:
|
|
||||||
node-version: 24
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: pnpm test
|
|
||||||
|
|
||||||
- name: Update dist/index.js
|
- name: Update dist/index.js
|
||||||
run: pnpm run build
|
run: pnpm run build
|
||||||
|
|
||||||
|
|||||||
Vendored
+111
-111
File diff suppressed because one or more lines are too long
+1
-2
@@ -4,8 +4,7 @@
|
|||||||
"build:bundle": "esbuild src/index.ts --bundle --platform=node --target=node24 --format=cjs --minify --outfile=dist/index.js --loader:.json=json",
|
"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",
|
"build": "pnpm run build:bundle",
|
||||||
"start": "pnpm run build && sh ./run.sh",
|
"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": {
|
"dependencies": {
|
||||||
"@actions/cache": "^4.1.0",
|
"@actions/cache": "^4.1.0",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { saveCache } from '@actions/cache'
|
import { saveCache } from '@actions/cache'
|
||||||
import { getState, info } from '@actions/core'
|
import { getState, info } from '@actions/core'
|
||||||
import { access } from 'fs/promises'
|
|
||||||
|
|
||||||
export async function runSaveCache() {
|
export async function runSaveCache() {
|
||||||
const state = getState('cache_restored_key')
|
const state = getState('cache_restored_key')
|
||||||
@@ -12,17 +11,6 @@ export async function runSaveCache() {
|
|||||||
return
|
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)
|
const cacheId = await saveCache([cachePath], primaryKey)
|
||||||
if (cacheId == -1) return
|
if (cacheId == -1) return
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
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