Merge d5bd7e8c9a3b4e8f53b0cc30f35038412eb9211e into a7487c7e89a18df4991f7f222e4898a00d66ddda

This commit is contained in:
Ben McCann 2025-02-07 14:50:19 +01:00 committed by GitHub
commit 91010c862d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ 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 util from 'util'
import * as yaml from 'yaml'
import { Inputs } from '../inputs' import { Inputs } from '../inputs'
import YAML from 'yaml' import YAML from 'yaml'
@ -83,10 +84,18 @@ Otherwise, please specify the pnpm version in the action configuration.`)
} }
if (typeof packageManager !== 'string') { 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: Please specify it by one of the following ways:
- in the GitHub Action config with the key "version" - in the GitHub Action config with the key "version"
- in the package.json with the key "packageManager"`) - in the package.json with the key "packageManager"`)
}
}
} }
if (!packageManager.startsWith('pnpm@')) { if (!packageManager.startsWith('pnpm@')) {
@ -100,4 +109,21 @@ Please specify it by one of the following ways:
return packageManager 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 export default runSelfInstaller