diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml new file mode 100644 index 0000000..27c04a1 --- /dev/null +++ b/.github/actions/setup-env/action.yml @@ -0,0 +1,18 @@ +name: Setup Environment +description: Install Zig toolchain, Node.js, pnpm, and dependencies + +runs: + using: composite + steps: + - uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4 + - uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2 + with: + version: 0.14.1 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 + with: + node-version: 24 + cache: pnpm + - run: zig version + shell: bash + - run: pnpm install --frozen-lockfile + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..247f256 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: CI + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: ./.github/actions/setup-env + - name: Build + run: pnpm build + + test-zig: + name: Zig Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: ./.github/actions/setup-env + - name: Test + run: pnpm test:zig + + test-js: + name: JS Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: ./.github/actions/setup-env + - name: Build + run: pnpm build + - name: Test + run: pnpm test:js + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: ./.github/actions/setup-env + - name: Lint + run: pnpm lint diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 0000000..ff0fb38 --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -0,0 +1,31 @@ +name: PR Title + +on: + pull_request: + branches: [main] + types: [opened, edited, synchronize] + +jobs: + conventional-commit: + name: Conventional Commit Title + runs-on: ubuntu-latest + steps: + - name: Validate PR title + env: + PR_TITLE: ${{ github.event.pull_request.title }} + run: | + pattern='^(feat|fix|chore|docs|refactor|test|ci|perf|build|revert)(\(.+\))?(!)?: .+' + if [[ ! "$PR_TITLE" =~ $pattern ]]; then + echo "::error::PR title does not follow Conventional Commits format." + echo "" + echo "Expected: [optional scope][!]: " + echo "Got: $PR_TITLE" + echo "" + echo "Allowed types: feat, fix, chore, docs, refactor, test, ci, perf, build, revert" + echo "Examples:" + echo " feat: add new API endpoint" + echo " fix(parser): handle edge case" + echo " chore!: drop support for Node 18" + exit 1 + fi + echo "PR title is valid: $PR_TITLE" diff --git a/examples/hello_world/mod.zig b/examples/hello_world/mod.zig index 3519eda..e9daae9 100644 --- a/examples/hello_world/mod.zig +++ b/examples/hello_world/mod.zig @@ -167,6 +167,7 @@ fn Timer_ctor(env: napi.Env, cb: napi.CallbackInfo(0)) !napi.Value { timer, Timer_finalize, null, + null, ); return cb.this(); } diff --git a/examples/type_tag/mod.zig b/examples/type_tag/mod.zig index beb2cfb..a66e2d5 100644 --- a/examples/type_tag/mod.zig +++ b/examples/type_tag/mod.zig @@ -63,7 +63,7 @@ fn Cat_ctor(env: napi.Env, cb: napi.CallbackInfo(1)) !napi.Value { const cat = try allocator.create(Cat); cat.* = Cat{ .name_buf = buf, .len = name.len }; - _ = try env.wrap(cb.this(), Cat, cat, Cat_finalize, null); + _ = try env.wrap(cb.this(), Cat, cat, Cat_finalize, null, null); try env.typeTagObject(cb.this(), cat_type_tag); return cb.this(); } @@ -94,7 +94,7 @@ fn Dog_ctor(env: napi.Env, cb: napi.CallbackInfo(1)) !napi.Value { const dog = try allocator.create(Dog); dog.* = Dog{ .name_buf = buf, .len = name.len }; - _ = try env.wrap(cb.this(), Dog, dog, Dog_finalize, null); + _ = try env.wrap(cb.this(), Dog, dog, Dog_finalize, null, null); try env.typeTagObject(cb.this(), dog_type_tag); return cb.this(); } diff --git a/package.json b/package.json index 643a803..51303ec 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,12 @@ "build": "pnpm build:js && pnpm build:zig", "build:js": "tsc --outDir lib", "build:zig": "zig build", - "test:napi": "zig build test:napi", - "test:examples": "vitest run examples/**/*.test.ts", - "test": "pnpm test:napi && pnpm test:examples", - "lint:zapi": "zig fmt src", - "lint:ts": "pnpm biome check", - "lint": "pnpm lint:zapi && pnpm lint:ts", + "test:zig": "zig build test:napi", + "test:js": "vitest run examples/**/*.test.ts", + "test": "pnpm test:zig && pnpm test:js", + "lint:zig": "zig fmt src", + "lint:js": "pnpm biome check", + "lint": "pnpm lint:zig && pnpm lint:js", "lint:fix": "pnpm biome check --write" }, "files": [ @@ -31,5 +31,6 @@ "@types/node": "^24.1.0", "typescript": "^5.8.3", "vitest": "^4.0.18" - } + }, + "packageManager": "pnpm@10.8.1+sha512.c50088ba998c67b8ca8c99df8a5e02fd2ae2e2b29aaf238feaa9e124248d3f48f9fb6db2424949ff901cffbb5e0f0cc1ad6aedb602cd29450751d11c35023677" }