Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
16e7f1f
feat: patch zlib to build on node 22
llimllib Oct 17, 2025
7349c27
format
llimllib Oct 17, 2025
1dc6b15
add tests for node 22
llimllib Oct 17, 2025
65ead1b
chore: try running the tests on mac 26
llimllib Oct 17, 2025
889318b
fix: remove windows and beos patches
llimllib Oct 17, 2025
8fe0aa3
fix: update test to not expect specific SHA
llimllib Oct 17, 2025
aca7691
chore: add a CLAUDE.md
llimllib Oct 17, 2025
1c2041a
chore: bump to version 2
llimllib Oct 17, 2025
25ad787
chore: run tests on publish job to test every arch
llimllib Oct 17, 2025
beeef92
fix: lint errors
llimllib Oct 17, 2025
a8a80ce
fix: do test setup to run tests
llimllib Oct 17, 2025
6b8c034
feat: add node 22 builds to publish job
llimllib Oct 17, 2025
462e1af
add arm-linux tests to CI
llimllib Oct 17, 2025
241af0f
fix: attempt to fix memory issue on linux-arm
llimllib Oct 17, 2025
5d6bf27
try just using atomic
llimllib Oct 17, 2025
4e07245
remove tests from dockerignore
llimllib Oct 17, 2025
cd384d9
fix: try another fix, I dunno
llimllib Oct 17, 2025
09558f3
revert: changes to generate
llimllib Oct 20, 2025
44a7fbb
skip failing linux-arm tests
llimllib Oct 20, 2025
6452e0f
fix: don't dockerignore test files
llimllib Oct 20, 2025
57d7b39
chore: remove tests from publish job
llimllib Oct 20, 2025
41661ab
Revert "chore: remove tests from publish job"
llimllib Oct 20, 2025
35db3b4
chore: remove tests from publish job (actually)
llimllib Oct 20, 2025
dcb8ca4
chore: update package-lock
llimllib Oct 20, 2025
3d98bf0
fix: try tagging node version
llimllib Oct 20, 2025
c31d364
feat: rename builds manually
llimllib Oct 21, 2025
6b8fa94
fix: dockerfile syntax
llimllib Oct 21, 2025
027321b
fix: gha var not bash var
llimllib Oct 21, 2025
8b192b5
fix: try removing --napi
llimllib Oct 21, 2025
755004a
fix: --napi=false gets abi version embedded
llimllib Oct 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exclude node_modules but allow test? Are we running tests in the Docker container?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • node_modules is excluded because the docker container may have a different arch so native builds will not work
  • test was excluded to speed up cross-compilation but:
    • it's tiny so kind of useless
    • I want to run the tests on cross-compiles before releasing. I actually had it in this PR but it was too much work so I pushed it off to the future

52 changes: 33 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: build
strategy:
matrix:
node: [20]
node: [20, 22]
os:
# macos-14 is arm64 (m1)
- name: darwin
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
submodules: true
- uses: actions/setup-node@v6
with:
node-version: 20
node-version: ${{ matrix.node }}
check-latest: true
- name: Prebuildify
run: |
Expand All @@ -50,48 +50,55 @@ jobs:
sudo apt-get install -y software-properties-common git build-essential clang libssl-dev libkrb5-dev libc++-dev wget python3 zlib1g-dev

npm ci
npx prebuildify --napi --strip --tag-libc -t "$(node --version | tr -d 'v')"
# does the JOBS=2 speed things up? not sure
JOBS=2 npx prebuildify --strip --napi=false --tag-libc -t "$(node --version | tr -d 'v')"
- uses: actions/upload-artifact@v4
with:
name: prebuild-${{ runner.os }}-${{ runner.arch }}
name: prebuild-${{ runner.os }}-${{ runner.arch }}-node${{ matrix.node }}
path: ./prebuilds
retention-days: 14

# musl build still needs QEMU since there are no native Alpine/musl runners
cross-compile-musl-amd64:
name: "cross compile linux/amd64-musl"
runs-on: ubuntu-22.04
strategy:
matrix:
node: [20, 22]
steps:
- uses: actions/checkout@v5
- uses: docker/setup-qemu-action@v3
- name: build linux musl amd64
run: |
docker build --platform=linux/amd64 --tag nodegit-linux-musl-amd64 -f scripts/Dockerfile.alpine .
docker create --platform=linux/amd64 --name nodegit-linux-musl-amd64 nodegit-linux-musl-amd64
docker cp "nodegit-linux-musl-amd64:/app/prebuilds" .
docker build --platform=linux/amd64 --build-arg NODE_VERSION=${{ matrix.node }} --tag nodegit-linux-musl-amd64-node${{ matrix.node }} -f scripts/Dockerfile.alpine .
docker create --platform=linux/amd64 --name nodegit-linux-musl-amd64-node${{ matrix.node }} nodegit-linux-musl-amd64-node${{ matrix.node }}
docker cp "nodegit-linux-musl-amd64-node${{ matrix.node }}:/app/prebuilds" .
- name: "list the generated files"
run: find prebuilds
- uses: actions/upload-artifact@v4
with:
name: prebuild-linux-musl-amd64
name: prebuild-linux-musl-amd64-node${{ matrix.node }}
path: ./prebuilds
retention-days: 14

cross-compile-musl-arm64:
name: "build linux/arm64-musl"
runs-on: ubuntu-22.04-arm
strategy:
matrix:
node: [20, 22]
steps:
- uses: actions/checkout@v5
- name: build linux musl arm64
run: |
docker build --platform=linux/arm64 --tag nodegit-linux-musl-arm64 -f scripts/Dockerfile.alpine .
docker create --platform=linux/arm64 --name nodegit-linux-musl-arm64 nodegit-linux-musl-arm64
docker cp "nodegit-linux-musl-arm64:/app/prebuilds" .
docker build --platform=linux/arm64 --build-arg NODE_VERSION=${{ matrix.node }} --tag nodegit-linux-musl-arm64-node${{ matrix.node }} -f scripts/Dockerfile.alpine .
docker create --platform=linux/arm64 --name nodegit-linux-musl-arm64-node${{ matrix.node }} nodegit-linux-musl-arm64-node${{ matrix.node }}
docker cp "nodegit-linux-musl-arm64-node${{ matrix.node }}:/app/prebuilds" .
- name: "list the generated files"
run: find prebuilds
- uses: actions/upload-artifact@v4
with:
name: prebuild-linux-musl-arm64
name: prebuild-linux-musl-arm64-node${{ matrix.node }}
path: ./prebuilds
retention-days: 14

Expand All @@ -108,7 +115,7 @@ jobs:
submodules: true
- uses: actions/setup-node@v6
with:
node-version: 20
node-version: 22
check-latest: true
registry-url: "https://registry.npmjs.org"
# for the publish step, we need a version of npm that supports OIDC (>=
Expand All @@ -128,12 +135,19 @@ jobs:
mkdir -p prebuilds/darwin-arm64
mkdir -p prebuilds/darwin-x64
find ${{ steps.download.outputs.download-path }}
mv ${{ steps.download.outputs.download-path }}/prebuild-Linux-X64/linux-x64/* ./prebuilds/linux-x64/
mv ${{ steps.download.outputs.download-path }}/prebuild-Linux-ARM64/linux-arm64/* ./prebuilds/linux-arm64/
mv ${{ steps.download.outputs.download-path }}/prebuild-linux-musl-amd64/linux-x64/* ./prebuilds/linux-x64/
mv ${{ steps.download.outputs.download-path }}/prebuild-linux-musl-arm64/linux-arm64/* ./prebuilds/linux-arm64/
mv ${{ steps.download.outputs.download-path }}/prebuild-macOS-ARM64/darwin-arm64/* ./prebuilds/darwin-arm64/
mv ${{ steps.download.outputs.download-path }}/prebuild-macOS-X64/darwin-x64/* ./prebuilds/darwin-x64/
# Copy Node 20 and 22 prebuilds for each platform
mv ${{ steps.download.outputs.download-path }}/prebuild-Linux-X64-node20/linux-x64/* ./prebuilds/linux-x64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-Linux-X64-node22/linux-x64/* ./prebuilds/linux-x64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-Linux-ARM64-node20/linux-arm64/* ./prebuilds/linux-arm64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-Linux-ARM64-node22/linux-arm64/* ./prebuilds/linux-arm64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-linux-musl-amd64-node20/linux-x64/* ./prebuilds/linux-x64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-linux-musl-amd64-node22/linux-x64/* ./prebuilds/linux-x64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-linux-musl-arm64-node20/linux-arm64/* ./prebuilds/linux-arm64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-linux-musl-arm64-node22/linux-arm64/* ./prebuilds/linux-arm64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-macOS-ARM64-node20/darwin-arm64/* ./prebuilds/darwin-arm64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-macOS-ARM64-node22/darwin-arm64/* ./prebuilds/darwin-arm64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-macOS-X64-node20/darwin-x64/* ./prebuilds/darwin-x64/ 2>/dev/null || true
mv ${{ steps.download.outputs.download-path }}/prebuild-macOS-X64-node22/darwin-x64/* ./prebuilds/darwin-x64/ 2>/dev/null || true
find ./prebuilds
- name: npm install
run: npm ci
Expand Down
58 changes: 53 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
linux-test:
name: "test on linux"
name: "test node ${{ matrix.node-version }} on linux"
env:
CC: clang
CXX: clang++
Expand All @@ -18,6 +18,9 @@ jobs:
DEBIAN_FRONTEND: "noninteractive"
runs-on: ubuntu-22.04
container: ubuntu:22.04
strategy:
matrix:
node-version: [20, 22]
steps:
- name: prerequisites
run: |
Expand All @@ -28,7 +31,7 @@ jobs:
submodules: true
- uses: actions/setup-node@v6
with:
node-version: 20
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Test
run: |
Expand All @@ -50,20 +53,23 @@ jobs:
npm test

mac-test:
name: "macOS tests"
name: "test node ${{ matrix.node-version }} on macOS"
env:
CC: clang
CXX: clang++
npm_config_clang: 1
GYP_DEFINES: use_obsolete_asm=true
runs-on: macos-13
runs-on: macos-26
strategy:
matrix:
node-version: [20, 22]
steps:
- uses: actions/checkout@v5
with:
submodules: true
- uses: actions/setup-node@v6
with:
node-version: 20
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Test
run: |
Expand All @@ -82,3 +88,45 @@ jobs:

npm install
npm test

linux-arm-test:
name: "test node ${{ matrix.node-version }} on linux-arm"
env:
CC: clang
CXX: clang++
npm_config_clang: 1
GYP_DEFINES: use_obsolete_asm=true
CXXFLAGS: -std=c++17
runs-on: ubuntu-22.04-arm
strategy:
matrix:
node-version: [20, 22]
steps:
- uses: actions/checkout@v5
with:
submodules: true
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y software-properties-common git build-essential clang libssl-dev libkrb5-dev libc++-dev wget python3 zlib1g-dev
- name: Test
run: |
set -xe
mkdir ~/.ssh_tests
chmod 700 ~/.ssh_tests
printf "%b" "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh_tests/config
cat test/id_rsa.pub > ~/.ssh_tests/id_rsa.pub
cat test/id_rsa.enc | base64 -d > ~/.ssh_tests/id_rsa
chmod 600 ~/.ssh_tests/id_rsa*
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

eval "$(ssh-agent -s)"
ssh-add ~/.ssh_tests/id_rsa

npm install
npm test
145 changes: 145 additions & 0 deletions CLAUDE.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# NodeGit Development Guide

## Overview

This is [@readme/nodegit](https://www.npmjs.com/package/@readme/nodegit), a fork of the original NodeGit library that provides Node.js bindings to libgit2. This fork is maintained by Readme and includes compatibility updates for Node.js 20 and 22.

## Quick Start

### Prerequisites
- Node.js >= 20 (supports Node 20 and 22)
- Git installed on your system
- Build tools (automatically handled during install)

### Installation
```bash
npm install
```

The install process automatically:
1. Runs preinstall scripts
2. Builds native bindings using node-gyp
3. Runs postinstall scripts

## Running Tests

### Full Test Suite
```bash
npm test
```
This runs linting followed by the complete test suite.

### Tests Only (Skip Linting)
```bash
npm run mocha
```

### Debug Tests
```bash
npm run mochaDebug
```
Runs tests with inspector for debugging.

### Run Specific Tests
```bash
# Run tests matching a pattern
npm run mocha -- --grep "pattern"

# Example: Run only commit tests
npm run mocha -- --grep "commit"

# Example: Run a specific test
npm run mocha -- --grep "can amend commit"
```

### Linting Only
```bash
npm run lint
```

## Development Commands

### Building
```bash
# Full rebuild (includes code generation)
npm run rebuild

# Debug build
npm run rebuildDebug

# Recompile only (skip code generation)
npm run recompile
```

### Code Generation
```bash
# Generate missing tests
npm run generateMissingTests

# Generate native code bindings
npm run generateNativeCode

# Generate JSON API definitions
npm run generateJson
```

## Test Structure

Tests are located in:
- `test/tests/` - Main test files
- `test/utils/` - Test utilities
- `test/repos/` - Test repositories

### Common Test Issues

**macOS Version Compatibility**: Tests may fail when upgrading macOS versions due to differences in Git behavior, file system precision, or system libraries. Hardcoded expected commit IDs are particularly sensitive to environment changes.

**Memory Management**: Tests use `--expose-gc` flag to test garbage collection behavior with native bindings.

**SSH Tests**: Some tests require SSH keys located in `test/id_rsa*` files.

## CI/CD

GitHub Actions workflows:
- **tests.yml**: Runs tests on Ubuntu 22.04 and macOS-26
- **publish.yml**: Handles package publishing

## Architecture

This library provides JavaScript bindings to the libgit2 C library:
- `src/` - C++ binding code
- `lib/` - Generated JavaScript APIs
- `generate/` - Code generation scripts
- `include/` - C++ headers
- `vendor/` - Vendored dependencies (libgit2)

## Troubleshooting

### Build Issues
```bash
# Clean rebuild
rm -rf build node_modules
npm install
```

### Test Failures
- Check that Git is properly configured:
```bash
git config --global user.name "Test User"
git config --global user.email "test@example.com"
```
- Ensure SSH agent is running for SSH tests

### Platform-Specific Issues
- **Linux**: May require libssl-dev, libkrb5-dev, and pcre development packages
- **macOS**: Uses clang compiler, may require Xcode command line tools
- **Windows**: Requires Visual Studio build tools

## Contributing

1. Run tests locally: `npm test`
2. Ensure linting passes: `npm run lint`
3. Test on target Node versions (20, 22)
4. Update tests if adding new functionality

For more detailed API documentation, visit [nodegit.org](http://www.nodegit.org/).
Loading