Compare commits
No commits in common. "master" and "v3" have entirely different histories.
57
README.md
57
README.md
@ -1,7 +1,3 @@
|
|||||||
> ## :warning: Upgrade from v2!
|
|
||||||
>
|
|
||||||
> The v2 version of this action [has stopped working](https://github.com/pnpm/action-setup/issues/135) with newer Node.js versions. Please, upgrade to the latest version to fix any issues.
|
|
||||||
|
|
||||||
# Setup pnpm
|
# Setup pnpm
|
||||||
|
|
||||||
Install pnpm package manager.
|
Install pnpm package manager.
|
||||||
@ -64,9 +60,7 @@ Location of `pnpm` and `pnpx` command.
|
|||||||
|
|
||||||
## Usage example
|
## Usage example
|
||||||
|
|
||||||
### Install only pnpm without `packageManager`
|
### Just install pnpm
|
||||||
|
|
||||||
This works when the repo either doesn't have a `package.json` or has a `package.json` but it doesn't specify `packageManager`.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
@ -78,28 +72,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 8
|
version: 8
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install only pnpm with `packageManager`
|
|
||||||
|
|
||||||
Omit `version` input to use the version in the [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
on:
|
|
||||||
- push
|
|
||||||
- pull_request
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
install:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: pnpm/action-setup@v4
|
|
||||||
```
|
|
||||||
|
|
||||||
### Install pnpm and a few npm packages
|
### Install pnpm and a few npm packages
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@ -112,9 +89,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 8
|
version: 8
|
||||||
run_install: |
|
run_install: |
|
||||||
@ -136,19 +113,31 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- name: Install Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
|
||||||
|
- uses: pnpm/action-setup@v3
|
||||||
name: Install pnpm
|
name: Install pnpm
|
||||||
with:
|
with:
|
||||||
version: 8
|
version: 8
|
||||||
run_install: false
|
run_install: false
|
||||||
|
|
||||||
- name: Install Node.js
|
- name: Get pnpm store directory
|
||||||
uses: actions/setup-node@v4
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
name: Setup pnpm cache
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
path: ${{ env.STORE_PATH }}
|
||||||
cache: 'pnpm'
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pnpm-store-
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
@ -162,4 +151,4 @@ This action does not setup Node.js for you, use [actions/setup-node](https://git
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT](https://github.com/pnpm/action-setup/blob/master/LICENSE.md) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)
|
[MIT](https://git.io/JfclH) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)
|
||||||
|
@ -23,11 +23,6 @@ inputs:
|
|||||||
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed, enabling using pnpm without Node.js.
|
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
|
required: false
|
||||||
default: 'false'
|
default: 'false'
|
||||||
outputs:
|
|
||||||
dest:
|
|
||||||
description: Expanded path of inputs#dest
|
|
||||||
bin_dest:
|
|
||||||
description: Location of `pnpm` and `pnpx` command
|
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node20
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
|
BIN
dist/index.js
vendored
BIN
dist/index.js
vendored
Binary file not shown.
@ -9,9 +9,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@types/expand-tilde": "^2.0.2",
|
"@types/expand-tilde": "^2.0.2",
|
||||||
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/node": "^20.11.5",
|
"@types/node": "^20.11.5",
|
||||||
"@types/node-fetch": "^2.6.11",
|
"@types/node-fetch": "^2.6.11",
|
||||||
"expand-tilde": "^2.0.2",
|
"expand-tilde": "^2.0.2",
|
||||||
|
"fs-extra": "^11.2.0",
|
||||||
"yaml": "^2.3.4",
|
"yaml": "^2.3.4",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.22.4"
|
||||||
},
|
},
|
||||||
|
@ -11,6 +11,9 @@ dependencies:
|
|||||||
'@types/expand-tilde':
|
'@types/expand-tilde':
|
||||||
specifier: ^2.0.2
|
specifier: ^2.0.2
|
||||||
version: 2.0.2
|
version: 2.0.2
|
||||||
|
'@types/fs-extra':
|
||||||
|
specifier: ^11.0.4
|
||||||
|
version: 11.0.4
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^20.11.5
|
specifier: ^20.11.5
|
||||||
version: 20.11.5
|
version: 20.11.5
|
||||||
@ -20,6 +23,9 @@ dependencies:
|
|||||||
expand-tilde:
|
expand-tilde:
|
||||||
specifier: ^2.0.2
|
specifier: ^2.0.2
|
||||||
version: 2.0.2
|
version: 2.0.2
|
||||||
|
fs-extra:
|
||||||
|
specifier: ^11.2.0
|
||||||
|
version: 11.2.0
|
||||||
yaml:
|
yaml:
|
||||||
specifier: ^2.3.4
|
specifier: ^2.3.4
|
||||||
version: 2.3.4
|
version: 2.3.4
|
||||||
@ -51,7 +57,7 @@ packages:
|
|||||||
resolution: {integrity: sha512-q+epW0trjVUUHboliPb4UF9g2msf+w61b32tAkFEwL/IwP0DQWgbCMM0Hbe3e3WXSKz5VcUXbzJQgy8Hkra/Lg==}
|
resolution: {integrity: sha512-q+epW0trjVUUHboliPb4UF9g2msf+w61b32tAkFEwL/IwP0DQWgbCMM0Hbe3e3WXSKz5VcUXbzJQgy8Hkra/Lg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
tunnel: 0.0.6
|
tunnel: 0.0.6
|
||||||
undici: 5.28.3
|
undici: 5.28.2
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@fastify/busboy@2.1.0:
|
/@fastify/busboy@2.1.0:
|
||||||
@ -63,6 +69,19 @@ packages:
|
|||||||
resolution: {integrity: sha512-wlsMYiapmIR4Eq/Z0qysN8xaDMjSkO6AIDNFx9oxgWGeKVA1jU+NzwPRZErBNP5z6/dx6QNkNpKglBGPO9OkTA==}
|
resolution: {integrity: sha512-wlsMYiapmIR4Eq/Z0qysN8xaDMjSkO6AIDNFx9oxgWGeKVA1jU+NzwPRZErBNP5z6/dx6QNkNpKglBGPO9OkTA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/@types/fs-extra@11.0.4:
|
||||||
|
resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==}
|
||||||
|
dependencies:
|
||||||
|
'@types/jsonfile': 6.1.4
|
||||||
|
'@types/node': 20.11.5
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@types/jsonfile@6.1.4:
|
||||||
|
resolution: {integrity: sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==}
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 20.11.5
|
||||||
|
dev: false
|
||||||
|
|
||||||
/@types/node-fetch@2.6.11:
|
/@types/node-fetch@2.6.11:
|
||||||
resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==}
|
resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -113,6 +132,19 @@ packages:
|
|||||||
mime-types: 2.1.35
|
mime-types: 2.1.35
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/fs-extra@11.2.0:
|
||||||
|
resolution: {integrity: sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==}
|
||||||
|
engines: {node: '>=14.14'}
|
||||||
|
dependencies:
|
||||||
|
graceful-fs: 4.2.11
|
||||||
|
jsonfile: 6.1.0
|
||||||
|
universalify: 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/graceful-fs@4.2.11:
|
||||||
|
resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/homedir-polyfill@1.0.3:
|
/homedir-polyfill@1.0.3:
|
||||||
resolution: {integrity: sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==}
|
resolution: {integrity: sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
@ -120,6 +152,14 @@ packages:
|
|||||||
parse-passwd: 1.0.0
|
parse-passwd: 1.0.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/jsonfile@6.1.0:
|
||||||
|
resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==}
|
||||||
|
dependencies:
|
||||||
|
universalify: 2.0.1
|
||||||
|
optionalDependencies:
|
||||||
|
graceful-fs: 4.2.11
|
||||||
|
dev: false
|
||||||
|
|
||||||
/mime-db@1.52.0:
|
/mime-db@1.52.0:
|
||||||
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
|
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
|
||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
@ -158,13 +198,18 @@ packages:
|
|||||||
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/undici@5.28.3:
|
/undici@5.28.2:
|
||||||
resolution: {integrity: sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==}
|
resolution: {integrity: sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==}
|
||||||
engines: {node: '>=14.0'}
|
engines: {node: '>=14.0'}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@fastify/busboy': 2.1.0
|
'@fastify/busboy': 2.1.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/universalify@2.0.1:
|
||||||
|
resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==}
|
||||||
|
engines: {node: '>= 10.0.0'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/uuid@8.3.2:
|
/uuid@8.3.2:
|
||||||
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
|
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
@ -1,21 +1,17 @@
|
|||||||
import { addPath, exportVariable } from '@actions/core'
|
import { addPath, exportVariable } from '@actions/core'
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
import { rm, writeFile, mkdir } from 'fs/promises'
|
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
|
||||||
import { readFileSync } from 'fs'
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { execPath } from 'process'
|
import { execPath } from 'process'
|
||||||
import util from 'util'
|
|
||||||
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, packageJsonFile, standalone } = inputs
|
const { version, dest, packageJsonFile, standalone } = inputs
|
||||||
|
|
||||||
// prepare self install
|
// prepare self install
|
||||||
await rm(dest, { recursive: true, force: true })
|
await remove(dest)
|
||||||
// create dest directory after removal
|
|
||||||
await mkdir(dest, { recursive: true })
|
|
||||||
const pkgJson = path.join(dest, 'package.json')
|
const pkgJson = path.join(dest, 'package.json')
|
||||||
// we have ensured the dest directory exists, we can write the file directly
|
await ensureFile(pkgJson)
|
||||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||||
|
|
||||||
// prepare target pnpm
|
// prepare target pnpm
|
||||||
@ -43,40 +39,18 @@ async function readTarget(opts: {
|
|||||||
readonly standalone: boolean
|
readonly standalone: boolean
|
||||||
}) {
|
}) {
|
||||||
const { version, packageJsonFile, standalone } = opts
|
const { version, packageJsonFile, standalone } = opts
|
||||||
|
|
||||||
|
if (version) return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||||
|
|
||||||
const { GITHUB_WORKSPACE } = process.env
|
const { GITHUB_WORKSPACE } = process.env
|
||||||
|
|
||||||
let packageManager
|
|
||||||
|
|
||||||
if (GITHUB_WORKSPACE) {
|
|
||||||
try {
|
|
||||||
({ packageManager } = JSON.parse(readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8')))
|
|
||||||
} catch (error: unknown) {
|
|
||||||
// Swallow error if package.json doesn't exist in root
|
|
||||||
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version) {
|
|
||||||
if (
|
|
||||||
typeof packageManager === 'string' &&
|
|
||||||
packageManager.replace('pnpm@', '') !== version
|
|
||||||
) {
|
|
||||||
throw new Error(`Multiple versions of pnpm specified:
|
|
||||||
- version ${version} in the GitHub Action config with the key "version"
|
|
||||||
- version ${packageManager} in the package.json with the key "packageManager"
|
|
||||||
Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_PM_VERSION`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GITHUB_WORKSPACE) {
|
if (!GITHUB_WORKSPACE) {
|
||||||
throw new Error(`No workspace is found.
|
throw new Error(`No workspace is found.
|
||||||
If you've intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
|
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.
|
please run the actions/checkout before pnpm/action-setup.
|
||||||
Otherwise, please specify the pnpm version in the action configuration.`)
|
Otherwise, please specify the pnpm version in the action configuration.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8'))
|
||||||
if (typeof packageManager !== 'string') {
|
if (typeof packageManager !== 'string') {
|
||||||
throw new Error(`No pnpm version is specified.
|
throw new Error(`No pnpm version is specified.
|
||||||
Please specify it by one of the following ways:
|
Please specify it by one of the following ways:
|
||||||
@ -88,7 +62,7 @@ Please specify it by one of the following ways:
|
|||||||
throw new Error('Invalid packageManager field in package.json')
|
throw new Error('Invalid packageManager field in package.json')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (standalone) {
|
if(standalone){
|
||||||
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user