1
0
Fork 0
mirror of https://github.com/imjasonh/apidiff-action synced 2026-07-06 22:52:43 +00:00

fix: make pre-commit scripts work in CI without nvm

- Check if already on Node 20 before trying to use nvm
- This fixes CI where nvm is not available but Node 20 is already set
This commit is contained in:
Jason Hall 2025-07-30 09:35:56 -04:00
parent 113224a225
commit c8230cc936
Failed to extract signature
2 changed files with 27 additions and 22 deletions

View file

@ -1,25 +1,30 @@
#!/bin/bash
# Pre-commit script to build dist with Node 20
# Source nvm
# Check if we're already on Node 20
node_version=$(node --version)
if [[ "$node_version" =~ ^v20\. ]]; then
# Already on Node 20, just build
npm run build
exit 0
fi
# Try to use nvm if available
export NVM_DIR="$HOME/.nvm"
if [ -s "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh"
else
echo "Error: nvm not found at $NVM_DIR/nvm.sh"
exit 1
nvm install 20.9.0 >/dev/null 2>&1
nvm use 20.9.0 >/dev/null 2>&1
# Verify we switched to Node 20
node_version=$(node --version)
if [[ "$node_version" =~ ^v20\. ]]; then
npm run build
exit 0
fi
fi
# Install and use Node 20
nvm install 20.9.0 >/dev/null 2>&1
nvm use 20.9.0 >/dev/null 2>&1
# Verify Node version
node_version=$(node --version)
if [[ ! "$node_version" =~ ^v20\. ]]; then
echo "Error: Failed to switch to Node 20 (current: $node_version)"
exit 1
fi
# Build dist
npm run build
# If we're not on Node 20 and can't switch, error out
echo "Error: Node.js v20 is required (found $node_version)"
echo "Please install Node 20 or use nvm to switch versions"
exit 1

View file

@ -1,12 +1,12 @@
#!/bin/bash
# Pre-commit script to check if dist is up to date
# Source nvm
# Try to use Node 20 via nvm if available
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Use Node 20
nvm use 20.9.0 >/dev/null 2>&1
if [ -s "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh"
nvm use 20.9.0 >/dev/null 2>&1
fi
# Check if dist has uncommitted changes
if [ -n "$(git status --porcelain dist)" ]; then