Skip to content

Commit 5739748

Browse files
authored
Merge pull request #11 from imjasonh/fix-dist-folder
Fix critical issue: commit dist/index.js
2 parents a627281 + 422a347 commit 5739748

File tree

10 files changed

+32446
-34
lines changed

10 files changed

+32446
-34
lines changed

.github/workflows/ci.yml

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,99 @@ on:
77
branches: [main]
88

99
permissions:
10-
contents: read
10+
contents: write
11+
pull-requests: write
1112

1213
jobs:
13-
pre-commit:
14+
check-dist:
1415
runs-on: ubuntu-latest
1516
steps:
1617
- uses: actions/checkout@v4
18+
with:
19+
# Use a token that can push for PR events from same repo
20+
token: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && secrets.GITHUB_TOKEN || github.token }}
21+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
22+
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version-file: .node-version
26+
cache: npm
27+
- run: npm ci
28+
- run: npm run build
29+
- id: check-changes
30+
run: |
31+
if [ -n "$(git status --porcelain dist/)" ]; then
32+
echo "changes=true" >> "$GITHUB_OUTPUT"
33+
else
34+
echo "changes=false" >> "$GITHUB_OUTPUT"
35+
fi
36+
37+
# For push events, just fail if out of date
38+
- name: Fail if dist is out of date (push)
39+
if: github.event_name == 'push' && steps.check-changes.outputs.changes == 'true'
40+
run: |
41+
echo "Detected uncommitted changes after build. See diff below:"
42+
git diff --ignore-space-at-eol --text dist/
43+
echo ""
44+
echo "Please run 'npm run build' locally and commit the changes."
45+
exit 1
46+
47+
# For PRs from same repo, update automatically
48+
- name: Update dist (PR)
49+
if: |
50+
github.event_name == 'pull_request' &&
51+
steps.check-changes.outputs.changes == 'true' &&
52+
github.event.pull_request.head.repo.full_name == github.repository
53+
run: |
54+
git config user.name "github-actions[bot]"
55+
git config user.email "github-actions[bot]@users.noreply.github.com"
56+
git add dist/
57+
git commit -m "chore: update dist" --no-verify
58+
git push
59+
echo ""
60+
echo "✅ Updated dist/ directory. The check-dist job will pass on the next CI run."
61+
echo ""
62+
exit 1 # Fail to prevent auto-merge of out-of-date dist
63+
64+
# For PRs from forks, fail with instructions
65+
- name: Fail if dist is out of date (fork PR)
66+
if: |
67+
github.event_name == 'pull_request' &&
68+
steps.check-changes.outputs.changes == 'true' &&
69+
github.event.pull_request.head.repo.full_name != github.repository
70+
run: |
71+
echo "Detected uncommitted changes after build. See diff below:"
72+
git diff --ignore-space-at-eol --text dist/
73+
echo ""
74+
echo "This PR is from a fork. Please run 'npm run build' locally and commit the changes."
75+
exit 1
1776
77+
pre-commit:
78+
runs-on: ubuntu-latest
79+
steps:
80+
- uses: actions/checkout@v4
1881
- uses: actions/setup-python@v5
1982
with:
2083
python-version: '3.x'
21-
2284
- uses: actions/setup-node@v4
2385
with:
2486
node-version: '20'
2587
cache: 'npm'
26-
27-
- name: Install dependencies
28-
run: npm ci
29-
88+
- run: npm ci
3089
- uses: pre-commit/[email protected]
3190

3291
# Test the action itself
3392
test-action:
3493
runs-on: ubuntu-latest
3594
steps:
3695
- uses: actions/checkout@v4
37-
3896
- uses: actions/setup-go@v5
3997
with:
4098
go-version: 'stable'
41-
4299
- uses: actions/setup-node@v4
43100
with:
44101
node-version: '20'
45-
46-
# Build the action
47-
- name: Build action
48-
run: |
102+
- run: |
49103
npm ci
50104
npm run build
51105

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ yarn-debug.log*
55
yarn-error.log*
66

77
# Build output
8-
dist/
8+
# dist/ is intentionally committed for GitHub Actions
99

1010
# Test coverage
1111
coverage/

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.9.0

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.9.0

.pre-commit-config.yaml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ repos:
33
rev: v4.5.0
44
hooks:
55
- id: trailing-whitespace
6+
exclude: ^dist/
67
- id: end-of-file-fixer
8+
exclude: ^dist/
79
- id: check-yaml
810
- id: check-added-large-files
11+
exclude: ^dist/
912
- id: check-json
1013
- id: pretty-format-json
1114
args: ['--autofix']
@@ -15,25 +18,12 @@ repos:
1518
rev: v3.1.0
1619
hooks:
1720
- id: prettier
21+
exclude: ^(dist/|.*\.md$)
1822

1923
- repo: https://github.com/pre-commit/mirrors-eslint
2024
rev: v8.56.0
2125
hooks:
2226
- id: eslint
2327
files: \.js$
2428
args: ['--fix']
25-
26-
- repo: local
27-
hooks:
28-
- id: build-dist
29-
name: Build dist
30-
entry: npm run build
31-
language: system
32-
pass_filenames: false
33-
files: ^(index\.js|lib/.*\.js)$
34-
- id: check-dist
35-
name: Check dist is up to date
36-
entry: bash -c 'if [ -n "$(git status --porcelain dist)" ]; then echo "dist is out of date. Run npm run build and commit the changes."; exit 1; fi'
37-
language: system
38-
pass_filenames: false
39-
always_run: true
29+
exclude: ^dist/

CLAUDE.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This is a GitHub Action written in Node.js that detects breaking API changes in
1010

1111
### Development
1212

13+
**Important**: Use Node.js v20 to match GitHub Actions runtime.
14+
1315
```bash
1416
# Install dependencies
1517
npm ci
@@ -47,21 +49,18 @@ INPUT_OLD=HEAD~1 INPUT_NEW=HEAD node index.js
4749
### Core Components
4850

4951
1. **index.js** - Main entry point that:
50-
5152
- Reads GitHub Action inputs
5253
- Determines which commits/directories to compare
5354
- Orchestrates the apidiff run, parsing, and PR commenting
5455
- Sets action outputs
5556

5657
2. **lib/apidiff.js** - Handles running the official apidiff tool:
57-
5858
- Installs `golang.org/x/exp/cmd/apidiff` if not present
5959
- Supports both git refs and directory comparisons
6060
- For directories: creates export files first, then compares them
6161
- For git refs: runs apidiff directly on the commits
6262

6363
3. **lib/parser.js** - Parses apidiff text output:
64-
6564
- Extracts breaking and compatible changes by package
6665
- Converts to structured format
6766
- Generates markdown reports for PR comments
@@ -83,7 +82,33 @@ Each test case has `old/` and `new/` subdirectories with Go code.
8382

8483
### Build Process
8584

86-
The action uses `@vercel/ncc` to compile all dependencies into a single `dist/index.js` file. This is required for GitHub Actions and must be committed to the repository.
85+
The action uses `@vercel/ncc` to compile all dependencies into a single `dist/index.js` file. This is required for GitHub Actions and must be committed to the repository. The dist/ folder is intentionally NOT in .gitignore.
86+
87+
**Important**: The dist must be built with Node.js v20 to match GitHub Actions runtime.
88+
89+
To build and commit dist after making changes:
90+
91+
```bash
92+
# Method 1: Use the helper script
93+
./scripts/use-node-20.sh # Switches to Node 20
94+
npm run build
95+
git add dist/index.js
96+
git commit -m "Rebuild dist"
97+
98+
# Method 2: Manual with nvm
99+
nvm use # Reads .nvmrc and switches to Node 20.9.0
100+
node --version # Should show v20.x.x
101+
npm run build
102+
git add dist/index.js
103+
git commit -m "Rebuild dist"
104+
```
105+
106+
**Important**: The pre-commit hooks will:
107+
1. Verify you're using Node 20 before building dist
108+
2. Automatically rebuild dist when source files change
109+
3. Prevent commits if dist is out of date
110+
111+
If you get an error about Node version, switch to Node 20 using `nvm use` or `./scripts/use-node-20.sh`.
87112

88113
### Pre-commit Hooks
89114

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contributing
2+
3+
## Building the Action
4+
5+
Before committing changes that affect the action code, you must rebuild the dist folder:
6+
7+
```bash
8+
npm run build
9+
```
10+
11+
This compiles all dependencies into `dist/index.js` which is what GitHub Actions actually runs.
12+
13+
**Important**: The dist folder must be committed to the repository for the action to work.
14+
15+
### Automatic dist updates
16+
17+
If you forget to rebuild dist, the `update-dist` workflow will automatically update it for you on pull requests.
18+
19+
## Node Version
20+
21+
This project requires Node.js v20. We recommend using nvm to manage Node versions:
22+
23+
```bash
24+
nvm use
25+
npm ci
26+
npm run build
27+
```
28+
29+
## Testing
30+
31+
Run tests with:
32+
33+
```bash
34+
npm test
35+
```
36+
37+
## Pre-commit Hooks
38+
39+
This project uses pre-commit hooks to ensure code quality. Install them with:
40+
41+
```bash
42+
pre-commit install
43+
```

0 commit comments

Comments
 (0)