mirror of
https://github.com/pnpm/action-setup.git
synced 2025-07-07 19:40:26 +08:00
Compare commits
31 Commits
v2.0.0-rc.
...
v2.2.0
Author | SHA1 | Date | |
---|---|---|---|
11ba3424e0 | |||
847a737d63 | |||
225f3bb4b0 | |||
777a50d72e | |||
e7c10c6fc5 | |||
a576a70bc6 | |||
1d51e20937 | |||
ad2b35ae0c | |||
d8ea532ac4 | |||
2270f39ef6 | |||
394c848db6 | |||
e13928ccc5 | |||
93bd5a123d | |||
9eb14dd77c | |||
eafb777c56 | |||
e6378df420 | |||
6ff6e97bc6 | |||
45d9c91ff6 | |||
15569a497d | |||
d70eebd14a | |||
3bf8acf16f | |||
3c2fe8c592 | |||
76cc04cd5e | |||
bcad811784 | |||
602b36f177 | |||
74a0fdc1a4 | |||
493e98ec5e | |||
646cdf4821 | |||
a1ba6cf5ae | |||
41b381a08b | |||
3236b209b5 |
81
README.md
81
README.md
@ -1,16 +1,20 @@
|
||||
# Setup PNPM
|
||||
# Setup pnpm
|
||||
|
||||
Install PNPM package manager.
|
||||
Install pnpm package manager.
|
||||
|
||||
## Inputs
|
||||
|
||||
### `version`
|
||||
|
||||
**Required** Version of PNPM to install.
|
||||
Version of pnpm to install.
|
||||
|
||||
**Optional** when there is a [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
|
||||
|
||||
otherwise, this field is **required** It supports npm versioning scheme, it could be an exact version (such as `6.24.1`), or a version range (such as `6`, `6.x.x`, `6.24.x`, `^6.24.1`, `*`, etc.), or `latest`.
|
||||
|
||||
### `dest`
|
||||
|
||||
**Optional** Where to store PNPM files.
|
||||
**Optional** Where to store pnpm files.
|
||||
|
||||
### `run_install`
|
||||
|
||||
@ -46,7 +50,7 @@ Location of `pnpm` and `pnpx` command.
|
||||
|
||||
## Usage example
|
||||
|
||||
### Just install PNPM
|
||||
### Just install pnpm
|
||||
|
||||
```yaml
|
||||
on:
|
||||
@ -54,15 +58,16 @@ on:
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
runs-on: ubuntu-latest
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.2
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v2.1.0
|
||||
with:
|
||||
version: 6.0.2
|
||||
```
|
||||
|
||||
### Install PNPM and a few NPM packages
|
||||
### Install pnpm and a few npm packages
|
||||
|
||||
```yaml
|
||||
on:
|
||||
@ -70,18 +75,19 @@ on:
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
runs-on: ubuntu-latest
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.2
|
||||
run_install: |
|
||||
- recursive: true
|
||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||
- args: [--global, gulp, prettier, typescript]
|
||||
- uses: pnpm/action-setup@v2.1.0
|
||||
with:
|
||||
version: 6.0.2
|
||||
run_install: |
|
||||
- recursive: true
|
||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||
- args: [--global, gulp, prettier, typescript]
|
||||
```
|
||||
|
||||
### Use cache to reduce installation time
|
||||
@ -92,26 +98,25 @@ on:
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
runs-on: ubuntu-latest
|
||||
cache-and-install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
build:
|
||||
- uses: actions/checkout@v2
|
||||
steps:
|
||||
build:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Cache pnpm modules
|
||||
uses: actions/cache@v2
|
||||
env:
|
||||
cache-name: cache-pnpm-modules
|
||||
with:
|
||||
path: ~/.pnpm-store
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
|
||||
- name: Cache pnpm modules
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.pnpm-store
|
||||
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-
|
||||
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.2
|
||||
run_install: true
|
||||
- uses: pnpm/action-setup@v2.1.0
|
||||
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.
|
||||
|
39
dist/index.js
vendored
39
dist/index.js
vendored
File diff suppressed because one or more lines are too long
25
package.json
25
package.json
@ -7,21 +7,22 @@
|
||||
"start": "pnpm run build && sh ./run.sh"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.6.1",
|
||||
"expand-tilde": "^2.0.2",
|
||||
"js-yaml": "^4.0.0",
|
||||
"ajv": "^6.12.5",
|
||||
"fs-extra": "^9.1.0",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/core": "^1.6.0",
|
||||
"@pnpm/fetch": "^4.2.5",
|
||||
"@pnpm/logger": "^4.0.0",
|
||||
"@types/expand-tilde": "^2.0.0",
|
||||
"@types/node-fetch": "^2.5.8",
|
||||
"@types/js-yaml": "^4.0.0",
|
||||
"@types/fs-extra": "^9.0.8",
|
||||
"@types/node": "^14.14.35"
|
||||
"@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",
|
||||
"expand-tilde": "^2.0.2",
|
||||
"fs-extra": "^10.0.0",
|
||||
"js-yaml": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^4.2.3",
|
||||
"@ts-schema-autogen/cli": "^0.1.2",
|
||||
"@vercel/ncc": "^0.27.0"
|
||||
"@vercel/ncc": "^0.33.3",
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
1270
pnpm-lock.yaml
generated
1270
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
import { setFailed, saveState, getState } from '@actions/core'
|
||||
import getInputs from './inputs'
|
||||
import setOutputs from './outputs'
|
||||
import installPnpm from './install-pnpm'
|
||||
import setOutputs from './outputs'
|
||||
import pnpmInstall from './pnpm-install'
|
||||
import pruneStore from './pnpm-store-prune'
|
||||
|
||||
|
@ -3,7 +3,7 @@ import expandTilde from 'expand-tilde'
|
||||
import { RunInstall, parseRunInstall } from './run-install'
|
||||
|
||||
export interface Inputs {
|
||||
readonly version: string
|
||||
readonly version?: string
|
||||
readonly dest: string
|
||||
readonly runInstall: RunInstall[]
|
||||
}
|
||||
@ -15,7 +15,7 @@ const options: InputOptions = {
|
||||
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
||||
|
||||
export const getInputs = (): Inputs => ({
|
||||
version: getInput('version', options),
|
||||
version: getInput('version'),
|
||||
dest: parseInputPath('dest'),
|
||||
runInstall: parseRunInstall('run_install'),
|
||||
})
|
||||
|
@ -1,7 +1,7 @@
|
||||
import process from 'process'
|
||||
import { load } from 'js-yaml'
|
||||
import Ajv from 'ajv'
|
||||
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'
|
||||
|
||||
export interface RunInstall {
|
||||
|
@ -9,7 +9,7 @@ export async function install(inputs: Inputs) {
|
||||
const status = await runSelfInstaller(inputs)
|
||||
endGroup()
|
||||
if (status) {
|
||||
return setFailed(`Something does wrong, self-installer exits with code ${status}`)
|
||||
return setFailed(`Something went wrong, self-installer exits with code ${status}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
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'
|
||||
import { execPath } from 'process'
|
||||
import { join } from 'path'
|
||||
import { remove, ensureFile, writeFile } from 'fs-extra'
|
||||
import fetch from 'node-fetch'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
const { version, dest } = inputs
|
||||
const target = version ? `pnpm@${version}` : 'pnpm'
|
||||
const pkgJson = join(dest, 'package.json')
|
||||
const pkgJson = path.join(dest, 'package.json')
|
||||
const target = await readTarget(pkgJson, version)
|
||||
|
||||
await remove(dest)
|
||||
await ensureFile(pkgJson)
|
||||
@ -19,13 +20,37 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
stdio: ['pipe', 'inherit', 'inherit'],
|
||||
})
|
||||
|
||||
const response = await fetch('https://pnpm.js.org/pnpm.js')
|
||||
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)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const exitCode = await new Promise<number>((resolve, reject) => {
|
||||
cp.on('error', reject)
|
||||
cp.on('close', resolve)
|
||||
})
|
||||
if (exitCode === 0) {
|
||||
const pnpmHome = path.join(dest, 'node_modules/.bin')
|
||||
addPath(pnpmHome)
|
||||
exportVariable('PNPM_HOME', pnpmHome)
|
||||
}
|
||||
return exitCode
|
||||
}
|
||||
|
||||
async function readTarget(packageJsonPath: string, version?: string | undefined) {
|
||||
if (version) return `pnpm@${version}`
|
||||
|
||||
const { packageManager } = JSON.parse(await readFile(packageJsonPath, '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)`)
|
||||
}
|
||||
|
||||
if (!packageManager.startsWith('pnpm@')) {
|
||||
throw new Error('Invalid packageManager field in package.json')
|
||||
}
|
||||
return packageManager
|
||||
}
|
||||
|
||||
export default runSelfInstaller
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { spawnSync } from 'child_process'
|
||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||
import { spawnSync } from 'child_process'
|
||||
import { Inputs } from '../inputs'
|
||||
import { patchPnpmEnv } from '../utils'
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { spawnSync } from 'child_process'
|
||||
import { warning, startGroup, endGroup } from '@actions/core'
|
||||
import { spawnSync } from 'child_process'
|
||||
import { Inputs } from '../inputs'
|
||||
import { patchPnpmEnv } from '../utils'
|
||||
|
||||
@ -13,7 +13,7 @@ export function pruneStore(inputs: Inputs) {
|
||||
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
env: patchPnpmEnv(inputs)
|
||||
env: patchPnpmEnv(inputs),
|
||||
})
|
||||
endGroup()
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import process from 'process'
|
||||
import path from 'path'
|
||||
import process from 'process'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
|
||||
|
||||
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
||||
...process.env,
|
||||
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH
|
||||
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH,
|
||||
})
|
||||
|
Reference in New Issue
Block a user