Compare commits
No commits in common. "18ac635edf3d6cd3e88d281bceecc25c4dbc1e73" and "ce859e384f8a1a0be70b423054e9fc15175c02a9" have entirely different histories.
18ac635edf
...
ce859e384f
51
README.md
51
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
|
||||||
@ -114,7 +91,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 8
|
version: 8
|
||||||
run_install: |
|
run_install: |
|
||||||
@ -138,17 +115,29 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- name: Install Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
|
||||||
|
- 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@v4
|
||||||
|
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
|
||||||
|
@ -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.
@ -1,10 +1,8 @@
|
|||||||
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 { rm, writeFile, readFile, mkdir } from 'fs/promises'
|
||||||
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> {
|
||||||
@ -43,40 +41,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:
|
||||||
|
Loading…
Reference in New Issue
Block a user