1
0
mirror of https://github.com/pnpm/action-setup.git synced 2026-06-26 16:43:47 +08:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Zoltan Kochan
1682287a8f test: update pnpm to v9 2025-02-06 22:22:33 +01:00
8 changed files with 17 additions and 48 deletions

View File

@@ -121,7 +121,7 @@ jobs:
fi
test_run_install:
name: 'Test with run_install (${{ matrix.run_install.name }}, prune=${{matrix.store_prune}}, ${{ matrix.os }})'
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
runs-on: ${{ matrix.os }}
@@ -158,9 +158,6 @@ jobs:
- --global-dir=./pnpm-global
- npm
- yarn
store_prune:
- 'true'
- 'false'
steps:
- uses: actions/checkout@v4
@@ -170,7 +167,6 @@ jobs:
with:
version: 9.15.5
run_install: ${{ matrix.run_install.value }}
store_prune: ${{ matrix.store_prune }}
- name: 'Test: which'
run: which pnpm; which pnpx

View File

@@ -30,8 +30,6 @@ If `run_install` is `true`, pnpm will install dependencies recursively.
If `run_install` is a YAML string representation of either an object or an array, pnpm will execute every install commands.
If any `run_install` is not falsy, and `store_prune` is not set to `false`, `pnpm store prune` will be executed after all install commands have been executed. This is to ensure the pnpm store is pruned before caching.
#### `run_install.recursive`
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to use `pnpm recursive install`.
@@ -42,15 +40,11 @@ If any `run_install` is not falsy, and `store_prune` is not set to `false`, `pnp
#### `run_install.args`
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--ignore-scripts, --strict-peer-dependencies]`.
#### `store_prune`
**Optional** (_type:_ `boolean`, _default:_ `true`) Whether to run `pnpm store prune` after installation. If `run_install` is falsy, this option will be ignored. If you run `pnpm install` on your own, and intend to cache the pnpm store, it's recommended to run `pnpm store prune` yourself to make sure the store that will be cached is pruned.
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
### `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.
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json` to read "packageManager" configuration.
### `standalone`
@@ -123,9 +117,9 @@ jobs:
- uses: pnpm/action-setup@v4
with:
version: 10
run_install:
run_install: |
- recursive: true
args: [--strict-peer-dependencies]
args: [--frozen-lockfile, --strict-peer-dependencies]
- args: [--global, gulp, prettier, typescript]
```
@@ -158,12 +152,9 @@ jobs:
- name: Install dependencies
run: pnpm install
- name: Prune pnpm store
run: pnpm store prune
```
**Note:** If you you opt to run install on your own (`run_install: false`), it's recommended to run [`pnpm store prune`](https://pnpm.io/cli/store#prune) after installation to make sure the store that will be cached is pruned.
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
## Notes

View File

@@ -15,10 +15,6 @@ inputs:
description: If specified, run `pnpm install`
required: false
default: 'null'
store_prune:
description: Enable store pruning after installation. Set to false to disable.
required: false
default: 'true'
package_json_file:
description: File path to the package.json to read "packageManager" configuration
required: false
@@ -35,3 +31,4 @@ outputs:
runs:
using: node20
main: dist/index.js
post: dist/index.js

6
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,4 @@
import { setFailed } from '@actions/core'
import { setFailed, saveState, getState } from '@actions/core'
import getInputs from './inputs'
import installPnpm from './install-pnpm'
import setOutputs from './outputs'
@@ -7,11 +7,13 @@ import pruneStore from './pnpm-store-prune'
async function main() {
const inputs = getInputs()
const isPost = getState('is_post')
if (isPost === 'true') return pruneStore(inputs)
saveState('is_post', 'true')
await installPnpm(inputs)
console.log('Installation Completed!')
setOutputs(inputs)
pnpmInstall(inputs)
pruneStore(inputs)
}
main().catch(error => {

View File

@@ -6,7 +6,6 @@ export interface Inputs {
readonly version?: string
readonly dest: string
readonly runInstall: RunInstall[]
readonly storePrune: boolean
readonly packageJsonFile: string
readonly standalone: boolean
}
@@ -21,7 +20,6 @@ export const getInputs = (): Inputs => ({
version: getInput('version'),
dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'),
storePrune: getBooleanInput('store_prune'),
packageJsonFile: parseInputPath('package_json_file'),
standalone: getBooleanInput('standalone'),
})

View File

@@ -1,6 +1,6 @@
import { addPath, exportVariable } from '@actions/core'
import { spawn } from 'child_process'
import { rm, writeFile, mkdir, copyFile } from 'fs/promises'
import { rm, writeFile, mkdir } from 'fs/promises'
import { readFileSync } from 'fs'
import path from 'path'
import { execPath } from 'process'
@@ -10,7 +10,6 @@ import YAML from 'yaml'
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest, packageJsonFile, standalone } = inputs
const { GITHUB_WORKSPACE } = process.env
// prepare self install
await rm(dest, { recursive: true, force: true })
@@ -20,16 +19,6 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
// we have ensured the dest directory exists, we can write the file directly
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
const target = await readTarget({ version, packageJsonFile, standalone })
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
@@ -75,7 +64,6 @@ async function readTarget(opts: {
if (version) {
if (
typeof packageManager === 'string' &&
packageManager.startsWith('pnpm@') &&
packageManager.replace('pnpm@', '') !== version
) {
throw new Error(`Multiple versions of pnpm specified:

View File

@@ -5,12 +5,7 @@ import { patchPnpmEnv } from '../utils'
export function pruneStore(inputs: Inputs) {
if (inputs.runInstall.length === 0) {
console.log('No install commands were run, skipping pnpm store prune, remember to run it after pnpm install if caching the store.')
return
}
if (!inputs.storePrune) {
console.log('Store pruning is disabled, skipping pnpm store prune.')
console.log('Pruning is unnecessary.')
return
}