1
0
mirror of https://github.com/pnpm/action-setup.git synced 2026-06-20 16:13:44 +08:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Ben McCann
bd24b65d67 Merge d5bd7e8c9a into 1e1c8eafbd 2025-12-19 17:11:37 +09:00
Ben McCann
d5bd7e8c9a Update src/install-pnpm/run.ts 2024-06-12 08:37:26 -07:00
Ben McCann
44def7846a feat: detect pnpm version from lockfile 2024-05-28 12:08:13 -07:00
7 changed files with 43 additions and 46 deletions

View File

@@ -1,28 +0,0 @@
name: pr-check
on: [ pull_request ]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Setup pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
run_install: true
version: 9
- name: Update dist/index.js
run: pnpm run build
- name: Check for uncommitted changes in dist
run: git diff --exit-code dist/index.js

View File

@@ -37,6 +37,6 @@ outputs:
bin_dest:
description: Location of `pnpm` and `pnpx` command
runs:
using: node24
using: node20
main: dist/index.js
post: dist/index.js

8
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -12,7 +12,7 @@
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.5.0",
"@types/expand-tilde": "^2.0.2",
"@types/node": "^22.0.0",
"@types/node": "^20.11.5",
"expand-tilde": "^2.0.2",
"yaml": "^2.3.4",
"zod": "^3.22.4"

18
pnpm-lock.yaml generated
View File

@@ -24,8 +24,8 @@ importers:
specifier: ^2.0.2
version: 2.0.2
'@types/node':
specifier: ^22.0.0
version: 22.19.11
specifier: ^20.11.5
version: 20.17.17
expand-tilde:
specifier: ^2.0.2
version: 2.0.2
@@ -137,8 +137,8 @@ packages:
'@types/expand-tilde@2.0.2':
resolution: {integrity: sha512-wlsMYiapmIR4Eq/Z0qysN8xaDMjSkO6AIDNFx9oxgWGeKVA1jU+NzwPRZErBNP5z6/dx6QNkNpKglBGPO9OkTA==}
'@types/node@22.19.11':
resolution: {integrity: sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w==}
'@types/node@20.17.17':
resolution: {integrity: sha512-/WndGO4kIfMicEQLTi/mDANUu/iVUhT7KboZPdEqqHQ4aTS+3qT3U5gIqWDFV+XouorjfgGqvKILJeHhuQgFYg==}
'@typespec/ts-http-runtime@0.3.0':
resolution: {integrity: sha512-sOx1PKSuFwnIl7z4RN0Ls7N9AQawmR9r66eI5rFCzLDIs8HTIYrIpH9QjYWoX0lkgGrkLxXhi4QnK7MizPRrIg==}
@@ -335,8 +335,8 @@ packages:
engines: {node: '>=14.17'}
hasBin: true
undici-types@6.21.0:
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
undici-types@6.19.8:
resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==}
undici@5.29.0:
resolution: {integrity: sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==}
@@ -539,9 +539,9 @@ snapshots:
'@types/expand-tilde@2.0.2': {}
'@types/node@22.19.11':
'@types/node@20.17.17':
dependencies:
undici-types: 6.21.0
undici-types: 6.19.8
'@typespec/ts-http-runtime@0.3.0':
dependencies:
@@ -717,7 +717,7 @@ snapshots:
typescript@5.7.3: {}
undici-types@6.21.0: {}
undici-types@6.19.8: {}
undici@5.29.0:
dependencies:

View File

@@ -5,6 +5,7 @@ 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 { parse as parseYaml } from 'yaml'
@@ -44,7 +45,6 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
if (exitCode === 0) {
const pnpmHome = path.join(dest, 'node_modules/.bin')
addPath(pnpmHome)
addPath(path.join(pnpmHome, 'bin'))
exportVariable('PNPM_HOME', pnpmHome)
}
return exitCode
@@ -96,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@')) {
@@ -113,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

View File

@@ -6,5 +6,5 @@ export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'no
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
...process.env,
PATH: path.join(getBinDest(inputs), 'bin') + path.delimiter + getBinDest(inputs) + path.delimiter + process.env.PATH,
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH,
})