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

refactor: simplify dist management to match GitHub Actions template

- Remove pre-commit hooks for building/checking dist
- Add check-dist.yml workflow that validates dist in CI
- This matches the approach used by actions/javascript-action
- Eliminates OS-specific build differences affecting commits
This commit is contained in:
Jason Hall 2025-07-30 09:53:16 -04:00
parent c8230cc936
commit b91371174f
Failed to extract signature
4 changed files with 39 additions and 60 deletions

39
.github/workflows/check-dist.yml vendored Normal file
View file

@ -0,0 +1,39 @@
name: Check dist
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build dist
run: npm run build
- name: Compare dist
run: |
if [ ! -d dist/ ]; then
echo "Expected dist/ directory does not exist"
exit 1
fi
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See diff below:"
git diff --ignore-space-at-eol --text dist/
echo ""
echo "Please run 'npm run build' locally and commit the changes"
exit 1
fi

View file

@ -27,18 +27,3 @@ repos:
files: \.js$
args: ['--fix']
exclude: ^dist/
- repo: local
hooks:
- id: build-dist
name: Build dist
entry: ./scripts/pre-commit-build.sh
language: system
pass_filenames: false
files: ^(index\.js|lib/.*\.js)$
- id: check-dist
name: Check dist is up to date
entry: ./scripts/pre-commit-check-dist.sh
language: system
pass_filenames: false
always_run: true

View file

@ -1,30 +0,0 @@
#!/bin/bash
# Pre-commit script to build dist with Node 20
# 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"
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
# 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,15 +0,0 @@
#!/bin/bash
# Pre-commit script to check if dist is up to date
# Try to use Node 20 via nvm if available
export NVM_DIR="$HOME/.nvm"
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
echo "dist is out of date. Run npm run build and commit the changes."
exit 1
fi