mirror of
https://github.com/pnpm/action-setup.git
synced 2026-03-04 08:01:02 +08:00
chore: sync with upstream pnpm/action-setup v4.2.0
Merge latest upstream changes including: - Store caching support (cache and cache_dependency_path inputs) - Custom NPM registry installation support - Refactored star imports - CI improvements (pinned actions, excluded macOS) - README and documentation updates - Dependency cleanup (removed unused @types/node-fetch)
This commit is contained in:
commit
e7a4f3e592
12
.github/workflows/test.yaml
vendored
12
.github/workflows/test.yaml
vendored
@ -22,7 +22,7 @@ jobs:
|
|||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -51,7 +51,7 @@ jobs:
|
|||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -74,8 +74,8 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
|
# macos is excluded from this test because node 12 is no longer available on this platform
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
standalone:
|
standalone:
|
||||||
@ -83,7 +83,7 @@ jobs:
|
|||||||
- false
|
- false
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -92,7 +92,7 @@ jobs:
|
|||||||
standalone: ${{ matrix.standalone }}
|
standalone: ${{ matrix.standalone }}
|
||||||
|
|
||||||
- name: install Node.js
|
- name: install Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||||
with:
|
with:
|
||||||
# Use Node.js 16 - has ARM64 support and works with pnpm standalone tests
|
# Use Node.js 16 - has ARM64 support and works with pnpm standalone tests
|
||||||
node-version: 16
|
node-version: 16
|
||||||
@ -160,7 +160,7 @@ jobs:
|
|||||||
- yarn
|
- yarn
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
|
|||||||
7
CLAUDE.md
Normal file
7
CLAUDE.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Claude Code Project Configuration
|
||||||
|
|
||||||
|
## Git Conventions
|
||||||
|
|
||||||
|
- Do NOT add `Co-Authored-By` lines to commit messages
|
||||||
|
- Do NOT add "Generated with Claude Code" to PR descriptions
|
||||||
|
- Keep commit messages concise and conventional-commit style
|
||||||
20
README.md
20
README.md
@ -40,7 +40,15 @@ If `run_install` is a YAML string representation of either an object or an array
|
|||||||
|
|
||||||
#### `run_install.args`
|
#### `run_install.args`
|
||||||
|
|
||||||
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
|
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--ignore-scripts, --strict-peer-dependencies]`.
|
||||||
|
|
||||||
|
### `cache`
|
||||||
|
|
||||||
|
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to cache the pnpm store directory.
|
||||||
|
|
||||||
|
### `cache_dependency_path`
|
||||||
|
|
||||||
|
**Optional** (_type:_ `string|string[]`, _default:_ `pnpm-lock.yaml`) File path to the pnpm lockfile, which contents hash will be used as a cache key.
|
||||||
|
|
||||||
### `package_json_file`
|
### `package_json_file`
|
||||||
|
|
||||||
@ -119,7 +127,7 @@ jobs:
|
|||||||
version: 10
|
version: 10
|
||||||
run_install: |
|
run_install: |
|
||||||
- recursive: true
|
- recursive: true
|
||||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
args: [--strict-peer-dependencies]
|
||||||
- args: [--global, gulp, prettier, typescript]
|
- args: [--global, gulp, prettier, typescript]
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -142,13 +150,7 @@ jobs:
|
|||||||
name: Install pnpm
|
name: Install pnpm
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 10
|
||||||
run_install: false
|
cache: true
|
||||||
|
|
||||||
- name: Install Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
cache: 'pnpm'
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|||||||
10
action.yml
10
action.yml
@ -15,8 +15,16 @@ inputs:
|
|||||||
description: If specified, run `pnpm install`
|
description: If specified, run `pnpm install`
|
||||||
required: false
|
required: false
|
||||||
default: 'null'
|
default: 'null'
|
||||||
|
cache:
|
||||||
|
description: Whether to cache the pnpm store directory
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
|
cache_dependency_path:
|
||||||
|
description: File path to the pnpm lockfile, which contents hash will be used as a cache key
|
||||||
|
required: false
|
||||||
|
default: 'pnpm-lock.yaml'
|
||||||
package_json_file:
|
package_json_file:
|
||||||
description: File path to the package.json to read "packageManager" configuration
|
description: File path to the package.json to read "packageManager" configuration. This path must be relative to the repository root (GITHUB_WORKSPACE).
|
||||||
required: false
|
required: false
|
||||||
default: 'package.json'
|
default: 'package.json'
|
||||||
standalone:
|
standalone:
|
||||||
|
|||||||
6
dist/index.js
vendored
6
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -18,10 +18,12 @@
|
|||||||
"check": "pnpm lint && pnpm typecheck"
|
"check": "pnpm lint && pnpm typecheck"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@actions/cache": "^4.1.0",
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
|
"@actions/exec": "^1.1.1",
|
||||||
|
"@actions/glob": "^0.5.0",
|
||||||
"@types/expand-tilde": "^2.0.2",
|
"@types/expand-tilde": "^2.0.2",
|
||||||
"@types/node": "^20.11.5",
|
"@types/node": "^20.11.5",
|
||||||
"@types/node-fetch": "^2.6.11",
|
|
||||||
"expand-tilde": "^2.0.2",
|
"expand-tilde": "^2.0.2",
|
||||||
"yaml": "^2.3.4",
|
"yaml": "^2.3.4",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.22.4"
|
||||||
|
|||||||
1135
pnpm-lock.yaml
1135
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
19
src/cache-restore/index.ts
Normal file
19
src/cache-restore/index.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { isFeatureAvailable } from '@actions/cache'
|
||||||
|
import { endGroup, startGroup, warning } from '@actions/core'
|
||||||
|
import { Inputs } from '../inputs'
|
||||||
|
import { runRestoreCache } from './run'
|
||||||
|
|
||||||
|
export async function restoreCache(inputs: Inputs) {
|
||||||
|
if (!inputs.cache) return
|
||||||
|
|
||||||
|
if (!isFeatureAvailable()) {
|
||||||
|
warning('Cache is not available, skipping cache restoration')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
startGroup('Restoring cache...')
|
||||||
|
await runRestoreCache(inputs)
|
||||||
|
endGroup()
|
||||||
|
}
|
||||||
|
|
||||||
|
export default restoreCache
|
||||||
39
src/cache-restore/run.ts
Normal file
39
src/cache-restore/run.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { restoreCache } from '@actions/cache'
|
||||||
|
import { debug, info, saveState, setOutput } from '@actions/core'
|
||||||
|
import { getExecOutput } from '@actions/exec'
|
||||||
|
import { hashFiles } from '@actions/glob'
|
||||||
|
import os from 'os'
|
||||||
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
|
export async function runRestoreCache(inputs: Inputs) {
|
||||||
|
const cachePath = await getCacheDirectory()
|
||||||
|
saveState('cache_path', cachePath)
|
||||||
|
|
||||||
|
const fileHash = await hashFiles(inputs.cacheDependencyPath)
|
||||||
|
if (!fileHash) {
|
||||||
|
throw new Error('Some specified paths were not resolved, unable to cache dependencies.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const primaryKey = `pnpm-cache-${process.env.RUNNER_OS}-${os.arch()}-${fileHash}`
|
||||||
|
debug(`Primary key is ${primaryKey}`)
|
||||||
|
saveState('cache_primary_key', primaryKey)
|
||||||
|
|
||||||
|
let cacheKey = await restoreCache([cachePath], primaryKey)
|
||||||
|
|
||||||
|
setOutput('cache-hit', Boolean(cacheKey))
|
||||||
|
|
||||||
|
if (!cacheKey) {
|
||||||
|
info(`Cache is not found`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
saveState('cache_restored_key', cacheKey)
|
||||||
|
info(`Cache restored from key: ${cacheKey}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCacheDirectory() {
|
||||||
|
const { stdout } = await getExecOutput('pnpm store path --silent')
|
||||||
|
const cacheFolderPath = stdout.trim()
|
||||||
|
debug(`Cache folder is set to "${cacheFolderPath}"`)
|
||||||
|
return cacheFolderPath
|
||||||
|
}
|
||||||
15
src/cache-save/index.ts
Normal file
15
src/cache-save/index.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { setFailed } from '@actions/core'
|
||||||
|
import { Inputs } from '../inputs'
|
||||||
|
import { runSaveCache } from './run'
|
||||||
|
|
||||||
|
export async function saveCache(inputs: Inputs) {
|
||||||
|
if (!inputs.cache) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await runSaveCache()
|
||||||
|
} catch (error) {
|
||||||
|
setFailed((error as Error).message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default saveCache
|
||||||
18
src/cache-save/run.ts
Normal file
18
src/cache-save/run.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { saveCache } from '@actions/cache'
|
||||||
|
import { getState, info } from '@actions/core'
|
||||||
|
|
||||||
|
export async function runSaveCache() {
|
||||||
|
const state = getState('cache_restored_key')
|
||||||
|
const primaryKey = getState('cache_primary_key')
|
||||||
|
const cachePath = getState('cache_path')
|
||||||
|
|
||||||
|
if (primaryKey === state) {
|
||||||
|
info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cacheId = await saveCache([cachePath], primaryKey)
|
||||||
|
if (cacheId == -1) return
|
||||||
|
|
||||||
|
info(`Cache saved with the key: ${primaryKey}`)
|
||||||
|
}
|
||||||
24
src/index.ts
24
src/index.ts
@ -1,5 +1,7 @@
|
|||||||
import { setFailed, saveState, getState } from '@actions/core'
|
import { setFailed, saveState, getState } from '@actions/core'
|
||||||
import getInputs from './inputs'
|
import restoreCache from './cache-restore'
|
||||||
|
import saveCache from './cache-save'
|
||||||
|
import getInputs, { Inputs } from './inputs'
|
||||||
import installPnpm from './install-pnpm'
|
import installPnpm from './install-pnpm'
|
||||||
import setOutputs from './outputs'
|
import setOutputs from './outputs'
|
||||||
import pnpmInstall from './pnpm-install'
|
import pnpmInstall from './pnpm-install'
|
||||||
@ -7,15 +9,31 @@ import pruneStore from './pnpm-store-prune'
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const inputs = getInputs()
|
const inputs = getInputs()
|
||||||
const isPost = getState('is_post')
|
|
||||||
if (isPost === 'true') return pruneStore(inputs)
|
if (getState('is_post') === 'true') {
|
||||||
|
await runPost(inputs)
|
||||||
|
} else {
|
||||||
|
await runMain(inputs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runMain(inputs: Inputs) {
|
||||||
saveState('is_post', 'true')
|
saveState('is_post', 'true')
|
||||||
|
|
||||||
await installPnpm(inputs)
|
await installPnpm(inputs)
|
||||||
console.log('Installation Completed!')
|
console.log('Installation Completed!')
|
||||||
setOutputs(inputs)
|
setOutputs(inputs)
|
||||||
|
|
||||||
|
await restoreCache(inputs)
|
||||||
|
|
||||||
pnpmInstall(inputs)
|
pnpmInstall(inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function runPost(inputs: Inputs) {
|
||||||
|
pruneStore(inputs)
|
||||||
|
await saveCache(inputs)
|
||||||
|
}
|
||||||
|
|
||||||
main().catch(error => {
|
main().catch(error => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
setFailed(error)
|
setFailed(error)
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import { RunInstall, parseRunInstall } from './run-install'
|
|||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
readonly version?: string
|
readonly version?: string
|
||||||
readonly dest: string
|
readonly dest: string
|
||||||
|
readonly cache: boolean
|
||||||
|
readonly cacheDependencyPath: string
|
||||||
readonly runInstall: RunInstall[]
|
readonly runInstall: RunInstall[]
|
||||||
readonly packageJsonFile: string
|
readonly packageJsonFile: string
|
||||||
readonly standalone: boolean
|
readonly standalone: boolean
|
||||||
@ -19,6 +21,8 @@ const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
|||||||
export const getInputs = (): Inputs => ({
|
export const getInputs = (): Inputs => ({
|
||||||
version: getInput('version'),
|
version: getInput('version'),
|
||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
|
cache: getBooleanInput('cache'),
|
||||||
|
cacheDependencyPath: parseInputPath('cache_dependency_path'),
|
||||||
runInstall: parseRunInstall('run_install'),
|
runInstall: parseRunInstall('run_install'),
|
||||||
packageJsonFile: parseInputPath('package_json_file'),
|
packageJsonFile: parseInputPath('package_json_file'),
|
||||||
standalone: getBooleanInput('standalone'),
|
standalone: getBooleanInput('standalone'),
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { getInput, error } from '@actions/core'
|
import { getInput, error } from '@actions/core'
|
||||||
import * as yaml from 'yaml'
|
import { parse as parseYaml } from 'yaml'
|
||||||
import { z, ZodError } from 'zod'
|
import { z, ZodError } from 'zod'
|
||||||
|
|
||||||
const RunInstallSchema = z.object({
|
const RunInstallSchema = z.object({
|
||||||
@ -20,7 +20,7 @@ export type RunInstall = z.infer<typeof RunInstallSchema>
|
|||||||
|
|
||||||
export function parseRunInstall(inputName: string): RunInstall[] {
|
export function parseRunInstall(inputName: string): RunInstall[] {
|
||||||
const input = getInput(inputName, { required: true })
|
const input = getInput(inputName, { required: true })
|
||||||
const parsedInput: unknown = yaml.parse(input)
|
const parsedInput: unknown = parseYaml(input)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
||||||
|
|||||||
@ -1,15 +1,16 @@
|
|||||||
import { addPath, exportVariable } from '@actions/core'
|
import { addPath, exportVariable } from '@actions/core'
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
import { rm, writeFile, mkdir } from 'fs/promises'
|
import { rm, writeFile, mkdir, copyFile } from 'fs/promises'
|
||||||
import { readFileSync } from 'fs'
|
import { readFileSync } from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { execPath } from 'process'
|
import { execPath } from 'process'
|
||||||
import util from 'util'
|
import util from 'util'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import YAML from 'yaml'
|
import { parse as parseYaml } from 'yaml'
|
||||||
|
|
||||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
const { version, dest, packageJsonFile, standalone } = inputs
|
const { version, dest, packageJsonFile, standalone } = inputs
|
||||||
|
const { GITHUB_WORKSPACE } = process.env
|
||||||
|
|
||||||
// prepare self install
|
// prepare self install
|
||||||
await rm(dest, { recursive: true, force: true })
|
await rm(dest, { recursive: true, force: true })
|
||||||
@ -19,6 +20,16 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
// we have ensured the dest directory exists, we can write the file directly
|
// we have ensured the dest directory exists, we can write the file directly
|
||||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||||
|
|
||||||
|
// copy .npmrc if it exists to install from custom registry
|
||||||
|
if (GITHUB_WORKSPACE) {
|
||||||
|
try {
|
||||||
|
await copyFile(path.join(GITHUB_WORKSPACE, '.npmrc'), path.join(dest, '.npmrc'))
|
||||||
|
} catch (error) {
|
||||||
|
// Swallow error if .npmrc doesn't exist
|
||||||
|
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// prepare target pnpm
|
// prepare target pnpm
|
||||||
const target = await readTarget({ version, packageJsonFile, standalone })
|
const target = await readTarget({ version, packageJsonFile, standalone })
|
||||||
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
|
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
|
||||||
@ -52,7 +63,7 @@ async function readTarget(opts: {
|
|||||||
try {
|
try {
|
||||||
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
|
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
|
||||||
({ packageManager } = packageJsonFile.endsWith(".yaml")
|
({ packageManager } = packageJsonFile.endsWith(".yaml")
|
||||||
? YAML.parse(content, { merge: true })
|
? parseYaml(content, { merge: true })
|
||||||
: JSON.parse(content)
|
: JSON.parse(content)
|
||||||
)
|
)
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user