111f838a09
corepack is bundled with Node.js and only available on PATH after actions/setup-node runs. The previous workflow ordered the corepack enable/install step before setup-node, causing: corepack: command not found Fix: move setup-node to run first. Because pnpm is not installed when setup-node runs, the built-in `cache: pnpm` cannot call `pnpm store path`. Split pnpm caching into explicit Get/Cache steps using actions/cache@v4 after pnpm is installed via either corepack or pnpm/action-setup. npm caching continues to use setup-node's built-in cache: npm. Fixes polaris PR #103 CI (headlamp-polaris-plugin v1.0.0 release). Co-Authored-By: Paperclip <noreply@paperclip.ing>
123 lines
3.9 KiB
YAML
123 lines
3.9 KiB
YAML
name: Plugin CI
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
node-version:
|
|
description: 'Node.js version to use'
|
|
required: false
|
|
type: string
|
|
default: '22'
|
|
|
|
jobs:
|
|
ci:
|
|
runs-on: runners-privilegedescalation
|
|
timeout-minutes: 10
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Detect package manager
|
|
id: pkg-manager
|
|
run: |
|
|
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 when `packageManager` is set (even without
|
|
# a `version` input), so we use Corepack directly for those repos.
|
|
# Use python3 (pre-installed on Ubuntu ARC runners) instead of node,
|
|
# because node is not on PATH before the Setup Node step runs.
|
|
PM=$(python3 -c "import json,sys; d=json.load(open('package.json')); print('true' if d.get('packageManager','').startswith('pnpm@') else 'false')" 2>/dev/null || echo "false")
|
|
echo "has_package_manager=$PM" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "manager=npm" >> $GITHUB_OUTPUT
|
|
echo "has_package_manager=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ inputs.node-version }}
|
|
# Only enable built-in npm caching here; pnpm caching is handled below
|
|
# after pnpm is installed (corepack is not available before setup-node).
|
|
cache: ${{ steps.pkg-manager.outputs.manager == 'npm' && 'npm' || '' }}
|
|
|
|
- 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'
|
|
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'
|
|
uses: pnpm/action-setup@v4
|
|
with:
|
|
run_install: false
|
|
version: latest
|
|
|
|
- name: Get pnpm store directory
|
|
id: pnpm-store
|
|
if: steps.pkg-manager.outputs.manager == 'pnpm'
|
|
run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Cache pnpm store
|
|
if: steps.pkg-manager.outputs.manager == 'pnpm'
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ steps.pnpm-store.outputs.dir }}
|
|
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
if [ "${{ steps.pkg-manager.outputs.manager }}" = "pnpm" ]; then
|
|
pnpm install --frozen-lockfile
|
|
else
|
|
npm ci
|
|
fi
|
|
|
|
- name: Build plugin
|
|
run: npx @kinvolk/headlamp-plugin build
|
|
|
|
- name: Lint
|
|
run: |
|
|
if [ "${{ steps.pkg-manager.outputs.manager }}" = "pnpm" ]; then
|
|
pnpm run lint
|
|
else
|
|
npm run lint
|
|
fi
|
|
|
|
- name: Type-check
|
|
run: |
|
|
if [ "${{ steps.pkg-manager.outputs.manager }}" = "pnpm" ]; then
|
|
pnpm run tsc
|
|
else
|
|
npm run tsc
|
|
fi
|
|
|
|
- name: Format check
|
|
run: |
|
|
if [ "${{ steps.pkg-manager.outputs.manager }}" = "pnpm" ]; then
|
|
pnpm run format:check
|
|
else
|
|
npm run format:check
|
|
fi
|
|
|
|
- name: Run tests
|
|
run: |
|
|
if [ "${{ steps.pkg-manager.outputs.manager }}" = "pnpm" ]; then
|
|
pnpm test
|
|
else
|
|
npm test
|
|
fi
|
|
|
|
- name: Security audit
|
|
run: |
|
|
if [ "${{ steps.pkg-manager.outputs.manager }}" = "pnpm" ]; then
|
|
pnpm audit --prod
|
|
else
|
|
npm audit --omit=dev
|
|
fi
|