mirror of
https://github.com/pnpm/action-setup.git
synced 2026-03-07 08:21:45 +08:00
Compare commits
6 Commits
05e5eb2762
...
bd24b65d67
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd24b65d67 | ||
|
|
1e1c8eafbd | ||
|
|
b9e1dbc72f | ||
|
|
61bc82c7df | ||
|
|
d5bd7e8c9a | ||
|
|
44def7846a |
12
.github/workflows/test.yaml
vendored
12
.github/workflows/test.yaml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
- windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
@ -51,7 +51,7 @@ jobs:
|
||||
- windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
@ -74,8 +74,8 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os:
|
||||
# macos is excluded from this test because node 12 is no longer available on this platform
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
|
||||
standalone:
|
||||
@ -83,7 +83,7 @@ jobs:
|
||||
- false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
@ -92,7 +92,7 @@ jobs:
|
||||
standalone: ${{ matrix.standalone }}
|
||||
|
||||
- name: install Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
# pnpm@7.0.0 is not compatible with Node.js 12
|
||||
node-version: 12.22.12
|
||||
@ -160,7 +160,7 @@ jobs:
|
||||
- yarn
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { getInput, error } from '@actions/core'
|
||||
import * as yaml from 'yaml'
|
||||
import { parse as parseYaml } from 'yaml'
|
||||
import { z, ZodError } from 'zod'
|
||||
|
||||
const RunInstallSchema = z.object({
|
||||
@ -20,7 +20,7 @@ export type RunInstall = z.infer<typeof RunInstallSchema>
|
||||
|
||||
export function parseRunInstall(inputName: string): RunInstall[] {
|
||||
const input = getInput(inputName, { required: true })
|
||||
const parsedInput: unknown = yaml.parse(input)
|
||||
const parsedInput: unknown = parseYaml(input)
|
||||
|
||||
try {
|
||||
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
||||
|
||||
@ -5,8 +5,9 @@ import { readFileSync } from 'fs'
|
||||
import path from 'path'
|
||||
import { execPath } from 'process'
|
||||
import util from 'util'
|
||||
import * as yaml from 'yaml'
|
||||
import { Inputs } from '../inputs'
|
||||
import YAML from 'yaml'
|
||||
import { parse as parseYaml } from 'yaml'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
const { version, dest, packageJsonFile, standalone } = inputs
|
||||
@ -63,7 +64,7 @@ async function readTarget(opts: {
|
||||
try {
|
||||
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
|
||||
({ packageManager } = packageJsonFile.endsWith(".yaml")
|
||||
? YAML.parse(content, { merge: true })
|
||||
? parseYaml(content, { merge: true })
|
||||
: JSON.parse(content)
|
||||
)
|
||||
} catch (error: unknown) {
|
||||
@ -95,10 +96,18 @@ Otherwise, please specify the pnpm version in the action configuration.`)
|
||||
}
|
||||
|
||||
if (typeof packageManager !== 'string') {
|
||||
throw new Error(`No pnpm version is specified.
|
||||
if (GITHUB_WORKSPACE) {
|
||||
try {
|
||||
const { lockfileVersion } = yaml.parse(readFileSync(path.join(GITHUB_WORKSPACE, 'pnpm-lock.yaml'), 'utf8'))
|
||||
const version = getPnpmVersionFromLockfile(lockfileVersion);
|
||||
return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||
} catch (error: unknown) {
|
||||
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"`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!packageManager.startsWith('pnpm@')) {
|
||||
@ -112,4 +121,21 @@ Please specify it by one of the following ways:
|
||||
return packageManager
|
||||
}
|
||||
|
||||
function getPnpmVersionFromLockfile(
|
||||
lockfileVersion: string | undefined
|
||||
): string | undefined {
|
||||
switch (true) {
|
||||
case lockfileVersion === '5.3':
|
||||
return 'latest-6';
|
||||
case lockfileVersion === '5.4':
|
||||
return 'latest-7';
|
||||
case lockfileVersion === '6.0' || lockfileVersion === '6.1':
|
||||
return 'latest-8';
|
||||
case lockfileVersion === '7.0' || lockfileVersion === '9.0':
|
||||
return 'latest-9';
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export default runSelfInstaller
|
||||
|
||||
Loading…
Reference in New Issue
Block a user