70 Commits

Author SHA1 Message Date
2270f39ef6 v2.1.0 2022-02-08 19:53:18 +07:00
394c848db6 Update the bundle 2022-02-08 19:50:57 +07:00
e13928ccc5 Merge pull request #27 from metonym/fix-jobs-syntax
Specify job name to fix syntax error
2022-02-08 19:48:36 +07:00
93bd5a123d Merge pull request #29 from pnpm/pnpm-v7
The pnpm home directory should be added to PATH and PNPM_HOME
2022-02-08 19:47:28 +07:00
9eb14dd77c decrease bundle size 2022-02-08 14:44:50 +02:00
eafb777c56 download script from pnpm.io 2022-02-08 00:39:20 +02:00
e6378df420 PNPM_HOME_PATH=>PNPM_HOME 2022-02-08 00:21:53 +02:00
6ff6e97bc6 The pnpm home directory should be added to PATH and PNPM_HOME
This change is needed to make the action compatible with pnpm v7.

Related breaking change in pnpm: pnpm/pnpm#4280
2022-02-07 23:15:44 +02:00
45d9c91ff6 Specify job name to fix syntax error 2022-01-29 08:17:29 -08:00
15569a497d Merge pull request #26 from ai/patch-1
Improve `version` docs
2021-12-16 21:20:06 +07:00
d70eebd14a Update README.md
Co-authored-by: Khải <hvksmr1996@gmail.com>
2021-12-16 17:18:46 +03:00
3bf8acf16f Improve version docs 2021-12-16 17:12:07 +03:00
3c2fe8c592 Merge pull request #21 from gaggle/patch-1
Spelling
2021-10-12 19:45:45 +07:00
76cc04cd5e Spelling 2021-10-12 13:34:10 +02:00
bcad811784 Remove unused env from examples 2021-07-24 08:25:23 +07:00
602b36f177 Remove uses of undefined variables from examples 2021-07-24 08:22:22 +07:00
74a0fdc1a4 Merge pull request #14 from Jack-Works-forks/master
Update README: use lockfile hash instead of package.json hash
2021-06-01 09:44:13 +07:00
493e98ec5e Update README.md 2021-06-01 10:42:26 +08:00
646cdf4821 Update versions in README examples to the latest 2021-04-24 21:13:36 +07:00
a1ba6cf5ae Merge pull request #11 from pnpm/zkochan-patch-1
docs(readme): PNPM=>pnpm
2021-03-27 18:50:58 +07:00
41b381a08b docs(readme): PNPM=>pnpm 2021-03-27 13:45:01 +02:00
3236b209b5 Merge branch 'v2' 2021-03-27 16:56:27 +07:00
2124926520 Update README.md 2021-03-23 12:53:37 +07:00
ba9826e81c Update test workflow 2021-03-23 12:53:25 +07:00
7c4472dbcf Forgot to specify working directory 2021-03-23 12:48:54 +07:00
0db7fb9961 Add .pnpm-store to .gitignore 2021-03-23 12:48:07 +07:00
aefcd1e623 Use pnpm.js to install pnpm 2021-03-23 12:42:43 +07:00
b7b9d6344b Instruct renovate to ignore ajv updates 2021-03-23 11:47:55 +07:00
7e61ea5847 Add "$schema" to renovate.json 2021-03-23 11:46:56 +07:00
3a2c7247e1 Fix js-yaml usage 2021-03-23 11:43:49 +07:00
2a105263a5 Update dependencies 2021-03-23 11:43:36 +07:00
9facd4db8e Merge pull request #9 from hildjj/cache-docs
Adds documentation hints for caching
2021-02-18 08:31:04 +07:00
6c1466d327 Make some tweaks to example code snippets 2021-02-18 08:30:07 +07:00
b26427e53e Adds documentation hints for caching. Fixes #8. 2021-02-17 09:45:25 -07:00
086f5bd3b6 Update README.md
close https://github.com/pnpm/action-setup/issues/6
2020-10-19 14:10:51 +07:00
bdb2a5ee76 Enable Dependabot 2020-10-05 22:16:14 +07:00
8e1abe543f Update dist/index.js 2020-10-05 21:51:43 +07:00
af6247d08a Fix https://github.com/pnpm/action-setup/issues/5 2020-10-05 21:45:45 +07:00
f87c8a916e Fix TypeScript error 2020-10-05 21:45:20 +07:00
d6790970e0 Update dependencies 2020-10-05 21:44:44 +07:00
fa62771e12 Add workflow_dispatch event 2020-08-27 08:25:30 +07:00
935101478d v1.2.0 2020-05-10 12:17:17 +07:00
4abca36d2a Merge pull request #2 from pnpm/install-command
Support install command
2020-05-10 12:16:23 +07:00
56013f801f Add more examples 2020-05-10 12:14:27 +07:00
fb99aeb8e3 Describe run_install in more details 2020-05-10 12:08:45 +07:00
b78eaea668 Describe default values 2020-05-10 12:00:23 +07:00
83681c63a7 Make logs foldable 2020-05-09 21:50:47 +07:00
6eb237a86d Only warn on failure of post action 2020-05-09 21:43:19 +07:00
b1febf84ed Fix pruneStore 2020-05-09 21:41:25 +07:00
2546768411 Add matrix.os to name 2020-05-09 21:35:09 +07:00
8cdddb18c5 Try fixing 2020-05-09 21:33:18 +07:00
4457a83971 Test with run_install 2020-05-09 21:26:17 +07:00
c8fc1974e1 Run pnpm store prune post action 2020-05-09 21:15:50 +07:00
291e58ad85 Enable post action 2020-05-09 21:02:32 +07:00
1790ca7f76 Add pnpm install 2020-05-09 20:24:52 +07:00
9a1617cf46 Rename install to install-pnpm 2020-05-09 20:03:45 +07:00
6fe65dc1af Move run-install to its own module 2020-05-09 20:01:25 +07:00
91d3d73121 Correct validation error message 2020-05-09 19:52:48 +07:00
7a5d08caa7 Update run.sh 2020-05-09 19:46:36 +07:00
e373fffa0a Use ajv to validate schema 2020-05-09 19:45:31 +07:00
bb24f595c2 Add schema generator 2020-05-09 19:24:07 +07:00
d44b8c5e53 Add run_install input 2020-05-09 19:13:46 +07:00
4b13327683 Re-add dist/index.js 2020-05-09 18:27:15 +07:00
49ba4cbc60 Delete dist/index.js 2020-05-09 18:26:16 +07:00
9649109f2e Fix .gitattributes 2020-05-09 08:13:09 +07:00
087311f996 refactor: Remove then 2020-05-08 21:55:03 +07:00
9979c3d928 Use node-fetch 2020-05-08 21:34:25 +07:00
738fb9213f Fix README.md 2020-05-08 21:23:23 +07:00
8925cc44da v1.1.0 2020-05-08 21:18:35 +07:00
7574328996 Forgot to update dist/index.js 2020-05-08 21:17:30 +07:00
26 changed files with 1204 additions and 847 deletions

2
.gitattributes vendored
View File

@ -1,2 +1,2 @@
* text=auto
dist/index.js -text
/dist/index.js binary

10
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- dependabot
- github-actions

View File

@ -3,6 +3,7 @@ name: Test Action
on:
- push
- pull_request
- workflow_dispatch
jobs:
test_default_inputs:
@ -57,11 +58,65 @@ jobs:
with:
version: 4.11.1
dest: ~/test/pnpm
bin_dest: ~/test/pnpm/.bin
registry: http://registry.yarnpkg.com/
- name: 'Test: which'
run: which pnpm && which pnpx
- name: 'Test: install'
run: pnpm install
test_run_install:
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
pnpm:
- 4.11.1
os:
- ubuntu-latest
- macos-latest
- windows-latest
run_install:
- name: 'null'
value: 'null'
- name: 'empty object'
value: '{}'
- name: 'recursive'
value: |
recursive: true
- name: 'global'
value: |
args:
- --global
- --global-dir=./pnpm-global
- npm
- yarn
- pnpm
- name: 'array'
value: |
- {}
- recursive: true
- args:
- --global
- --global-dir=./pnpm-global
- npm
- yarn
- pnpm
steps:
- uses: actions/checkout@v2
- name: Run the action
uses: ./
with:
version: 4.11.1
run_install: ${{ matrix.run_install.value }}
- name: 'Test: which'
run: which pnpm; which pnpx
- name: 'Test: install'
run: pnpm install

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ temp
*.temp
tmp.*
temp.*
.pnpm-store

104
README.md
View File

@ -1,24 +1,38 @@
# Setup PNPM
# Setup pnpm
Install PNPM package manager.
Install pnpm package manager.
## Inputs
### `version`
**Required** Version of PNPM to install.
**Required** Version of pnpm to install. 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.
### `bin_dest`
### `run_install`
**Optional** Where to store executables (`pnpm` and `pnpx` commands).
**Optional** (_default:_ `null`) If specified, run `pnpm install`.
### `registry`
If `run_install` is either `null` or `false`, pnpm will not install any npm package.
**Optional** Registry to download PNPM from.
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.
#### `run_install.recursive`
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to use `pnpm recursive install`.
#### `run_install.cwd`
**Optional** (_type:_ `string`) Working directory when run `pnpm [recursive] install`.
#### `run_install.args`
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
## Outputs
@ -28,29 +42,81 @@ Expanded path of inputs#dest.
### `bin_dest`
Expanded path of inputs@bin_dest.
Location of `pnpm` and `pnpx` command.
## Usage example
### Just install pnpm
```yaml
on:
- push
- pull_request
jobs:
runs-on: ubuntu-latest
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v1
with:
version: 4.11.1
- name: Install dependencies
run: pnpm install
steps:
- uses: pnpm/action-setup@v2.1.0
with:
version: 6.0.2
```
### Install pnpm and a few npm packages
```yaml
on:
- push
- pull_request
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- 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
```yaml
on:
- push
- pull_request
jobs:
cache-and-install:
runs-on: ubuntu-latest
steps:
build:
- uses: actions/checkout@v2
- 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@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.
## Notes
This action does not setup Node.js for you, use [actions/setup-node](https://github.com/actions/setup-node) yourself.

View File

@ -11,14 +11,11 @@ inputs:
description: Where to store PNPM files
required: false
default: ~/setup-pnpm
bin_dest:
description: Where to store executables (pnpm and pnpx commands)
run_install:
description: If specified, run `pnpm install`
required: false
default: ~/setup-pnpm/.bin
registry:
description: Registry to download PNPM from
required: false
default: https://registry.npmjs.com
default: 'null'
runs:
using: node12
main: dist/index.js
post: dist/index.js

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,20 +1,27 @@
{
"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": "tsc && pnpm run build:ncc",
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc",
"start": "pnpm run build && sh ./run.sh"
},
"dependencies": {
"download": "^8.0.0",
"expand-tilde": "^2.0.2",
"@actions/core": "^1.2.4",
"@types/download": "^6.2.4",
"@actions/core": "^1.6.0",
"@types/expand-tilde": "^2.0.0",
"@types/node": "^13.13.5"
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.5",
"@types/node": "^14.18.10",
"@types/node-fetch": "^2.5.12",
"ajv": "^6.12.6",
"expand-tilde": "^2.0.2",
"fs-extra": "^9.1.0",
"js-yaml": "^4.1.0",
"node-fetch": "^2.6.7"
},
"devDependencies": {
"typescript": "^3.8.3",
"@zeit/ncc": "^0.22.1"
"@ts-schema-autogen/cli": "^0.1.2",
"@vercel/ncc": "^0.27.0",
"typescript": "^4.5.5"
}
}

1546
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,10 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"pinVersions": false,
"extends": [
"config:base"
],
"ignoreDeps": [
"ajv"
]
}

3
run.sh
View File

@ -3,6 +3,5 @@
export HOME="$(pwd)"
export INPUT_VERSION=4.11.1
export INPUT_DEST='~/pnpm.temp'
export INPUT_BIN_DEST='~/pnpm.temp/.bin'
export INPUT_REGISTRY=https://registry.npmjs.com
export INPUT_RUN_INSTALL=null
exec node dist/index.js

View File

@ -1,14 +1,19 @@
import { setFailed } from '@actions/core'
import { setFailed, saveState, getState } from '@actions/core'
import getInputs from './inputs'
import setOutputs from './outputs'
import install from './install'
import installPnpm from './install-pnpm'
import pnpmInstall from './pnpm-install'
import pruneStore from './pnpm-store-prune'
async function main() {
const inputs = getInputs()
await install(inputs).then(() => {
console.log('Installation Completed!')
setOutputs(inputs)
})
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)
}
main().catch(error => {

View File

@ -1,11 +1,11 @@
import { getInput, InputOptions } from '@actions/core'
import expandTilde from 'expand-tilde'
import { RunInstall, parseRunInstall } from './run-install'
export interface Inputs {
readonly version: string
readonly dest: string
readonly binDest: string
readonly registry: string
readonly runInstall: RunInstall[]
}
const options: InputOptions = {
@ -17,8 +17,7 @@ const parseInputPath = (name: string) => expandTilde(getInput(name, options))
export const getInputs = (): Inputs => ({
version: getInput('version', options),
dest: parseInputPath('dest'),
binDest: parseInputPath('bin_dest'),
registry: getInput('registry', options),
runInstall: parseRunInstall('run_install'),
})
export default getInputs

View File

@ -0,0 +1,21 @@
{
"$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"
}
}

View File

@ -0,0 +1,39 @@
{
"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#"
}

39
src/inputs/run-install.ts Normal file
View File

@ -0,0 +1,39 @@
import process from 'process'
import { load } from 'js-yaml'
import Ajv from 'ajv'
import { getInput, error, InputOptions } from '@actions/core'
import runInstallSchema from './run-install-input.schema.json'
export interface RunInstall {
readonly recursive?: boolean
readonly cwd?: string
readonly args?: readonly string[]
}
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
const options: InputOptions = {
required: true,
}
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}`)
}
return process.exit(1)
}
if (!result) return []
if (result === true) return [{ recursive: true }]
if (Array.isArray(result)) return result
return [result]
}

View File

@ -1,13 +1,15 @@
import { setFailed } from '@actions/core'
import { setFailed, startGroup, endGroup } from '@actions/core'
import { Inputs } from '../inputs'
import runSelfInstaller from './run'
export { runSelfInstaller }
export async function install(inputs: Inputs) {
startGroup('Running self-installer...')
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}`)
}
}

38
src/install-pnpm/run.ts Normal file
View File

@ -0,0 +1,38 @@
import { addPath, exportVariable } from '@actions/core'
import { spawn } from 'child_process'
import { execPath } from 'process'
import path 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 = path.join(dest, 'package.json')
await remove(dest)
await ensureFile(pkgJson)
await writeFile(pkgJson, JSON.stringify({ private: true }))
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
})
const response = await fetch('https://pnpm.io/pnpm.js')
response.body.pipe(cp.stdin)
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
}
export default runSelfInstaller

View File

@ -1,25 +0,0 @@
import { spawn } from 'child_process'
import { execPath } from 'process'
import { downloadSelfInstaller } from '../self-installer'
import { Inputs } from '../inputs'
export function runSelfInstaller(inputs: Inputs): Promise<number> {
const cp = spawn(execPath, {
env: {
PNPM_VERSION: inputs.version,
PNPM_DEST: inputs.dest,
PNPM_BIN_DEST: inputs.binDest,
PNPM_REGISTRY: inputs.registry,
},
stdio: ['pipe', 'inherit', 'inherit'],
})
downloadSelfInstaller().pipe(cp.stdin)
return new Promise((resolve, reject) => {
cp.on('error', reject)
cp.on('close', resolve)
})
}
export default runSelfInstaller

View File

@ -1,10 +1,12 @@
import { setOutput, addPath } from '@actions/core'
import { Inputs } from '../inputs'
import { getBinDest } from '../utils'
export function setOutputs(inputs: Inputs) {
addPath(inputs.binDest)
const binDest = getBinDest(inputs)
addPath(binDest)
setOutput('dest', inputs.dest)
setOutput('bin_dest', inputs.binDest)
setOutput('bin_dest', binDest)
}
export default setOutputs

38
src/pnpm-install/index.ts Normal file
View File

@ -0,0 +1,38 @@
import { spawnSync } from 'child_process'
import { setFailed, startGroup, endGroup } from '@actions/core'
import { Inputs } from '../inputs'
import { patchPnpmEnv } from '../utils'
export function runPnpmInstall(inputs: Inputs) {
const env = patchPnpmEnv(inputs)
for (const options of inputs.runInstall) {
const args = ['install']
if (options.recursive) args.unshift('recursive')
if (options.args) args.push(...options.args)
const cmdStr = ['pnpm', ...args].join(' ')
startGroup(`Running ${cmdStr}...`)
const { error, status } = spawnSync('pnpm', args, {
stdio: 'inherit',
cwd: options.cwd,
shell: true,
env,
})
endGroup()
if (error) {
setFailed(error)
continue
}
if (status) {
setFailed(`Command ${cmdStr} (cwd: ${options.cwd}) exits with status ${status}`)
continue
}
}
}
export default runPnpmInstall

View File

@ -0,0 +1,31 @@
import { spawnSync } from 'child_process'
import { warning, startGroup, endGroup } from '@actions/core'
import { Inputs } from '../inputs'
import { patchPnpmEnv } from '../utils'
export function pruneStore(inputs: Inputs) {
if (inputs.runInstall.length === 0) {
console.log('Pruning is unnecessary.')
return
}
startGroup('Running pnpm store prune...')
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
stdio: 'inherit',
shell: true,
env: patchPnpmEnv(inputs)
})
endGroup()
if (error) {
warning(error)
return
}
if (status) {
warning(`command pnpm store prune exits with code ${status}`)
return
}
}
export default pruneStore

View File

@ -1,4 +0,0 @@
import download from 'download'
import url from './url'
export const downloadSelfInstaller = () => download(url)
export default downloadSelfInstaller

View File

@ -1,2 +0,0 @@
export * from './url'
export * from './download'

View File

@ -1,3 +0,0 @@
export const ref = '301414cec74a2b6b63c95b42f2ad1790ccb980ed'
export const url = `https://raw.githubusercontent.com/pnpm/self-installer/${ref}/install.js`
export default url

10
src/utils/index.ts Normal file
View File

@ -0,0 +1,10 @@
import process from 'process'
import path from 'path'
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
})