mirror of
https://github.com/pnpm/action-setup.git
synced 2026-06-26 16:43:47 +08:00
Compare commits
15 Commits
v4.1.0
...
8a1f0929f7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a1f0929f7 | ||
|
|
3a0024f066 | ||
|
|
72f04517b7 | ||
|
|
35353b8037 | ||
|
|
4f04570f82 | ||
|
|
40fbc12c16 | ||
|
|
14f23f2699 | ||
|
|
6a5147c614 | ||
|
|
82352014bc | ||
|
|
37f0218d62 | ||
|
|
3cec5320c9 | ||
|
|
41ff726559 | ||
|
|
f2b2b233b5 | ||
|
|
77504a59bc | ||
|
|
d648c2dd06 |
6
.github/workflows/test.yaml
vendored
6
.github/workflows/test.yaml
vendored
@@ -121,7 +121,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
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 }}, prune=${{matrix.store_prune}}, ${{ matrix.os }})'
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
@@ -158,6 +158,9 @@ jobs:
|
|||||||
- --global-dir=./pnpm-global
|
- --global-dir=./pnpm-global
|
||||||
- npm
|
- npm
|
||||||
- yarn
|
- yarn
|
||||||
|
store_prune:
|
||||||
|
- 'true'
|
||||||
|
- 'false'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -167,6 +170,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
version: 9.15.5
|
version: 9.15.5
|
||||||
run_install: ${{ matrix.run_install.value }}
|
run_install: ${{ matrix.run_install.value }}
|
||||||
|
store_prune: ${{ matrix.store_prune }}
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
run: which pnpm; which pnpx
|
run: which pnpm; which pnpx
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -30,6 +30,8 @@ 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 `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`
|
#### `run_install.recursive`
|
||||||
|
|
||||||
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to use `pnpm recursive install`.
|
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to use `pnpm recursive install`.
|
||||||
@@ -40,7 +42,11 @@ 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]`.
|
||||||
|
|
||||||
|
#### `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.
|
||||||
|
|
||||||
### `package_json_file`
|
### `package_json_file`
|
||||||
|
|
||||||
@@ -119,7 +125,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]
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -152,9 +158,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: Prune pnpm store
|
||||||
|
run: pnpm store prune
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
|
**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.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ inputs:
|
|||||||
description: If specified, run `pnpm install`
|
description: If specified, run `pnpm install`
|
||||||
required: false
|
required: false
|
||||||
default: 'null'
|
default: 'null'
|
||||||
|
store_prune:
|
||||||
|
description: Enable store pruning after installation. Set to false to disable.
|
||||||
|
required: false
|
||||||
|
default: 'true'
|
||||||
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
|
||||||
required: false
|
required: false
|
||||||
@@ -31,4 +35,3 @@ outputs:
|
|||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node20
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
post: dist/index.js
|
|
||||||
|
|||||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -10,7 +10,6 @@
|
|||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@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"
|
||||||
|
|||||||
54
pnpm-lock.yaml
generated
54
pnpm-lock.yaml
generated
@@ -17,9 +17,6 @@ importers:
|
|||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^20.11.5
|
specifier: ^20.11.5
|
||||||
version: 20.17.17
|
version: 20.17.17
|
||||||
'@types/node-fetch':
|
|
||||||
specifier: ^2.6.11
|
|
||||||
version: 2.6.12
|
|
||||||
expand-tilde:
|
expand-tilde:
|
||||||
specifier: ^2.0.2
|
specifier: ^2.0.2
|
||||||
version: 2.0.2
|
version: 2.0.2
|
||||||
@@ -57,9 +54,6 @@ packages:
|
|||||||
'@types/expand-tilde@2.0.2':
|
'@types/expand-tilde@2.0.2':
|
||||||
resolution: {integrity: sha512-wlsMYiapmIR4Eq/Z0qysN8xaDMjSkO6AIDNFx9oxgWGeKVA1jU+NzwPRZErBNP5z6/dx6QNkNpKglBGPO9OkTA==}
|
resolution: {integrity: sha512-wlsMYiapmIR4Eq/Z0qysN8xaDMjSkO6AIDNFx9oxgWGeKVA1jU+NzwPRZErBNP5z6/dx6QNkNpKglBGPO9OkTA==}
|
||||||
|
|
||||||
'@types/node-fetch@2.6.12':
|
|
||||||
resolution: {integrity: sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA==}
|
|
||||||
|
|
||||||
'@types/node@20.17.17':
|
'@types/node@20.17.17':
|
||||||
resolution: {integrity: sha512-/WndGO4kIfMicEQLTi/mDANUu/iVUhT7KboZPdEqqHQ4aTS+3qT3U5gIqWDFV+XouorjfgGqvKILJeHhuQgFYg==}
|
resolution: {integrity: sha512-/WndGO4kIfMicEQLTi/mDANUu/iVUhT7KboZPdEqqHQ4aTS+3qT3U5gIqWDFV+XouorjfgGqvKILJeHhuQgFYg==}
|
||||||
|
|
||||||
@@ -67,37 +61,14 @@ packages:
|
|||||||
resolution: {integrity: sha512-rnK6hJBS6mwc+Bkab+PGPs9OiS0i/3kdTO+CkI8V0/VrW3vmz7O2Pxjw/owOlmo6PKEIxRSeZKv/kuL9itnpYA==}
|
resolution: {integrity: sha512-rnK6hJBS6mwc+Bkab+PGPs9OiS0i/3kdTO+CkI8V0/VrW3vmz7O2Pxjw/owOlmo6PKEIxRSeZKv/kuL9itnpYA==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
asynckit@0.4.0:
|
|
||||||
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
|
|
||||||
|
|
||||||
combined-stream@1.0.8:
|
|
||||||
resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
|
|
||||||
engines: {node: '>= 0.8'}
|
|
||||||
|
|
||||||
delayed-stream@1.0.0:
|
|
||||||
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
|
|
||||||
engines: {node: '>=0.4.0'}
|
|
||||||
|
|
||||||
expand-tilde@2.0.2:
|
expand-tilde@2.0.2:
|
||||||
resolution: {integrity: sha512-A5EmesHW6rfnZ9ysHQjPdJRni0SRar0tjtG5MNtm9n5TUvsYU8oozprtRD4AqHxcZWWlVuAmQo2nWKfN9oyjTw==}
|
resolution: {integrity: sha512-A5EmesHW6rfnZ9ysHQjPdJRni0SRar0tjtG5MNtm9n5TUvsYU8oozprtRD4AqHxcZWWlVuAmQo2nWKfN9oyjTw==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
|
||||||
form-data@4.0.1:
|
|
||||||
resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==}
|
|
||||||
engines: {node: '>= 6'}
|
|
||||||
|
|
||||||
homedir-polyfill@1.0.3:
|
homedir-polyfill@1.0.3:
|
||||||
resolution: {integrity: sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==}
|
resolution: {integrity: sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
|
||||||
mime-db@1.52.0:
|
|
||||||
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
|
|
||||||
engines: {node: '>= 0.6'}
|
|
||||||
|
|
||||||
mime-types@2.1.35:
|
|
||||||
resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
|
|
||||||
engines: {node: '>= 0.6'}
|
|
||||||
|
|
||||||
parse-passwd@1.0.0:
|
parse-passwd@1.0.0:
|
||||||
resolution: {integrity: sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==}
|
resolution: {integrity: sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
@@ -146,45 +117,20 @@ snapshots:
|
|||||||
|
|
||||||
'@types/expand-tilde@2.0.2': {}
|
'@types/expand-tilde@2.0.2': {}
|
||||||
|
|
||||||
'@types/node-fetch@2.6.12':
|
|
||||||
dependencies:
|
|
||||||
'@types/node': 20.17.17
|
|
||||||
form-data: 4.0.1
|
|
||||||
|
|
||||||
'@types/node@20.17.17':
|
'@types/node@20.17.17':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 6.19.8
|
undici-types: 6.19.8
|
||||||
|
|
||||||
'@vercel/ncc@0.38.3': {}
|
'@vercel/ncc@0.38.3': {}
|
||||||
|
|
||||||
asynckit@0.4.0: {}
|
|
||||||
|
|
||||||
combined-stream@1.0.8:
|
|
||||||
dependencies:
|
|
||||||
delayed-stream: 1.0.0
|
|
||||||
|
|
||||||
delayed-stream@1.0.0: {}
|
|
||||||
|
|
||||||
expand-tilde@2.0.2:
|
expand-tilde@2.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
homedir-polyfill: 1.0.3
|
homedir-polyfill: 1.0.3
|
||||||
|
|
||||||
form-data@4.0.1:
|
|
||||||
dependencies:
|
|
||||||
asynckit: 0.4.0
|
|
||||||
combined-stream: 1.0.8
|
|
||||||
mime-types: 2.1.35
|
|
||||||
|
|
||||||
homedir-polyfill@1.0.3:
|
homedir-polyfill@1.0.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
parse-passwd: 1.0.0
|
parse-passwd: 1.0.0
|
||||||
|
|
||||||
mime-db@1.52.0: {}
|
|
||||||
|
|
||||||
mime-types@2.1.35:
|
|
||||||
dependencies:
|
|
||||||
mime-db: 1.52.0
|
|
||||||
|
|
||||||
parse-passwd@1.0.0: {}
|
parse-passwd@1.0.0: {}
|
||||||
|
|
||||||
pnpm@8.15.9: {}
|
pnpm@8.15.9: {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { setFailed, saveState, getState } from '@actions/core'
|
import { setFailed } from '@actions/core'
|
||||||
import getInputs from './inputs'
|
import getInputs from './inputs'
|
||||||
import installPnpm from './install-pnpm'
|
import installPnpm from './install-pnpm'
|
||||||
import setOutputs from './outputs'
|
import setOutputs from './outputs'
|
||||||
@@ -7,13 +7,11 @@ 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)
|
|
||||||
saveState('is_post', 'true')
|
|
||||||
await installPnpm(inputs)
|
await installPnpm(inputs)
|
||||||
console.log('Installation Completed!')
|
console.log('Installation Completed!')
|
||||||
setOutputs(inputs)
|
setOutputs(inputs)
|
||||||
pnpmInstall(inputs)
|
pnpmInstall(inputs)
|
||||||
|
pruneStore(inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(error => {
|
main().catch(error => {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export interface Inputs {
|
|||||||
readonly version?: string
|
readonly version?: string
|
||||||
readonly dest: string
|
readonly dest: string
|
||||||
readonly runInstall: RunInstall[]
|
readonly runInstall: RunInstall[]
|
||||||
|
readonly storePrune: boolean
|
||||||
readonly packageJsonFile: string
|
readonly packageJsonFile: string
|
||||||
readonly standalone: boolean
|
readonly standalone: boolean
|
||||||
}
|
}
|
||||||
@@ -20,6 +21,7 @@ export const getInputs = (): Inputs => ({
|
|||||||
version: getInput('version'),
|
version: getInput('version'),
|
||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
runInstall: parseRunInstall('run_install'),
|
runInstall: parseRunInstall('run_install'),
|
||||||
|
storePrune: getBooleanInput('store_prune'),
|
||||||
packageJsonFile: parseInputPath('package_json_file'),
|
packageJsonFile: parseInputPath('package_json_file'),
|
||||||
standalone: getBooleanInput('standalone'),
|
standalone: getBooleanInput('standalone'),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
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'
|
||||||
@@ -10,6 +10,7 @@ import YAML 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'], {
|
||||||
@@ -64,6 +75,7 @@ async function readTarget(opts: {
|
|||||||
if (version) {
|
if (version) {
|
||||||
if (
|
if (
|
||||||
typeof packageManager === 'string' &&
|
typeof packageManager === 'string' &&
|
||||||
|
packageManager.startsWith('pnpm@') &&
|
||||||
packageManager.replace('pnpm@', '') !== version
|
packageManager.replace('pnpm@', '') !== version
|
||||||
) {
|
) {
|
||||||
throw new Error(`Multiple versions of pnpm specified:
|
throw new Error(`Multiple versions of pnpm specified:
|
||||||
|
|||||||
@@ -5,7 +5,12 @@ import { patchPnpmEnv } from '../utils'
|
|||||||
|
|
||||||
export function pruneStore(inputs: Inputs) {
|
export function pruneStore(inputs: Inputs) {
|
||||||
if (inputs.runInstall.length === 0) {
|
if (inputs.runInstall.length === 0) {
|
||||||
console.log('Pruning is unnecessary.')
|
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.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user