Compare commits

..

No commits in common. "master" and "v2.2.1" have entirely different histories.

25 changed files with 1231 additions and 1729 deletions

14
.github/FUNDING.yml vendored
View File

@ -1,2 +1,12 @@
custom: # These are supported funding model platforms
- https://opencollective.com/pnpm
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: khai96_
open_collective: # Collective unavailable
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # disabled
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@ -5,3 +5,6 @@ updates:
schedule: schedule:
interval: weekly interval: weekly
open-pull-requests-limit: 10 open-pull-requests-limit: 10
labels:
- dependabot
- github-actions

View File

@ -1,28 +0,0 @@
name: pr-check
on: [ pull_request ]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Setup pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
run_install: true
version: 9
- name: Update dist/index.js
run: pnpm run build
- name: Check for uncommitted changes in dist
run: git diff --exit-code dist/index.js

View File

@ -15,36 +15,28 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
pnpm: pnpm:
- 9.15.5 - 4.11.1
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
- windows-latest - windows-latest
steps: steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 - uses: actions/checkout@v2
- name: Run the action - name: Run the action
uses: ./ uses: ./
with: with:
version: 9.15.5 version: 4.11.1
- name: 'Test: which' - name: 'Test: which'
run: which pnpm; which pnpx run: which pnpm; which pnpx
- name: 'Test: version' - name: 'Test: install'
run: pnpm --version run: pnpm install
- name: 'Test: install in a fresh project' test_explicit_inputs:
run: | name: Test with explicit inputs
mkdir /tmp/test-project
cd /tmp/test-project
pnpm init
pnpm add is-odd
shell: bash
test_dest:
name: Test with dest
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
@ -52,111 +44,26 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
pnpm: pnpm:
- 9.15.5 - 4.11.1
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
- windows-latest - windows-latest
steps: steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 - uses: actions/checkout@v2
- name: Run the action - name: Run the action
uses: ./ uses: ./
with: with:
version: 9.15.5 version: 4.11.1
dest: ~/test/pnpm dest: ~/test/pnpm
- name: 'Test: which' - name: 'Test: which'
run: which pnpm && which pnpx run: which pnpm && which pnpx
- name: 'Test: version' - name: 'Test: install'
run: pnpm --version run: pnpm install
test_standalone:
name: Test with standalone
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Run the action
uses: ./
with:
version: 9.15.0
standalone: true
- name: 'Test: which'
run: which pnpm
- name: 'Test: version'
run: pnpm --version
- name: 'Test: install in a fresh project'
run: |
mkdir /tmp/test-standalone
cd /tmp/test-standalone
pnpm init
pnpm add is-odd
shell: bash
test_dev_engines:
name: Test with devEngines.packageManager
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
version:
- '9.15.5'
- '>=9.15.0'
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Set up package.json with devEngines.packageManager
run: echo '{"devEngines":{"packageManager":{"name":"pnpm","version":"${{ matrix.version }}","onFail":"download"}}}' > package.json
shell: bash
- name: Run the action
uses: ./
- name: 'Test: which'
run: which pnpm; which pnpx
- name: 'Test: version'
run: |
set -e
required='${{ matrix.version }}'
actual="$(pnpm --version)"
echo "pnpm version: ${actual}"
if [ "${required}" = ">=9.15.0" ]; then
min="9.15.0"
if [ "$(printf '%s\n' "${min}" "${actual}" | sort -V | head -n1)" != "${min}" ]; then
echo "Expected pnpm version >= ${min}, but got ${actual}"
exit 1
fi
else
if [ "${actual}" != "${required}" ]; then
echo "Expected pnpm version ${required}, but got ${actual}"
exit 1
fi
fi
shell: bash
test_run_install: test_run_install:
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})' name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
@ -167,7 +74,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
pnpm: pnpm:
- 9.15.5 - 4.11.1
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
@ -175,6 +82,11 @@ jobs:
run_install: run_install:
- name: 'null' - name: 'null'
value: 'null' value: 'null'
- name: 'empty object'
value: '{}'
- name: 'recursive'
value: |
recursive: true
- name: 'global' - name: 'global'
value: | value: |
args: args:
@ -182,18 +94,29 @@ jobs:
- --global-dir=./pnpm-global - --global-dir=./pnpm-global
- npm - npm
- yarn - yarn
- pnpm
- name: 'array'
value: |
- {}
- recursive: true
- args:
- --global
- --global-dir=./pnpm-global
- npm
- yarn
- pnpm
steps: steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 - uses: actions/checkout@v2
- name: Run the action - name: Run the action
uses: ./ uses: ./
with: with:
version: 9.15.5 version: 4.11.1
run_install: ${{ matrix.run_install.value }} run_install: ${{ matrix.run_install.value }}
- name: 'Test: which' - name: 'Test: which'
run: which pnpm; which pnpx run: which pnpm; which pnpx
- name: 'Test: version' - name: 'Test: install'
run: pnpm --version run: pnpm install

View File

@ -1,7 +1,3 @@
> ## :warning: Upgrade from v2!
>
> The v2 version of this action [has stopped working](https://github.com/pnpm/action-setup/issues/135) with newer Node.js versions. Please, upgrade to the latest version to fix any issues.
# Setup pnpm # Setup pnpm
Install pnpm package manager. Install pnpm package manager.
@ -40,25 +36,7 @@ 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. `[--ignore-scripts, --strict-peer-dependencies]`. **Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --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`
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json`/[`package.yaml`](https://github.com/pnpm/pnpm/pull/1799) to read "packageManager" configuration.
### `standalone`
**Optional** (_type:_ `boolean`, _default:_ `false`) When set to true, [@pnpm/exe](https://www.npmjs.com/package/@pnpm/exe), which is a Node.js bundled package, will be installed, enabling using `pnpm` without Node.js.
This is useful when you want to use a incompatible pair of Node.js and pnpm.
## Outputs ## Outputs
@ -72,9 +50,7 @@ Location of `pnpm` and `pnpx` command.
## Usage example ## Usage example
### Install only pnpm without `packageManager` ### Just install pnpm
This works when the repo either doesn't have a `package.json` or has a `package.json` but it doesn't specify `packageManager`.
```yaml ```yaml
on: on:
@ -86,26 +62,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: pnpm/action-setup@v5 - uses: pnpm/action-setup@v2.1.0
with: with:
version: 10 version: 6.0.2
```
### Install only pnpm with `packageManager`
Omit `version` input to use the version in the [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
```yaml
on:
- push
- pull_request
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v5
``` ```
### Install pnpm and a few npm packages ### Install pnpm and a few npm packages
@ -120,14 +79,14 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v2
- uses: pnpm/action-setup@v5 - uses: pnpm/action-setup@v2.1.0
with: with:
version: 10 version: 6.0.2
run_install: | run_install: |
- recursive: true - recursive: true
args: [--strict-peer-dependencies] args: [--frozen-lockfile, --strict-peer-dependencies]
- args: [--global, gulp, prettier, typescript] - args: [--global, gulp, prettier, typescript]
``` ```
@ -143,17 +102,21 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout build:
uses: actions/checkout@v4 - uses: actions/checkout@v2
- uses: pnpm/action-setup@v5 - name: Cache pnpm modules
name: Install pnpm uses: actions/cache@v2
with: with:
version: 10 path: ~/.pnpm-store
cache: true key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- name: Install dependencies - uses: pnpm/action-setup@v2.1.0
run: pnpm install with:
version: 6.0.2
run_install: true
``` ```
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that. **Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
@ -164,4 +127,4 @@ This action does not setup Node.js for you, use [actions/setup-node](https://git
## License ## License
[MIT](https://github.com/pnpm/action-setup/blob/master/LICENSE.md) © [Hoàng Văn Khải](https://github.com/KSXGitHub/) [MIT](https://git.io/JfclH) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)

View File

@ -1,42 +1,20 @@
name: Setup pnpm name: Setup PNPM
description: Install pnpm package manager description: Install PNPM package manager
branding: branding:
icon: package icon: package
color: orange color: orange
inputs: inputs:
version: version:
description: Version of pnpm to install description: Version of PNPM to install
required: false
dest: dest:
description: Where to store pnpm files description: Where to store PNPM files
required: false required: false
default: ~/setup-pnpm default: ~/setup-pnpm
run_install: run_install:
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:
description: File path to the package.json to read "packageManager" configuration. This path must be relative to the repository root (GITHUB_WORKSPACE).
required: false
default: 'package.json'
standalone:
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed, enabling using pnpm without Node.js.
required: false
default: 'false'
outputs:
dest:
description: Expanded path of inputs#dest
bin_dest:
description: Location of `pnpm` and `pnpx` command
runs: runs:
using: node24 using: node12
main: dist/index.js main: dist/index.js
post: dist/index.js post: dist/index.js

BIN
dist/index.js vendored

Binary file not shown.

View File

@ -1,23 +1,28 @@
{ {
"private": true, "private": true,
"scripts": { "scripts": {
"build:bundle": "esbuild src/index.ts --bundle --platform=node --target=node24 --format=cjs --minify --outfile=dist/index.js --loader:.json=json", "build:schemas": "ts-schema-autogen generate",
"build": "pnpm run build:bundle", "build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc",
"start": "pnpm run build && sh ./run.sh" "start": "pnpm run build && sh ./run.sh"
}, },
"dependencies": { "dependencies": {
"@actions/cache": "^4.1.0", "@actions/core": "^1.6.0",
"@actions/core": "^1.10.1", "@pnpm/fetch": "^4.2.5",
"@actions/exec": "^1.1.1", "@pnpm/logger": "^4.0.0",
"@actions/glob": "^0.5.0", "@types/expand-tilde": "^2.0.0",
"@types/expand-tilde": "^2.0.2", "@types/fs-extra": "^9.0.13",
"@types/node": "^22.0.0", "@types/js-yaml": "^4.0.5",
"@types/node": "^14.18.10",
"@types/node-fetch": "^2.6.1",
"ajv": "^6.12.6",
"expand-tilde": "^2.0.2", "expand-tilde": "^2.0.2",
"yaml": "^2.3.4", "fs-extra": "^10.0.0",
"zod": "^3.22.4" "js-yaml": "^4.1.0"
}, },
"devDependencies": { "devDependencies": {
"esbuild": "^0.27.4", "@ts-schema-autogen/cli": "^0.1.2",
"typescript": "^5.3.3" "@vercel/ncc": "^0.33.3",
"typescript": "^4.5.5"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +0,0 @@
packages:
- '.'
allowBuilds:
esbuild: true

1
run.sh
View File

@ -4,5 +4,4 @@ export HOME="$(pwd)"
export INPUT_VERSION=4.11.1 export INPUT_VERSION=4.11.1
export INPUT_DEST='~/pnpm.temp' export INPUT_DEST='~/pnpm.temp'
export INPUT_RUN_INSTALL=null export INPUT_RUN_INSTALL=null
export INPUT_standalone=false
exec node dist/index.js exec node dist/index.js

View File

@ -1,19 +0,0 @@
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

View File

@ -1,39 +0,0 @@
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
}

View File

@ -1,15 +0,0 @@
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

View File

@ -1,18 +0,0 @@
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}`)
}

View File

@ -1,7 +1,5 @@
import { setFailed, saveState, getState } from '@actions/core' import { setFailed, saveState, getState } from '@actions/core'
import restoreCache from './cache-restore' import getInputs from './inputs'
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'
@ -9,31 +7,15 @@ import pruneStore from './pnpm-store-prune'
async function main() { async function main() {
const inputs = getInputs() const inputs = getInputs()
const isPost = getState('is_post')
if (getState('is_post') === 'true') { if (isPost === 'true') return pruneStore(inputs)
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)

View File

@ -1,15 +1,11 @@
import { getBooleanInput, getInput, InputOptions } from '@actions/core' import { getInput, InputOptions } from '@actions/core'
import expandTilde from 'expand-tilde' import expandTilde from 'expand-tilde'
import { RunInstall, parseRunInstall } from './run-install' 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 standalone: boolean
} }
const options: InputOptions = { const options: InputOptions = {
@ -21,11 +17,7 @@ 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'),
standalone: getBooleanInput('standalone'),
}) })
export default getInputs export default getInputs

View File

@ -0,0 +1,21 @@
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"instruction": {
"compilerOptions": {
"strict": true,
"target": "ES2018",
"lib": [
"ES2018",
"ES2019",
"ES2020",
"ESNext"
],
"moduleResolution": "Node",
"esModuleInterop": true,
"resolveJsonModule": true
},
"input": "run-install.ts",
"symbol": "RunInstallInput",
"output": "run-install-input.schema.json"
}
}

View File

@ -0,0 +1,39 @@
{
"anyOf": [
{
"$ref": "#/definitions/RunInstall"
},
{
"type": "array",
"items": {
"$ref": "#/definitions/RunInstall"
}
},
{
"type": [
"null",
"boolean"
]
}
],
"definitions": {
"RunInstall": {
"type": "object",
"properties": {
"recursive": {
"type": "boolean"
},
"cwd": {
"type": "string"
},
"args": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}

View File

@ -1,41 +1,39 @@
import { getInput, error } from '@actions/core' import { getInput, error, InputOptions } from '@actions/core'
import { parse as parseYaml } from 'yaml' import Ajv from 'ajv'
import { z, ZodError } from 'zod' import { load } from 'js-yaml'
import process from 'process'
import runInstallSchema from './run-install-input.schema.json'
const RunInstallSchema = z.object({ export interface RunInstall {
recursive: z.boolean().optional(), readonly recursive?: boolean
cwd: z.string().optional(), readonly cwd?: string
args: z.array(z.string()).optional(), readonly args?: readonly string[]
}
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
const options: InputOptions = {
required: true,
}
export function parseRunInstall(name: string): RunInstall[] {
const result: RunInstallInput = load(getInput(name, options)) as any
const ajv = new Ajv({
allErrors: true,
}) })
const validate = ajv.compile(runInstallSchema)
const RunInstallInputSchema = z.union([ if (!validate(result)) {
z.null(), for (const errorItem of validate.errors!) {
z.boolean(), error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
RunInstallSchema, }
z.array(RunInstallSchema), return process.exit(1)
]) }
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
export type RunInstall = z.infer<typeof RunInstallSchema>
export function parseRunInstall(inputName: string): RunInstall[] {
const input = getInput(inputName, { required: true })
const parsedInput: unknown = parseYaml(input)
try {
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
if (!result) return [] if (!result) return []
if (result === true) return [{ recursive: true }] if (result === true) return [{ recursive: true }]
if (Array.isArray(result)) return result if (Array.isArray(result)) return result
return [result] return [result]
} catch (exception: unknown) {
error(`Error for input "${inputName}" = ${input}`)
if (exception instanceof ZodError) {
error(`Errors: ${exception.errors}`)
} else {
error(`Exception: ${exception}`)
}
process.exit(1)
}
} }

View File

@ -1,282 +0,0 @@
{
"name": "bootstrap-exe",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@pnpm/exe": "11.0.0-beta.3"
}
},
"node_modules/@pnpm/exe": {
"version": "11.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@pnpm/exe/-/exe-11.0.0-beta.3.tgz",
"integrity": "sha512-yWNlHHdYmvf4c0MCkCzAa4csJDPdA+7yJCbXBUDXMbUu/0Zv/AxtO77q24MwlnBUC0dWeA+0F/pPmdkR9aTV2A==",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"@reflink/reflink": "0.1.19"
},
"bin": {
"pn": "pn",
"pnpm": "pnpm",
"pnpx": "pnpx",
"pnx": "pnx"
},
"funding": {
"url": "https://opencollective.com/pnpm"
},
"optionalDependencies": {
"@pnpm/linux-arm64": "11.0.0-beta.3",
"@pnpm/linux-x64": "11.0.0-beta.3",
"@pnpm/macos-arm64": "11.0.0-beta.3",
"@pnpm/macos-x64": "11.0.0-beta.3",
"@pnpm/win-arm64": "11.0.0-beta.3",
"@pnpm/win-x64": "11.0.0-beta.3"
}
},
"node_modules/@pnpm/linux-arm64": {
"version": "11.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@pnpm/linux-arm64/-/linux-arm64-11.0.0-beta.3.tgz",
"integrity": "sha512-TF2fyuCY9GggR4kfhjo1hMmgn+rIohenwNoH0tLPM7JlBK7/UAIFt1LI+o999tRwTCEw7gnxHFwtI2vyQuDfNw==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/linux-x64": {
"version": "11.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@pnpm/linux-x64/-/linux-x64-11.0.0-beta.3.tgz",
"integrity": "sha512-7GrLsnSuDH62y486GUTwJdohGIC1ugz9ZJkbKOHgxIAkNGcSTJ1IkkdARtv7/WMmOEwwESDmtpOQ6LmjnpDMSA==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/macos-arm64": {
"version": "11.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@pnpm/macos-arm64/-/macos-arm64-11.0.0-beta.3.tgz",
"integrity": "sha512-NQKgI1DURrEiOUzpxL0Mc+yn7DV4tpShqGnjaJLbz8ZCXsX/qhmybebvCG3r+IfSk3P5KID66lcgC/Osiaz0Dg==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/macos-x64": {
"version": "11.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@pnpm/macos-x64/-/macos-x64-11.0.0-beta.3.tgz",
"integrity": "sha512-Ky22KFYHXx8+8WU4KJT9NXVgzFioL2w9pHTQjsqTK70AbxiErscPYhrFIehlCNbXjgs+tGVIy13QNKkiwvmS8w==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/win-arm64": {
"version": "11.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@pnpm/win-arm64/-/win-arm64-11.0.0-beta.3.tgz",
"integrity": "sha512-7L8TFNDm25m+XYSyhcola3YFd/li6BZzzl56SsyGnZabsvUslMwnDiJad48wOz8IuN7zsrTSGh+X/x6F+GdrFQ==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/win-x64": {
"version": "11.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@pnpm/win-x64/-/win-x64-11.0.0-beta.3.tgz",
"integrity": "sha512-Z/6OpMUaIpggXjCtWEhp6kWjiT/2EImhkJAu8AodOORqeNcWouGEq3sO4XU0em6d+pAHmdV0hWMQ2xCUmPVuiA==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@reflink/reflink": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink/-/reflink-0.1.19.tgz",
"integrity": "sha512-DmCG8GzysnCZ15bres3N5AHCmwBwYgp0As6xjhQ47rAUTUXxJiK+lLUxaGsX3hd/30qUpVElh05PbGuxRPgJwA==",
"license": "MIT",
"engines": {
"node": ">= 10"
},
"optionalDependencies": {
"@reflink/reflink-darwin-arm64": "0.1.19",
"@reflink/reflink-darwin-x64": "0.1.19",
"@reflink/reflink-linux-arm64-gnu": "0.1.19",
"@reflink/reflink-linux-arm64-musl": "0.1.19",
"@reflink/reflink-linux-x64-gnu": "0.1.19",
"@reflink/reflink-linux-x64-musl": "0.1.19",
"@reflink/reflink-win32-arm64-msvc": "0.1.19",
"@reflink/reflink-win32-x64-msvc": "0.1.19"
}
},
"node_modules/@reflink/reflink-darwin-arm64": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink-darwin-arm64/-/reflink-darwin-arm64-0.1.19.tgz",
"integrity": "sha512-ruy44Lpepdk1FqDz38vExBY/PVUsjxZA+chd9wozjUH9JjuDT/HEaQYA6wYN9mf041l0yLVar6BCZuWABJvHSA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@reflink/reflink-darwin-x64": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink-darwin-x64/-/reflink-darwin-x64-0.1.19.tgz",
"integrity": "sha512-By85MSWrMZa+c26TcnAy8SDk0sTUkYlNnwknSchkhHpGXOtjNDUOxJE9oByBnGbeuIE1PiQsxDG3Ud+IVV9yuA==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@reflink/reflink-linux-arm64-gnu": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink-linux-arm64-gnu/-/reflink-linux-arm64-gnu-0.1.19.tgz",
"integrity": "sha512-7P+er8+rP9iNeN+bfmccM4hTAaLP6PQJPKWSA4iSk2bNvo6KU6RyPgYeHxXmzNKzPVRcypZQTpFgstHam6maVg==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@reflink/reflink-linux-arm64-musl": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink-linux-arm64-musl/-/reflink-linux-arm64-musl-0.1.19.tgz",
"integrity": "sha512-37iO/Dp6m5DDaC2sf3zPtx/hl9FV3Xze4xoYidrxxS9bgP3S8ALroxRK6xBG/1TtfXKTvolvp+IjrUU6ujIGmA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@reflink/reflink-linux-x64-gnu": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink-linux-x64-gnu/-/reflink-linux-x64-gnu-0.1.19.tgz",
"integrity": "sha512-jbI8jvuYCaA3MVUdu8vLoLAFqC+iNMpiSuLbxlAgg7x3K5bsS8nOpTRnkLF7vISJ+rVR8W+7ThXlXlUQ93ulkw==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@reflink/reflink-linux-x64-musl": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink-linux-x64-musl/-/reflink-linux-x64-musl-0.1.19.tgz",
"integrity": "sha512-e9FBWDe+lv7QKAwtKOt6A2W/fyy/aEEfr0g6j/hWzvQcrzHCsz07BNQYlNOjTfeytrtLU7k449H1PI95jA4OjQ==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@reflink/reflink-win32-arm64-msvc": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink-win32-arm64-msvc/-/reflink-win32-arm64-msvc-0.1.19.tgz",
"integrity": "sha512-09PxnVIQcd+UOn4WAW73WU6PXL7DwGS6wPlkMhMg2zlHHG65F3vHepOw06HFCq+N42qkaNAc8AKIabWvtk6cIQ==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@reflink/reflink-win32-x64-msvc": {
"version": "0.1.19",
"resolved": "https://registry.npmjs.org/@reflink/reflink-win32-x64-msvc/-/reflink-win32-x64-msvc-0.1.19.tgz",
"integrity": "sha512-E//yT4ni2SyhwP8JRjVGWr3cbnhWDiPLgnQ66qqaanjjnMiu3O/2tjCPQXlcGc/DEYofpDc9fvhv6tALQsMV9w==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
}
}
}

View File

@ -1,30 +0,0 @@
{
"name": "bootstrap-pnpm",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"pnpm": "11.0.0-beta.3"
}
},
"node_modules/pnpm": {
"version": "11.0.0-beta.3",
"resolved": "https://registry.npmjs.org/pnpm/-/pnpm-11.0.0-beta.3.tgz",
"integrity": "sha512-6PrfRjycZV4vRX6ttG9oR6pOgbI2/OcF2QLOzHm35UcRuvtqP4zf3wQfAAPwEbeu1uAbpSg/Q5cL8h32tumy6Q==",
"license": "MIT",
"bin": {
"pn": "bin/pnpm.mjs",
"pnpm": "bin/pnpm.mjs",
"pnpx": "bin/pnpx.mjs",
"pnx": "bin/pnpx.mjs"
},
"engines": {
"node": ">=22.13"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
}
}
}

View File

@ -1,158 +1,66 @@
import { addPath, exportVariable } from '@actions/core' import { addPath, exportVariable } from '@actions/core'
import fetch from '@pnpm/fetch'
import { spawn } from 'child_process' import { spawn } from 'child_process'
import { rm, writeFile, mkdir, symlink } from 'fs/promises' import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
import { readFileSync, existsSync } from 'fs'
import path from 'path' import path from 'path'
import util from 'util' import { execPath } from 'process'
import { Inputs } from '../inputs' import { Inputs } from '../inputs'
import { parse as parseYaml } from 'yaml'
import pnpmLock from './bootstrap/pnpm-lock.json'
import exeLock from './bootstrap/exe-lock.json'
const BOOTSTRAP_PNPM_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { pnpm: pnpmLock.packages['node_modules/pnpm'].version } })
const BOOTSTRAP_EXE_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { '@pnpm/exe': exeLock.packages['node_modules/@pnpm/exe'].version } })
export async function runSelfInstaller(inputs: Inputs): Promise<number> { export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest, packageJsonFile } = inputs const { version, dest } = inputs
// pnpm v11 requires Node >= 22.13; use standalone (exe) bootstrap which // prepare self install
// bundles its own Node.js when the system Node is too old await remove(dest)
const systemNode = await getSystemNodeVersion() const pkgJson = path.join(dest, 'package.json')
const standalone = inputs.standalone || systemNode.major < 22 || (systemNode.major === 22 && systemNode.minor < 13) await ensureFile(pkgJson)
await writeFile(pkgJson, JSON.stringify({ private: true }))
// Install bootstrap pnpm via npm (integrity verified by committed lockfile) // prepare target pnpm
await rm(dest, { recursive: true, force: true }) const target = await readTarget(version)
await mkdir(dest, { recursive: true }) const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
})
const lockfile = standalone ? exeLock : pnpmLock const response = await fetch('https://get.pnpm.io/v6.16.js')
const packageJson = standalone ? BOOTSTRAP_EXE_PACKAGE_JSON : BOOTSTRAP_PNPM_PACKAGE_JSON if (!response.body) throw new Error('Did not receive response body')
await writeFile(path.join(dest, 'package.json'), packageJson) response.body.pipe(cp.stdin)
await writeFile(path.join(dest, 'package-lock.json'), JSON.stringify(lockfile))
const npmExitCode = await runCommand('npm', ['ci'], { cwd: dest }) const exitCode = await new Promise<number>((resolve, reject) => {
if (npmExitCode !== 0) { cp.on('error', reject)
return npmExitCode cp.on('close', resolve)
} })
if (exitCode === 0) {
const pnpmHome = path.join(dest, 'node_modules', '.bin') const pnpmHome = path.join(dest, 'node_modules/.bin')
addPath(pnpmHome) addPath(pnpmHome)
addPath(path.join(pnpmHome, 'bin'))
exportVariable('PNPM_HOME', pnpmHome) exportVariable('PNPM_HOME', pnpmHome)
// Ensure pnpm bin link exists — npm ci sometimes doesn't create it
const pnpmBinLink = path.join(pnpmHome, 'pnpm')
if (!existsSync(pnpmBinLink)) {
await mkdir(pnpmHome, { recursive: true })
const target = standalone
? path.join('..', '@pnpm', 'exe', 'pnpm')
: path.join('..', 'pnpm', 'bin', 'pnpm.mjs')
await symlink(target, pnpmBinLink)
} }
const bootstrapPnpm = standalone
? path.join(dest, 'node_modules', '@pnpm', 'exe', 'pnpm')
: path.join(dest, 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')
// Determine the target version
const targetVersion = readTargetVersion({ version, packageJsonFile })
if (targetVersion) {
const cmd = standalone ? bootstrapPnpm : process.execPath
const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
const exitCode = await runCommand(cmd, args, { cwd: dest })
if (exitCode !== 0) {
return exitCode return exitCode
} }
}
return 0 async function readTarget(version?: string | undefined) {
} if (version) return `pnpm@${version}`
function readTargetVersion(opts: {
readonly version?: string | undefined
readonly packageJsonFile: string
}): string | undefined {
const { version, packageJsonFile } = opts
const { GITHUB_WORKSPACE } = process.env const { GITHUB_WORKSPACE } = process.env
let packageManager: string | undefined
let devEngines: { packageManager?: { name?: string; version?: string } } | undefined
if (GITHUB_WORKSPACE) {
try {
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
const manifest = packageJsonFile.endsWith(".yaml")
? parseYaml(content, { merge: true })
: JSON.parse(content)
packageManager = manifest.packageManager
devEngines = manifest.devEngines
} catch (error: unknown) {
// Swallow error if package.json doesn't exist in root
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
}
}
if (version) {
if (
typeof packageManager === 'string' &&
packageManager.startsWith('pnpm@') &&
packageManager.replace('pnpm@', '') !== version
) {
throw new Error(`Multiple versions of pnpm specified:
- version ${version} in the GitHub Action config with the key "version"
- version ${packageManager} in the package.json with the key "packageManager"
Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_PM_VERSION`)
}
return version
}
// pnpm will automatically download and switch to the right version
if (typeof packageManager === 'string' && packageManager.startsWith('pnpm@')) {
return undefined
}
if (devEngines?.packageManager?.name === 'pnpm' && devEngines.packageManager.version) {
return undefined
}
if (!GITHUB_WORKSPACE) { if (!GITHUB_WORKSPACE) {
throw new Error(`No workspace is found. throw new Error(`No workspace is found.
If you've intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file, If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
please run the actions/checkout before pnpm/action-setup. please run the actions/checkout before pnpm/action-setup.
Otherwise, please specify the pnpm version in the action configuration.`) Otherwise, please specify the pnpm version in the action configuration.`)
} }
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, 'package.json'), 'utf8'))
if (typeof packageManager !== 'string') {
throw new Error(`No pnpm version is specified. throw new Error(`No pnpm version is specified.
Please specify it by one of the following ways: Please specify it by one of the following ways:
- in the GitHub Action config with the key "version" - in the GitHub Action config with the key "version"
- in the package.json with the key "packageManager" - in the package.json with the key "packageManager" (See https://nodejs.org/api/corepack.html)`)
- in the package.json with the key "devEngines.packageManager"`)
} }
function getSystemNodeVersion(): Promise<{ major: number; minor: number }> { if (!packageManager.startsWith('pnpm@')) {
return new Promise((resolve) => { throw new Error('Invalid packageManager field in package.json')
const cp = spawn('node', ['--version'], { stdio: ['pipe', 'pipe', 'pipe'], shell: process.platform === 'win32' })
let output = ''
cp.stdout.on('data', (data: Buffer) => { output += data.toString() })
cp.on('close', () => {
const match = output.match(/^v(\d+)\.(\d+)/)
resolve(match ? { major: parseInt(match[1], 10), minor: parseInt(match[2], 10) } : { major: 0, minor: 0 })
})
cp.on('error', () => resolve({ major: 0, minor: 0 }))
})
} }
return packageManager
function runCommand(cmd: string, args: string[], opts: { cwd: string }): Promise<number> {
return new Promise<number>((resolve, reject) => {
const cp = spawn(cmd, args, {
cwd: opts.cwd,
stdio: ['pipe', 'inherit', 'inherit'],
shell: process.platform === 'win32',
})
cp.on('error', reject)
cp.on('close', resolve)
})
} }
export default runSelfInstaller export default runSelfInstaller

View File

@ -6,5 +6,5 @@ export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'no
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({ export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
...process.env, ...process.env,
PATH: path.join(getBinDest(inputs), 'bin') + path.delimiter + getBinDest(inputs) + path.delimiter + process.env.PATH, PATH: getBinDest(inputs) + path.delimiter + process.env.PATH,
}) })

View File

@ -1,19 +1,30 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2022", "target": "ES2018",
"module": "ESNext", "module": "CommonJS",
"moduleResolution": "bundler", "moduleResolution": "Node",
"resolveJsonModule": true, "resolveJsonModule": true,
"lib": [ "lib": [
"ES2023" "ES2018",
"ES2019",
"ES2020",
"ESNext"
], ],
"noEmit": true, "outDir": "./dist/tsc",
"preserveConstEnums": true,
"incremental": false,
"declaration": true,
"sourceMap": true,
"importHelpers": false,
"strict": true, "strict": true,
"pretty": true, "pretty": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"esModuleInterop": true "esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
} }
} }