fix(ci): use Corepack for pnpm setup when packageManager field is set

pnpm/action-setup@v4 errors with "Multiple versions of pnpm specified"
even when no explicit version input is provided, if the repo has a
packageManager field in package.json.

Switch to Corepack for repos that pin their pnpm version via the
packageManager field. Corepack reads the version from package.json
directly and installs it without conflicting with pnpm/action-setup.

Repos without a packageManager field continue using pnpm/action-setup@v4
with version: latest (unchanged behavior).

Unblocks headlamp-polaris-plugin PR #103 (ci/pin-pnpm-version).

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Hugh Hackman
2026-03-22 05:41:30 +00:00
parent 547c4ad5aa
commit a5c19aae8d
+6 -6
View File
@@ -24,8 +24,8 @@ jobs:
if [ -f "pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> $GITHUB_OUTPUT
# Check for packageManager field in package.json (Corepack pinning).
# pnpm/action-setup@v4 errors if both `version` input and `packageManager`
# are set, so we detect here and use two conditional steps below.
# pnpm/action-setup@v4 errors when `packageManager` is set (even without
# a `version` input), so we use Corepack directly for those repos.
PM=$(node -e "try{const p=require('./package.json');const v=p.packageManager||'';console.log(v.startsWith('pnpm@')?'true':'false')}catch(e){console.log('false')}" 2>/dev/null || echo "false")
echo "has_package_manager=$PM" >> $GITHUB_OUTPUT
else
@@ -33,11 +33,11 @@ jobs:
echo "has_package_manager=false" >> $GITHUB_OUTPUT
fi
- name: Setup pnpm (version from packageManager field)
- name: Setup pnpm (via Corepack, reads version from packageManager field)
if: steps.pkg-manager.outputs.manager == 'pnpm' && steps.pkg-manager.outputs.has_package_manager == 'true'
uses: pnpm/action-setup@v4
with:
run_install: false
run: |
corepack enable pnpm
corepack install
- name: Setup pnpm (version latest)
if: steps.pkg-manager.outputs.manager == 'pnpm' && steps.pkg-manager.outputs.has_package_manager == 'false'