fix: packageManager reader (#35)
Some checks failed
Test Action / Test with default inputs (ubuntu-latest, 4.11.1) (push) Successful in 22s
Test Action / Test with explicit inputs (ubuntu-latest, 4.11.1) (push) Successful in 21s
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (ubuntu-latest, 4.11.1, map[name:empty object value:{}]) (push) Successful in 26s
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (ubuntu-latest, 4.11.1, map[name:array value:- {} - recursive: true - args: - --global - --global-dir=./pnpm-global - npm - yarn - pnpm ]) (push) Successful in 28s
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (ubuntu-latest, 4.11.1, map[name:global value:args: - --global - --global-dir=./pnpm-global - npm - yarn - pnpm ]) (push) Successful in 23s
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (ubuntu-latest, 4.11.1, map[name:null value:null]) (push) Successful in 23s
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (ubuntu-latest, 4.11.1, map[name:recursive value:recursive: true ]) (push) Successful in 19s
Test Action / Test with default inputs (macos-latest, 4.11.1) (push) Has been cancelled
Test Action / Test with default inputs (windows-latest, 4.11.1) (push) Has been cancelled
Test Action / Test with explicit inputs (macos-latest, 4.11.1) (push) Has been cancelled
Test Action / Test with explicit inputs (windows-latest, 4.11.1) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (macos-latest, 4.11.1, map[name:array value:- {} - recursive: true - args: - --global - --global-dir=./pnpm-global - npm - yarn - pnpm ]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (macos-latest, 4.11.1, map[name:empty object value:{}]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (macos-latest, 4.11.1, map[name:global value:args: - --global - --global-dir=./pnpm-global - npm - yarn - pnpm ]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (macos-latest, 4.11.1, map[name:null value:null]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (macos-latest, 4.11.1, map[name:recursive value:recursive: true ]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (windows-latest, 4.11.1, map[name:array value:- {} - recursive: true - args: - --global - --global-dir=./pnpm-global - npm - yarn - pnpm ]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (windows-latest, 4.11.1, map[name:empty object value:{}]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (windows-latest, 4.11.1, map[name:global value:args: - --global - --global-dir=./pnpm-global - npm - yarn - pnpm ]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (windows-latest, 4.11.1, map[name:null value:null]) (push) Has been cancelled
Test Action / Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }}) (windows-latest, 4.11.1, map[name:recursive value:recursive: true ]) (push) Has been cancelled

* fix: packageManager reader

* chore: resolve review

* chore: run build
This commit is contained in:
Jack Works 2022-02-25 12:43:26 +08:00 committed by GitHub
parent 11ba3424e0
commit 35ab4267a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

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

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -8,13 +8,15 @@ 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 pkgJson = path.join(dest, 'package.json')
const target = await readTarget(pkgJson, version)
// prepare self install
await remove(dest) await remove(dest)
const pkgJson = path.join(dest, 'package.json')
await ensureFile(pkgJson) await ensureFile(pkgJson)
await writeFile(pkgJson, JSON.stringify({ private: true })) await writeFile(pkgJson, JSON.stringify({ private: true }))
// prepare target pnpm
const target = await readTarget(version)
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], { const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
cwd: dest, cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'], stdio: ['pipe', 'inherit', 'inherit'],
@ -36,10 +38,18 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
return exitCode return exitCode
} }
async function readTarget(packageJsonPath: string, version?: string | undefined) { async function readTarget(version?: string | undefined) {
if (version) return `pnpm@${version}` if (version) return `pnpm@${version}`
const { packageManager } = JSON.parse(await readFile(packageJsonPath, 'utf8')) 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') { 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: