mirror of
https://github.com/pnpm/action-setup.git
synced 2025-08-20 05:55:49 +08:00
Compare commits
27 Commits
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 |
71
README.md
71
README.md
@@ -6,7 +6,11 @@ Install pnpm package manager.
|
|||||||
|
|
||||||
### `version`
|
### `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`
|
### `dest`
|
||||||
|
|
||||||
@@ -54,12 +58,13 @@ on:
|
|||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
runs-on: ubuntu-latest
|
install:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: pnpm/action-setup@v2.0.1
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
with:
|
with:
|
||||||
version: 6.0.2
|
version: 6.0.2
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install pnpm and a few npm packages
|
### Install pnpm and a few npm packages
|
||||||
@@ -70,18 +75,19 @@ on:
|
|||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
runs-on: ubuntu-latest
|
install:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v2.0.1
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
with:
|
with:
|
||||||
version: 6.0.2
|
version: 6.0.2
|
||||||
run_install: |
|
run_install: |
|
||||||
- recursive: true
|
- recursive: true
|
||||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||||
- args: [--global, gulp, prettier, typescript]
|
- args: [--global, gulp, prettier, typescript]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Use cache to reduce installation time
|
### Use cache to reduce installation time
|
||||||
@@ -92,26 +98,25 @@ on:
|
|||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
runs-on: ubuntu-latest
|
cache-and-install:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
build:
|
build:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Cache pnpm modules
|
- name: Cache pnpm modules
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v2
|
||||||
env:
|
with:
|
||||||
cache-name: cache-pnpm-modules
|
path: ~/.pnpm-store
|
||||||
with:
|
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
path: ~/.pnpm-store
|
restore-keys: |
|
||||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
|
${{ runner.os }}-
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
|
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v2.0.1
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
with:
|
with:
|
||||||
version: 6.0.2
|
version: 6.0.2
|
||||||
run_install: true
|
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.
|
||||||
|
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"
|
"start": "pnpm run build && sh ./run.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-fetch": "^2.6.1",
|
"@actions/core": "^1.6.0",
|
||||||
"expand-tilde": "^2.0.2",
|
"@pnpm/fetch": "^4.2.5",
|
||||||
"js-yaml": "^4.0.0",
|
"@pnpm/logger": "^4.0.0",
|
||||||
"ajv": "^6.12.5",
|
|
||||||
"fs-extra": "^9.1.0",
|
|
||||||
"@actions/core": "^1.2.6",
|
|
||||||
"@types/expand-tilde": "^2.0.0",
|
"@types/expand-tilde": "^2.0.0",
|
||||||
"@types/node-fetch": "^2.5.8",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/js-yaml": "^4.0.0",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/fs-extra": "^9.0.8",
|
"@types/node": "^14.18.10",
|
||||||
"@types/node": "^14.14.35"
|
"@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": {
|
"devDependencies": {
|
||||||
"typescript": "^4.2.3",
|
|
||||||
"@ts-schema-autogen/cli": "^0.1.2",
|
"@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 { setFailed, saveState, getState } from '@actions/core'
|
||||||
import getInputs from './inputs'
|
import getInputs from './inputs'
|
||||||
import setOutputs from './outputs'
|
|
||||||
import installPnpm from './install-pnpm'
|
import installPnpm from './install-pnpm'
|
||||||
|
import setOutputs from './outputs'
|
||||||
import pnpmInstall from './pnpm-install'
|
import pnpmInstall from './pnpm-install'
|
||||||
import pruneStore from './pnpm-store-prune'
|
import pruneStore from './pnpm-store-prune'
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ 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 runInstall: RunInstall[]
|
readonly runInstall: RunInstall[]
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ const options: InputOptions = {
|
|||||||
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
||||||
|
|
||||||
export const getInputs = (): Inputs => ({
|
export const getInputs = (): Inputs => ({
|
||||||
version: getInput('version', options),
|
version: getInput('version'),
|
||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
runInstall: parseRunInstall('run_install'),
|
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 { 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 runInstallSchema from './run-install-input.schema.json'
|
||||||
|
|
||||||
export interface RunInstall {
|
export interface RunInstall {
|
||||||
|
@@ -9,7 +9,7 @@ export async function install(inputs: Inputs) {
|
|||||||
const status = await runSelfInstaller(inputs)
|
const status = await runSelfInstaller(inputs)
|
||||||
endGroup()
|
endGroup()
|
||||||
if (status) {
|
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 { spawn } from 'child_process'
|
||||||
|
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
|
||||||
|
import path from 'path'
|
||||||
import { execPath } from 'process'
|
import { execPath } from 'process'
|
||||||
import { join } from 'path'
|
|
||||||
import { remove, ensureFile, writeFile } from 'fs-extra'
|
|
||||||
import fetch from 'node-fetch'
|
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
const { version, dest } = inputs
|
const { version, dest } = inputs
|
||||||
const target = version ? `pnpm@${version}` : 'pnpm'
|
const pkgJson = path.join(dest, 'package.json')
|
||||||
const pkgJson = join(dest, 'package.json')
|
const target = await readTarget(pkgJson, version)
|
||||||
|
|
||||||
await remove(dest)
|
await remove(dest)
|
||||||
await ensureFile(pkgJson)
|
await ensureFile(pkgJson)
|
||||||
@@ -19,13 +20,37 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
stdio: ['pipe', 'inherit', 'inherit'],
|
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)
|
response.body.pipe(cp.stdin)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
const exitCode = await new Promise<number>((resolve, reject) => {
|
||||||
cp.on('error', reject)
|
cp.on('error', reject)
|
||||||
cp.on('close', resolve)
|
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
|
export default runSelfInstaller
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { spawnSync } from 'child_process'
|
|
||||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||||
|
import { spawnSync } from 'child_process'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import { patchPnpmEnv } from '../utils'
|
import { patchPnpmEnv } from '../utils'
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { spawnSync } from 'child_process'
|
|
||||||
import { warning, startGroup, endGroup } from '@actions/core'
|
import { warning, startGroup, endGroup } from '@actions/core'
|
||||||
|
import { spawnSync } from 'child_process'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import { patchPnpmEnv } from '../utils'
|
import { patchPnpmEnv } from '../utils'
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ export function pruneStore(inputs: Inputs) {
|
|||||||
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
|
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
shell: true,
|
shell: true,
|
||||||
env: patchPnpmEnv(inputs)
|
env: patchPnpmEnv(inputs),
|
||||||
})
|
})
|
||||||
endGroup()
|
endGroup()
|
||||||
|
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import process from 'process'
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import process from 'process'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
|
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
|
||||||
|
|
||||||
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
||||||
...process.env,
|
...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