From ed68967d3c583f65c6ceb8825bbcd40790efb700 Mon Sep 17 00:00:00 2001 From: Seokju Na Date: Mon, 3 Mar 2025 01:30:59 +0900 Subject: [PATCH 1/8] add test token --- .github/workflows/ci.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c00f6a2..3f482a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -178,6 +178,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: @@ -212,6 +214,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: @@ -242,7 +246,11 @@ 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: @@ -275,4 +283,8 @@ 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 From 4a42a05ee3cb88a8656f0dd9e5bf4cac36975692 Mon Sep 17 00:00:00 2001 From: Seokju Na Date: Mon, 3 Mar 2025 01:31:09 +0900 Subject: [PATCH 2/8] change dummy repo url --- tests/remote.spec.ts | 10 +++++----- tests/repository.spec.ts | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/remote.spec.ts b/tests/remote.spec.ts index b6b9fe5..f949e89 100644 --- a/tests/remote.spec.ts +++ b/tests/remote.spec.ts @@ -7,16 +7,16 @@ import { makeTmpDir } from './tmp'; describe('remote', () => { it('get remote names', { skip: LINUX }, 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 () => { 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/); }); @@ -38,14 +38,14 @@ describe('remote', () => { it('fetch remote', { skip: LINUX }, 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 () => { 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'); diff --git a/tests/repository.spec.ts b/tests/repository.spec.ts index 12131f0..0e82d03 100644 --- a/tests/repository.spec.ts +++ b/tests/repository.spec.ts @@ -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 } from './env'; import { useFixture } from './fixtures'; import { makeTmpDir } from './tmp'; @@ -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', 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!, }, }, }); From 5ec0b44ec8a38190a379b499400adf5e3692dd4b Mon Sep 17 00:00:00 2001 From: Seokju Na Date: Mon, 3 Mar 2025 02:02:46 +0900 Subject: [PATCH 3/8] fix --- .github/workflows/ci.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f482a7..3adbdb0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -246,11 +246,7 @@ jobs: run: ls -R . shell: bash - name: Test bindings - run: docker run --rm \ - -e TEST_GITHUB_TOKEN=${{ secrets.TEST_GITHUB_TOKEN }} - -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: @@ -283,8 +279,4 @@ jobs: run: ls -R . shell: bash - name: Test bindings - run: docker run --rm \ - -e TEST_GITHUB_TOKEN=${{ secrets.TEST_GITHUB_TOKEN }} - -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 From 0e761a62ef24f2349cba96b923a6f9d4cbd0398e Mon Sep 17 00:00:00 2001 From: Seokju Na Date: Mon, 3 Mar 2025 10:53:46 +0900 Subject: [PATCH 4/8] vendored ssh/https --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 3ac18c3..5c80f60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] bitflags = "2.1.0" chrono = "0.4" git2 = { version = "0.20.0", features = ["vendored-libgit2", "vendored-openssl"] } +libgit2-sys = { version = "*", features = ["ssh", "https", "vendored", "vendored-openssl"] } napi = { version = "2.16.13", default-features = false, features = ["napi6", "chrono_date"] } napi-derive = "2.16.12" thiserror = "2.0.3" From 722294132ce1438ab8da9ca07261322e6458f6f6 Mon Sep 17 00:00:00 2001 From: Seokju Na Date: Mon, 3 Mar 2025 13:01:02 +0900 Subject: [PATCH 5/8] maybe? --- .github/workflows/ci.yml | 13 ++++--------- Cargo.toml | 1 - 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3adbdb0..e9b2a1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,21 +78,16 @@ 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: yarn build --target x86_64-unknown-linux-musl name: stable - ${{ matrix.settings.target }} - node@20 runs-on: ${{ matrix.settings.host }} steps: diff --git a/Cargo.toml b/Cargo.toml index 5c80f60..3ac18c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ crate-type = ["cdylib"] bitflags = "2.1.0" chrono = "0.4" git2 = { version = "0.20.0", features = ["vendored-libgit2", "vendored-openssl"] } -libgit2-sys = { version = "*", features = ["ssh", "https", "vendored", "vendored-openssl"] } napi = { version = "2.16.13", default-features = false, features = ["napi6", "chrono_date"] } napi-derive = "2.16.12" thiserror = "2.0.3" From 5d5f2bae30125a260f0dc7a6cf1d3d7ab0f5f108 Mon Sep 17 00:00:00 2001 From: Seokju Na Date: Mon, 3 Mar 2025 13:09:07 +0900 Subject: [PATCH 6/8] perl --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9b2a1e..42fa001 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,7 +87,11 @@ jobs: - host: ubuntu-latest target: x86_64-unknown-linux-musl docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine - build: yarn build --target x86_64-unknown-linux-musl + 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: From 54a908a35610696f771b1134a9c9ecd85a42d704 Mon Sep 17 00:00:00 2001 From: Seokju Na Date: Mon, 3 Mar 2025 17:33:16 +0900 Subject: [PATCH 7/8] skip linux gnu --- tests/diff.spec.ts | 4 ++-- tests/env.ts | 40 ++++++++++++++++++++++++++++++++++++++-- tests/remote.spec.ts | 12 +++++++----- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/tests/diff.spec.ts b/tests/diff.spec.ts index a754d55..f643c55 100644 --- a/tests/diff.spec.ts +++ b/tests/diff.spec.ts @@ -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'; @@ -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'); diff --git a/tests/env.ts b/tests/env.ts index 61a7b95..288d8df 100644 --- a/tests/env.ts +++ b/tests/env.ts @@ -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(); diff --git a/tests/remote.spec.ts b/tests/remote.spec.ts index f949e89..93d526f 100644 --- a/tests/remote.spec.ts +++ b/tests/remote.spec.ts @@ -1,17 +1,19 @@ 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/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/seokju-na/dummy-repo', p); const remote = repo.getRemote('origin'); @@ -36,14 +38,14 @@ 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/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/seokju-na/dummy-repo', p); const remote = repo.getRemote('origin'); From 7ac8441ce6f58f2f1c178e944f1a944a27420132 Mon Sep 17 00:00:00 2001 From: Seokju Na Date: Mon, 3 Mar 2025 18:43:55 +0900 Subject: [PATCH 8/8] skip linux gnu --- tests/repository.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/repository.spec.ts b/tests/repository.spec.ts index 0e82d03..c59923e 100644 --- a/tests/repository.spec.ts +++ b/tests/repository.spec.ts @@ -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 } from './env'; +import { CI, TARGET } from './env'; import { useFixture } from './fixtures'; import { makeTmpDir } from './tmp'; @@ -35,7 +35,7 @@ describe('Repository', () => { await expect(fs.readFile(path.join(p, 'first'), 'utf8')).resolves.toEqual(expect.stringContaining('first')); }); - it('clone from remote', 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');