Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 14 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,20 @@ jobs:
target: aarch64-apple-darwin
build: yarn build --target aarch64-apple-darwin
- host: windows-latest
build: yarn build --target x86_64-pc-windows-msvc
target: x86_64-pc-windows-msvc
build: yarn build --target x86_64-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-zig
build: |-
set -e &&
apt update &&
apt install -y pkg-config build-essential libssl-dev librust-openssl-dev openssl libz-dev zlib1g-dev lib32z1-dev &&
RUSTFLAGS='-C link-args=-L/usr/lib/x86_64-linux-gnu/' yarn build --target x86_64-unknown-linux-gnu --zig --zig-abi-suffix 2.17 &&
strip *.node
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: yarn build --target x86_64-unknown-linux-gnu
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: set -e && apk add --no-cache --update perl musl-dev pkgconfig openssl-dev && yarn build && strip *.node
build: |-
# perl nees for building openssl
set -e &&
apk add perl &&
yarn build
name: stable - ${{ matrix.settings.target }} - node@20
runs-on: ${{ matrix.settings.host }}
steps:
Expand Down Expand Up @@ -178,6 +177,8 @@ jobs:
shell: bash
- name: Test bindings
run: yarn vitest run
env:
TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
test-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
Expand Down Expand Up @@ -212,6 +213,8 @@ jobs:
shell: bash
- name: Test bindings
run: yarn vitest run
env:
TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
test-linux-x64-gnu-binding:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
needs:
Expand Down Expand Up @@ -242,7 +245,7 @@ jobs:
run: ls -R .
shell: bash
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn vitest run
run: docker run --rm -e TEST_GITHUB_TOKEN=${{ secrets.TEST_GITHUB_TOKEN }} -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn vitest run
test-linux-x64-musl-binding:
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
needs:
Expand Down Expand Up @@ -275,4 +278,4 @@ jobs:
run: ls -R .
shell: bash
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn vitest run
run: docker run --rm -e TEST_GITHUB_TOKEN=${{ secrets.TEST_GITHUB_TOKEN }} -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn vitest run
4 changes: 2 additions & 2 deletions tests/diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { type DiffDelta, type DiffFile, openRepository } from '../index';
import { WIN32 } from './env';
import { TARGET } from './env';
import { useFixture } from './fixtures';
import type { FlattenMethods } from './types';

Expand Down Expand Up @@ -90,7 +90,7 @@ describe('diff', () => {

// Windows track all files when 'includeUntracked' option is enabled.
// Need to look further into why.
it('get diff include untracked', { skip: WIN32 }, async () => {
it('get diff include untracked', { skip: TARGET[0] === 'win32' }, async () => {
const p = await useFixture('commits');
const repo = await openRepository(p);
await fs.writeFile(path.join(p, 'third'), 'third created');
Expand Down
40 changes: 38 additions & 2 deletions tests/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
export const CI = !!process.env.CI;
export const LINUX = process.platform === 'linux';
export const WIN32 = process.platform === 'win32';

function getTarget() {
switch (process.platform) {
case 'win32': {
switch (process.arch) {
case 'x64':
return ['win32', 'x64'] as const;
case 'ia32':
return ['win32', 'ia32'] as const;
case 'arm64':
return ['win32', 'arm64'] as const;
}
break;
}
case 'darwin': {
switch (process.arch) {
case 'x64':
return ['darwin', 'x64'] as const;
case 'arm64':
return ['darwin', 'arm64'] as const;
}
break;
}
case 'linux': {
const isMusl = !(process.report.getReport() as any).header.glibcVersionRuntime;
const type = isMusl ? 'musl' : 'gnu';
switch (process.arch) {
case 'x64':
return ['linux', 'x64', type] as const;
case 'arm64':
return ['linux', 'arm64', type] as const;
}
}
}
throw new Error('Unsupported target');
}

export const TARGET = getTarget();
22 changes: 12 additions & 10 deletions tests/remote.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { describe, expect, it } from 'vitest';
import { cloneRepository, openRepository } from '../index';
import { LINUX } from './env';
import { TARGET } from './env';
import { useFixture } from './fixtures';
import { makeTmpDir } from './tmp';

describe('remote', () => {
it('get remote names', { skip: LINUX }, async () => {
const isLinuxGnu = TARGET[0] === 'linux' && TARGET[2] === 'gnu';

it('get remote names', { skip: isLinuxGnu }, async () => {
const p = await makeTmpDir('clone');
const repo = await cloneRepository('https://github.com/toss/es-toolkit', p);
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
expect(repo.remoteNames()).toContain('origin');
});

it('get remote', { skip: LINUX }, async () => {
it('get remote', { skip: isLinuxGnu }, async () => {
const p = await makeTmpDir('clone');
const repo = await cloneRepository('https://github.com/toss/es-toolkit', p);
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
const remote = repo.getRemote('origin');
expect(remote.name()).toEqual('origin');
expect(remote.url()).toEqual('https://github.com/toss/es-toolkit');
expect(remote.url()).toEqual('https://github.com/seokju-na/dummy-repo');
expect(() => repo.getRemote('not_exists')).toThrowError(/libgit2 error: remote 'not_exists' does not exist/);
});

Expand All @@ -36,16 +38,16 @@ describe('remote', () => {
expect(remote.name()).toEqual('origin');
});

it('fetch remote', { skip: LINUX }, async () => {
it('fetch remote', { skip: isLinuxGnu }, async () => {
const p = await makeTmpDir('clone');
const repo = await cloneRepository('https://github.com/toss/es-toolkit', p);
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
const remote = repo.getRemote('origin');
await remote.fetch(['main']);
});

it('get remote default branch', { skip: LINUX }, async () => {
it('get remote default branch', { skip: isLinuxGnu }, async () => {
const p = await makeTmpDir('clone');
const repo = await cloneRepository('https://github.com/toss/es-toolkit', p);
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
const remote = repo.getRemote('origin');
const branch = await remote.defaultBranch();
expect(branch).toEqual('refs/heads/main');
Expand Down
11 changes: 6 additions & 5 deletions tests/repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { cloneRepository, initRepository, openRepository } from '../index';
import { CI, LINUX } from './env';
import { CI, TARGET } from './env';
import { useFixture } from './fixtures';
import { makeTmpDir } from './tmp';

Expand Down Expand Up @@ -35,19 +35,20 @@ describe('Repository', () => {
await expect(fs.readFile(path.join(p, 'first'), 'utf8')).resolves.toEqual(expect.stringContaining('first'));
});

it('clone from remote', { skip: LINUX }, async () => {
it('clone from remote', { skip: TARGET[0] === 'linux' && TARGET[2] === 'gnu' }, async () => {
const p = await makeTmpDir('clone');
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
expect(repo.state()).toBe('Clean');
});

it('clone from remote with credential', { skip: CI || LINUX }, async () => {
it('clone from remote with credential', { skip: !CI }, async () => {
const p = await makeTmpDir('clone');
const repo = await cloneRepository('git@github.com:seokju-na/dummy-repo', p, {
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo-private', p, {
fetch: {
followRedirects: 'All',
credential: {
type: 'SSHKeyFromAgent',
type: 'Plain',
password: process.env.TEST_GITHUB_TOKEN!,
},
},
});
Expand Down
Loading