mirror of
https://github.com/pnpm/action-setup.git
synced 2025-07-07 23:41:04 +08:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
a3252b78c4 | |||
1ee9c9d01d | |||
ebcfd6995d | |||
d2613e087f | |||
d928be8e0c | |||
d882d12c64 | |||
0b715c7ebb | |||
2ed49cbb02 | |||
218cb35941 | |||
3723f63bb4 | |||
849d884800 | |||
f92eb0edb6 | |||
b27f801bf9 | |||
11dd14d0c0 | |||
61eb8c655a | |||
65db188e28 | |||
0609f0983b | |||
7208fa2733 | |||
1bd00a2972 | |||
d5601fb603 | |||
bc06aa6030 | |||
cd2af74528 | |||
c8a150e137 | |||
ed0172a253 | |||
c3b53f6a16 | |||
21e88da200 | |||
fc3334fa11 | |||
d01953a678 | |||
3360b50db7 | |||
6f9e9a867a | |||
537643d491 | |||
f4129fb46e | |||
6e1964dde3 | |||
10693b3829 | |||
99ecd24520 | |||
958500fcab |
14
.github/FUNDING.yml
vendored
14
.github/FUNDING.yml
vendored
@ -1,12 +1,2 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
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']
|
||||
custom:
|
||||
- https://opencollective.com/pnpm
|
||||
|
65
.github/workflows/test.yaml
vendored
65
.github/workflows/test.yaml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
- windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
@ -35,8 +35,8 @@ jobs:
|
||||
- name: 'Test: install'
|
||||
run: pnpm install
|
||||
|
||||
test_explicit_inputs:
|
||||
name: Test with explicit inputs
|
||||
test_dest:
|
||||
name: Test with dest
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
@ -51,7 +51,7 @@ jobs:
|
||||
- windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
@ -65,6 +65,61 @@ jobs:
|
||||
- name: 'Test: install'
|
||||
run: pnpm install
|
||||
|
||||
test_standalone:
|
||||
name: Test with standalone
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
|
||||
standalone:
|
||||
- true
|
||||
- false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
with:
|
||||
version: 7.0.0
|
||||
standalone: ${{ matrix.standalone }}
|
||||
|
||||
- name: install Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
# pnpm@7.0.0 is not compatible with Node.js 12
|
||||
node-version: 12.22.12
|
||||
|
||||
- name: 'Test: which (pnpm)'
|
||||
run: which pnpm
|
||||
|
||||
- name: 'Test: which (pnpx)'
|
||||
if: matrix.standalone == false
|
||||
run: which pnpx
|
||||
|
||||
- name: 'Test: install when standalone is true'
|
||||
if: matrix.standalone
|
||||
run: pnpm install
|
||||
|
||||
- name: 'Test: install when standalone is false'
|
||||
if: matrix.standalone == false
|
||||
# Since the default shell on windows runner is pwsh, we specify bash explicitly
|
||||
shell: bash
|
||||
run: |
|
||||
if pnpm install; then
|
||||
echo "pnpm install should fail"
|
||||
exit 1
|
||||
else
|
||||
echo "pnpm install failed as expected"
|
||||
fi
|
||||
|
||||
test_run_install:
|
||||
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
||||
|
||||
@ -107,7 +162,7 @@ jobs:
|
||||
- pnpm
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,6 +2,8 @@ node_modules
|
||||
*.log
|
||||
/dist/*
|
||||
!/dist/index.js
|
||||
!/dist/pnpm.cjs
|
||||
!/dist/worker.js
|
||||
tmp
|
||||
temp
|
||||
*.tmp
|
||||
|
33
README.md
33
README.md
@ -38,6 +38,16 @@ If `run_install` is a YAML string representation of either an object or an array
|
||||
|
||||
**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` 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
|
||||
|
||||
### `dest`
|
||||
@ -62,9 +72,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v2.1.0
|
||||
- uses: pnpm/action-setup@v3
|
||||
with:
|
||||
version: 6.0.2
|
||||
version: 8
|
||||
```
|
||||
|
||||
### Install pnpm and a few npm packages
|
||||
@ -79,11 +89,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: pnpm/action-setup@v2.1.0
|
||||
- uses: pnpm/action-setup@v3
|
||||
with:
|
||||
version: 6.0.2
|
||||
version: 8
|
||||
run_install: |
|
||||
- recursive: true
|
||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||
@ -105,27 +115,26 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Node.js
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
|
||||
- uses: pnpm/action-setup@v2.0.1
|
||||
- uses: pnpm/action-setup@v3
|
||||
name: Install pnpm
|
||||
id: pnpm-install
|
||||
with:
|
||||
version: 7
|
||||
version: 8
|
||||
run_install: false
|
||||
|
||||
- name: Get pnpm store directory
|
||||
id: pnpm-cache
|
||||
shell: bash
|
||||
run: |
|
||||
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
|
||||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||||
|
||||
- uses: actions/cache@v3
|
||||
name: Setup pnpm cache
|
||||
with:
|
||||
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
|
||||
path: ${{ env.STORE_PATH }}
|
||||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-
|
||||
|
19
action.yml
19
action.yml
@ -1,20 +1,29 @@
|
||||
name: Setup PNPM
|
||||
description: Install PNPM package manager
|
||||
name: Setup pnpm
|
||||
description: Install pnpm package manager
|
||||
branding:
|
||||
icon: package
|
||||
color: orange
|
||||
inputs:
|
||||
version:
|
||||
description: Version of PNPM to install
|
||||
description: Version of pnpm to install
|
||||
required: false
|
||||
dest:
|
||||
description: Where to store PNPM files
|
||||
description: Where to store pnpm files
|
||||
required: false
|
||||
default: ~/setup-pnpm
|
||||
run_install:
|
||||
description: If specified, run `pnpm install`
|
||||
required: false
|
||||
default: 'null'
|
||||
package_json_file:
|
||||
description: File path to the package.json to read "packageManager" configuration
|
||||
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'
|
||||
runs:
|
||||
using: node12
|
||||
using: node20
|
||||
main: dist/index.js
|
||||
post: dist/index.js
|
||||
|
36
dist/index.js
vendored
36
dist/index.js
vendored
File diff suppressed because one or more lines are too long
220780
dist/pnpm.cjs
vendored
Normal file
220780
dist/pnpm.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
16625
dist/worker.js
vendored
Normal file
16625
dist/worker.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@ -1,28 +1,25 @@
|
||||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build:schemas": "ts-schema-autogen generate",
|
||||
"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"
|
||||
"build": "tsc && pnpm run build:ncc",
|
||||
"start": "pnpm run build && sh ./run.sh",
|
||||
"update-pnpm-dist": "pnpm install && cp ./node_modules/pnpm/dist/pnpm.cjs ./dist/pnpm.cjs && cp ./node_modules/pnpm/dist/worker.js ./dist/worker.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.6.0",
|
||||
"@pnpm/fetch": "^4.2.5",
|
||||
"@pnpm/logger": "^4.0.0",
|
||||
"@types/expand-tilde": "^2.0.0",
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"@types/node": "^14.18.10",
|
||||
"@types/node-fetch": "^2.6.1",
|
||||
"ajv": "^6.12.6",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@types/expand-tilde": "^2.0.2",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/node": "^20.11.5",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"expand-tilde": "^2.0.2",
|
||||
"fs-extra": "^10.0.0",
|
||||
"js-yaml": "^4.1.0"
|
||||
"fs-extra": "^11.2.0",
|
||||
"yaml": "^2.3.4",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ts-schema-autogen/cli": "^0.1.2",
|
||||
"@vercel/ncc": "^0.33.3",
|
||||
"typescript": "^4.5.5"
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"pnpm": "^8.14.3",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
|
1132
pnpm-lock.yaml
generated
1132
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
1
run.sh
1
run.sh
@ -4,4 +4,5 @@ export HOME="$(pwd)"
|
||||
export INPUT_VERSION=4.11.1
|
||||
export INPUT_DEST='~/pnpm.temp'
|
||||
export INPUT_RUN_INSTALL=null
|
||||
export INPUT_standalone=false
|
||||
exec node dist/index.js
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getInput, InputOptions } from '@actions/core'
|
||||
import { getBooleanInput, getInput, InputOptions } from '@actions/core'
|
||||
import expandTilde from 'expand-tilde'
|
||||
import { RunInstall, parseRunInstall } from './run-install'
|
||||
|
||||
@ -6,6 +6,8 @@ export interface Inputs {
|
||||
readonly version?: string
|
||||
readonly dest: string
|
||||
readonly runInstall: RunInstall[]
|
||||
readonly packageJsonFile: string
|
||||
readonly standalone: boolean
|
||||
}
|
||||
|
||||
const options: InputOptions = {
|
||||
@ -18,6 +20,8 @@ export const getInputs = (): Inputs => ({
|
||||
version: getInput('version'),
|
||||
dest: parseInputPath('dest'),
|
||||
runInstall: parseRunInstall('run_install'),
|
||||
packageJsonFile: parseInputPath('package_json_file'),
|
||||
standalone: getBooleanInput('standalone'),
|
||||
})
|
||||
|
||||
export default getInputs
|
||||
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"$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"
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
{
|
||||
"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#"
|
||||
}
|
@ -1,39 +1,41 @@
|
||||
import { getInput, error, InputOptions } from '@actions/core'
|
||||
import Ajv from 'ajv'
|
||||
import { load } from 'js-yaml'
|
||||
import process from 'process'
|
||||
import runInstallSchema from './run-install-input.schema.json'
|
||||
import { getInput, error } from '@actions/core'
|
||||
import * as yaml from 'yaml'
|
||||
import { z, ZodError } from 'zod'
|
||||
|
||||
export interface RunInstall {
|
||||
readonly recursive?: boolean
|
||||
readonly cwd?: string
|
||||
readonly args?: readonly string[]
|
||||
}
|
||||
const RunInstallSchema = z.object({
|
||||
recursive: z.boolean().optional(),
|
||||
cwd: z.string().optional(),
|
||||
args: z.array(z.string()).optional(),
|
||||
})
|
||||
|
||||
export type RunInstallInput =
|
||||
| null
|
||||
| boolean
|
||||
| RunInstall
|
||||
| RunInstall[]
|
||||
const RunInstallInputSchema = z.union([
|
||||
z.null(),
|
||||
z.boolean(),
|
||||
RunInstallSchema,
|
||||
z.array(RunInstallSchema),
|
||||
])
|
||||
|
||||
const options: InputOptions = {
|
||||
required: true,
|
||||
}
|
||||
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
|
||||
export type RunInstall = z.infer<typeof RunInstallSchema>
|
||||
|
||||
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)
|
||||
if (!validate(result)) {
|
||||
for (const errorItem of validate.errors!) {
|
||||
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
|
||||
export function parseRunInstall(inputName: string): RunInstall[] {
|
||||
const input = getInput(inputName, { required: true })
|
||||
const parsedInput: unknown = yaml.parse(input)
|
||||
|
||||
try {
|
||||
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
||||
if (!result) return []
|
||||
if (result === true) return [{ recursive: true }]
|
||||
if (Array.isArray(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}`)
|
||||
}
|
||||
return process.exit(1)
|
||||
process.exit(1)
|
||||
}
|
||||
if (!result) return []
|
||||
if (result === true) return [{ recursive: true }]
|
||||
if (Array.isArray(result)) return result
|
||||
return [result]
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { addPath, exportVariable } from '@actions/core'
|
||||
import fetch from '@pnpm/fetch'
|
||||
import { spawn } from 'child_process'
|
||||
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
|
||||
import path from 'path'
|
||||
@ -7,7 +6,7 @@ import { execPath } from 'process'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
const { version, dest } = inputs
|
||||
const { version, dest, packageJsonFile, standalone } = inputs
|
||||
|
||||
// prepare self install
|
||||
await remove(dest)
|
||||
@ -16,16 +15,12 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||
|
||||
// prepare target pnpm
|
||||
const target = await readTarget(version)
|
||||
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
|
||||
const target = await readTarget({ version, packageJsonFile, standalone })
|
||||
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
|
||||
cwd: dest,
|
||||
stdio: ['pipe', 'inherit', 'inherit'],
|
||||
})
|
||||
|
||||
const response = await fetch('https://get.pnpm.io/v6.16.js')
|
||||
if (!response.body) throw new Error('Did not receive response body')
|
||||
response.body.pipe(cp.stdin)
|
||||
|
||||
const exitCode = await new Promise<number>((resolve, reject) => {
|
||||
cp.on('error', reject)
|
||||
cp.on('close', resolve)
|
||||
@ -38,8 +33,14 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
return exitCode
|
||||
}
|
||||
|
||||
async function readTarget(version?: string | undefined) {
|
||||
if (version) return `pnpm@${version}`
|
||||
async function readTarget(opts: {
|
||||
readonly version?: string | undefined
|
||||
readonly packageJsonFile: string
|
||||
readonly standalone: boolean
|
||||
}) {
|
||||
const { version, packageJsonFile, standalone } = opts
|
||||
|
||||
if (version) return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||
|
||||
const { GITHUB_WORKSPACE } = process.env
|
||||
if (!GITHUB_WORKSPACE) {
|
||||
@ -49,17 +50,22 @@ please run the actions/checkout before pnpm/action-setup.
|
||||
Otherwise, please specify the pnpm version in the action configuration.`)
|
||||
}
|
||||
|
||||
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, 'package.json'), 'utf8'))
|
||||
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8'))
|
||||
if (typeof packageManager !== 'string') {
|
||||
throw new Error(`No pnpm version is specified.
|
||||
Please specify it by one of the following ways:
|
||||
- in the GitHub Action config with the key "version"
|
||||
- in the package.json with the key "packageManager" (See https://nodejs.org/api/corepack.html)`)
|
||||
- in the package.json with the key "packageManager"`)
|
||||
}
|
||||
|
||||
if (!packageManager.startsWith('pnpm@')) {
|
||||
throw new Error('Invalid packageManager field in package.json')
|
||||
}
|
||||
|
||||
if(standalone){
|
||||
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
||||
}
|
||||
|
||||
return packageManager
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,11 @@
|
||||
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2018",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"target": "ES2022",
|
||||
"module": "Node16",
|
||||
"resolveJsonModule": true,
|
||||
"lib": [
|
||||
"ES2018",
|
||||
"ES2019",
|
||||
"ES2020",
|
||||
"ESNext"
|
||||
"ES2023"
|
||||
],
|
||||
"outDir": "./dist/tsc",
|
||||
"preserveConstEnums": true,
|
||||
|
Reference in New Issue
Block a user