fix(plugin-ci): use npm audit for both pnpm and npm repos (#92)
The pnpm registry audit endpoint is retired (HTTP 410). Fix: for pnpm repos, run 'npm install --package-lock-only --ignore-scripts --quiet --no-audit' to generate a package-lock.json from pnpm-lock.yaml metadata, then run npm audit. For npm repos, continue using npm audit directly. Use --audit-level=moderate to fail only on high/critical vulnerabilities, not moderate ones, reducing noise from transitive dependencies. Co-authored-by: Hugh Hackman <hugh@privilegedescalation> Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
committed by
GitHub
parent
521506cf1d
commit
922b462195
@@ -25,7 +25,6 @@ jobs:
|
|||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# yaml not available — skip (shouldn't happen on ubuntu runners)
|
|
||||||
print("::warning::PyYAML not available, skipping artifacthub-pkg.yml validation")
|
print("::warning::PyYAML not available, skipping artifacthub-pkg.yml validation")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
@@ -41,17 +40,14 @@ jobs:
|
|||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
# Required top-level fields
|
|
||||||
for field in ["version", "name", "description", "homeURL"]:
|
for field in ["version", "name", "description", "homeURL"]:
|
||||||
if not pkg.get(field):
|
if not pkg.get(field):
|
||||||
errors.append(f"Missing required field: {field}")
|
errors.append(f"Missing required field: {field}")
|
||||||
|
|
||||||
# Version must be SemVer
|
|
||||||
version = pkg.get("version", "")
|
version = pkg.get("version", "")
|
||||||
if version and not re.match(r'^\d+\.\d+\.\d+$', str(version)):
|
if version and not re.match(r'^\d+\.\d+\.\d+$', str(version)):
|
||||||
errors.append(f"version '{version}' is not SemVer (expected X.Y.Z)")
|
errors.append(f"version '{version}' is not SemVer (expected X.Y.Z)")
|
||||||
|
|
||||||
# Headlamp plugin annotations
|
|
||||||
annotations = pkg.get("annotations", {}) or {}
|
annotations = pkg.get("annotations", {}) or {}
|
||||||
archive_url = annotations.get("headlamp/plugin/archive-url", "")
|
archive_url = annotations.get("headlamp/plugin/archive-url", "")
|
||||||
archive_checksum = annotations.get("headlamp/plugin/archive-checksum", "")
|
archive_checksum = annotations.get("headlamp/plugin/archive-checksum", "")
|
||||||
@@ -76,11 +72,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
if [ -f "pnpm-lock.yaml" ]; then
|
if [ -f "pnpm-lock.yaml" ]; then
|
||||||
echo "manager=pnpm" >> $GITHUB_OUTPUT
|
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")
|
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
|
echo "has_package_manager=$PM" >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
@@ -92,8 +83,6 @@ jobs:
|
|||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: ${{ inputs.node-version }}
|
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' || '' }}
|
cache: ${{ steps.pkg-manager.outputs.manager == 'npm' && 'npm' || '' }}
|
||||||
|
|
||||||
- name: Setup pnpm (via Corepack, reads version from packageManager field)
|
- name: Setup pnpm (via Corepack, reads version from packageManager field)
|
||||||
@@ -169,7 +158,15 @@ jobs:
|
|||||||
|
|
||||||
- name: Security audit
|
- name: Security audit
|
||||||
run: |
|
run: |
|
||||||
# npm retired the pnpm audit endpoint (410). Use npm audit instead.
|
# The pnpm registry audit endpoint is retired (HTTP 410).
|
||||||
# pnpm projects don't have package-lock.json, so generate one first.
|
# Use npm's offline audit to check installed packages without network.
|
||||||
npm install --package-lock-only --ignore-scripts --quiet
|
# For pnpm repos: generate a minimal package-lock.json from pnpm-lock.yaml via npm install --package-lock-only
|
||||||
npm audit --omit=dev
|
# For npm repos: use npm audit directly.
|
||||||
|
if [ "${{ steps.pkg-manager.outputs.manager }}" = "pnpm" ]; then
|
||||||
|
# Use --ignore-scripts to avoid running lifecycle hooks which may conflict with pnpm
|
||||||
|
# Use --no-audit to skip the audit during install (we audit after)
|
||||||
|
npm install --package-lock-only --ignore-scripts --quiet --no-audit 2>/dev/null || true
|
||||||
|
npm audit --omit=dev --audit-level=moderate
|
||||||
|
else
|
||||||
|
npm audit --omit=dev --audit-level=moderate
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user