3 Commits

Author SHA1 Message Date
187ace9a18 test: don't check pnpx 2022-02-10 01:18:35 +02:00
7f8a57faa8 test: update pnpm version 2022-02-10 01:16:10 +02:00
268b4179de Install the self-contained binary version of pnpm
This is a breaking change because the binary version of pnpm
is only available from v6.17.1

close #18
2022-02-10 01:13:09 +02:00
17 changed files with 113 additions and 268187 deletions

View File

@ -5,3 +5,6 @@ updates:
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- dependabot
- github-actions

View File

@ -15,22 +15,22 @@ jobs:
fail-fast: false
matrix:
pnpm:
- 4.11.1
- 6.17.1
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- name: Run the action
uses: ./
with:
version: 4.11.1
version: 6.17.1
- name: 'Test: which'
run: which pnpm; which pnpx
run: which pnpm
- name: 'Test: install'
run: pnpm install
@ -44,23 +44,23 @@ jobs:
fail-fast: false
matrix:
pnpm:
- 4.11.1
- 6.17.1
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- name: Run the action
uses: ./
with:
version: 4.11.1
version: 6.17.1
dest: ~/test/pnpm
- name: 'Test: which'
run: which pnpm && which pnpx
run: which pnpm
- name: 'Test: install'
run: pnpm install
@ -74,7 +74,7 @@ jobs:
fail-fast: false
matrix:
pnpm:
- 4.11.1
- 6.17.1
os:
- ubuntu-latest
- macos-latest
@ -107,16 +107,16 @@ jobs:
- pnpm
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- name: Run the action
uses: ./
with:
version: 4.11.1
version: 6.17.1
run_install: ${{ matrix.run_install.value }}
- name: 'Test: which'
run: which pnpm; which pnpx
run: which pnpm
- name: 'Test: install'
run: pnpm install

1
.gitignore vendored
View File

@ -2,7 +2,6 @@ node_modules
*.log
/dist/*
!/dist/index.js
!/dist/pnpm.js
tmp
temp
*.tmp

View File

@ -6,11 +6,7 @@ Install pnpm package manager.
### `version`
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`.
**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`
@ -102,36 +98,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
build:
- uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- 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.0.1
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- 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.

View File

@ -6,6 +6,7 @@ branding:
inputs:
version:
description: Version of PNPM to install
required: true
dest:
description: Where to store PNPM files
required: false

11
dist/index.js vendored

File diff suppressed because one or more lines are too long

134031
dist/pnpm.js vendored

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
"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 && cp src/install-pnpm/pnpm.js dist/pnpm.js",
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc",
"start": "pnpm run build && sh ./run.sh"
},
"dependencies": {
@ -12,15 +12,16 @@
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.5",
"@types/node": "^14.18.10",
"@types/node-fetch": "^2.6.1",
"@types/node-fetch": "^2.5.12",
"ajv": "^6.12.6",
"expand-tilde": "^2.0.2",
"fs-extra": "^10.0.0",
"js-yaml": "^4.1.0"
"fs-extra": "^9.1.0",
"js-yaml": "^4.1.0",
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@ts-schema-autogen/cli": "^0.1.2",
"@vercel/ncc": "^0.33.3",
"@vercel/ncc": "^0.27.0",
"typescript": "^4.5.5"
}
}

75
pnpm-lock.yaml generated
View File

@ -1,4 +1,4 @@
lockfileVersion: 5.4
lockfileVersion: 5.3
specifiers:
'@actions/core': ^1.6.0
@ -7,12 +7,13 @@ specifiers:
'@types/fs-extra': ^9.0.13
'@types/js-yaml': ^4.0.5
'@types/node': ^14.18.10
'@types/node-fetch': ^2.6.1
'@vercel/ncc': ^0.33.3
'@types/node-fetch': ^2.5.12
'@vercel/ncc': ^0.27.0
ajv: ^6.12.6
expand-tilde: ^2.0.2
fs-extra: ^10.0.0
fs-extra: ^9.1.0
js-yaml: ^4.1.0
node-fetch: ^2.6.7
typescript: ^4.5.5
dependencies:
@ -21,15 +22,16 @@ dependencies:
'@types/fs-extra': 9.0.13
'@types/js-yaml': 4.0.5
'@types/node': 14.18.10
'@types/node-fetch': 2.6.1
'@types/node-fetch': 2.5.12
ajv: 6.12.6
expand-tilde: 2.0.2
fs-extra: 10.0.0
fs-extra: 9.1.0
js-yaml: 4.1.0
node-fetch: 2.6.7
devDependencies:
'@ts-schema-autogen/cli': 0.1.2
'@vercel/ncc': 0.33.3
'@vercel/ncc': 0.27.0
typescript: 4.5.5
packages:
@ -214,8 +216,8 @@ packages:
resolution: {integrity: sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==}
dev: true
/@types/node-fetch/2.6.1:
resolution: {integrity: sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==}
/@types/node-fetch/2.5.12:
resolution: {integrity: sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==}
dependencies:
'@types/node': 14.18.10
form-data: 3.0.1
@ -238,8 +240,8 @@ packages:
'@types/yargs-parser': 20.2.1
dev: true
/@vercel/ncc/0.33.3:
resolution: {integrity: sha512-JGZ11QV+/ZcfudW2Cz2JVp54/pJNXbsuWRgSh2ZmmZdQBKXqBtIGrwI1Wyx8nlbzAiEFe7FHi4K1zX4//jxTnQ==}
/@vercel/ncc/0.27.0:
resolution: {integrity: sha512-DllIJQapnU2YwewIhh/4dYesmMQw3h2cFtabECc/zSJHqUbNa0eJuEkRa6DXbZvh1YPWBtYQoPV17NlDpBw1Vw==}
hasBin: true
dev: true
@ -289,6 +291,11 @@ packages:
resolution: {integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k=}
dev: false
/at-least-node/1.0.0:
resolution: {integrity: sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==}
engines: {node: '>= 4.0.0'}
dev: false
/balanced-match/1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
dev: true
@ -435,15 +442,6 @@ packages:
mime-types: 2.1.34
dev: false
/fs-extra/10.0.0:
resolution: {integrity: sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==}
engines: {node: '>=12'}
dependencies:
graceful-fs: 4.2.9
jsonfile: 6.1.0
universalify: 2.0.0
dev: false
/fs-extra/8.1.0:
resolution: {integrity: sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==}
engines: {node: '>=6 <7 || >=8'}
@ -453,6 +451,16 @@ packages:
universalify: 0.1.2
dev: true
/fs-extra/9.1.0:
resolution: {integrity: sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==}
engines: {node: '>=10'}
dependencies:
at-least-node: 1.0.0
graceful-fs: 4.2.9
jsonfile: 6.1.0
universalify: 2.0.0
dev: false
/fs.realpath/1.0.0:
resolution: {integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8=}
dev: true
@ -579,6 +587,18 @@ packages:
brace-expansion: 1.1.11
dev: true
/node-fetch/2.6.7:
resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
engines: {node: 4.x || >=6.0.0}
peerDependencies:
encoding: ^0.1.0
peerDependenciesMeta:
encoding:
optional: true
dependencies:
whatwg-url: 5.0.0
dev: false
/once/1.4.0:
resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=}
dependencies:
@ -684,6 +704,10 @@ packages:
ansi-regex: 5.0.1
dev: true
/tr46/0.0.3:
resolution: {integrity: sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=}
dev: false
/tslib/1.14.1:
resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
dev: true
@ -740,6 +764,17 @@ packages:
engines: {node: '>= 4'}
dev: true
/webidl-conversions/3.0.1:
resolution: {integrity: sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=}
dev: false
/whatwg-url/5.0.0:
resolution: {integrity: sha1-lmRU6HZUYuN2RNNib2dCzotwll0=}
dependencies:
tr46: 0.0.3
webidl-conversions: 3.0.1
dev: false
/which-module/2.0.0:
resolution: {integrity: sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=}
dev: true

View File

@ -1,7 +1,7 @@
import { setFailed, saveState, getState } from '@actions/core'
import getInputs from './inputs'
import installPnpm from './install-pnpm'
import setOutputs from './outputs'
import installPnpm from './install-pnpm'
import pnpmInstall from './pnpm-install'
import pruneStore from './pnpm-store-prune'

View File

@ -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'),
version: getInput('version', options),
dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'),
})

View File

@ -1,7 +1,7 @@
import { getInput, error, InputOptions } from '@actions/core'
import Ajv from 'ajv'
import { load } from 'js-yaml'
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 {

File diff suppressed because one or more lines are too long

View File

@ -1,26 +1,28 @@
import { addPath, exportVariable } from '@actions/core'
import { spawn } from 'child_process'
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
import path from 'path'
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
// prepare self install
await remove(dest)
const target = version ? `@pnpm/exe@${version}` : '@pnpm/exe'
const pkgJson = path.join(dest, 'package.json')
await remove(dest)
await ensureFile(pkgJson)
await writeFile(pkgJson, JSON.stringify({ private: true }))
// prepare target pnpm
const target = await readTarget(version)
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
})
const response = await fetch('https://get.pnpm.io/v6.16.js')
response.body.pipe(cp.stdin)
const exitCode = await new Promise<number>((resolve, reject) => {
cp.on('error', reject)
cp.on('close', resolve)
@ -33,29 +35,4 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
return exitCode
}
async function readTarget(version?: string | undefined) {
if (version) return `pnpm@${version}`
const { GITHUB_WORKSPACE } = process.env
if (!GITHUB_WORKSPACE) {
throw new Error(`No workspace is found.
If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
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'))
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

View File

@ -1,5 +1,5 @@
import { setFailed, startGroup, endGroup } from '@actions/core'
import { spawnSync } from 'child_process'
import { setFailed, startGroup, endGroup } from '@actions/core'
import { Inputs } from '../inputs'
import { patchPnpmEnv } from '../utils'

View File

@ -1,5 +1,5 @@
import { warning, startGroup, endGroup } from '@actions/core'
import { spawnSync } from 'child_process'
import { warning, startGroup, endGroup } from '@actions/core'
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()

View File

@ -1,10 +1,10 @@
import path from 'path'
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,
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH
})