Skip to content

Commit de4641d

Browse files
authored
Merge pull request #2 from synadia-labs/claude/add-taskfile-and-gh-actions-6mflx
Add Taskfile.yaml and CI workflow
2 parents f3a3674 + f6d218d commit de4641d

File tree

8 files changed

+189
-22
lines changed

8 files changed

+189
-22
lines changed

.github/workflows/ci.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18+
with:
19+
persist-credentials: false
20+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
21+
with:
22+
node-version-file: .tool-versions
23+
cache: npm
24+
- run: npm ci
25+
- uses: tree-sitter/setup-action@eeb902ac2f1be576edc296309872cf476a209b7f # v2
26+
with:
27+
install-lib: false
28+
- uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
29+
with:
30+
version: 3.x
31+
- run: task ci:test
32+
33+
check-github:
34+
name: Check GitHub Actions
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38+
with:
39+
persist-credentials: false
40+
- name: Run zizmor
41+
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ build/
66
prebuilds/
77
target/
88

9+
tree-sitter-nats_server_conf.wasm
10+
libtree-*.a
11+
libtree-*.so
12+
src/*.o
13+
914
# OS files
1015
.DS_Store
1116
*.swp
@@ -18,3 +23,4 @@ target/
1823

1924
# Logs
2025
*.log
26+
.task/

.tool-versions

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

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ The grammar handles the full NATS server configuration format:
2424
```bash
2525
# Install dependencies
2626
npm install
27+
# This is more reliable than the npm approach, so we've split it out.
28+
# Assumes that you have rust/cargo installed and ~/.cargo/bin in $PATH already.
29+
command -v tree-sitter || cargo install tree-sitter-cli
2730

2831
# Generate the parser
29-
npx tree-sitter generate
32+
tree-sitter generate
3033

3134
# Run tests
32-
npx tree-sitter test
35+
tree-sitter test
3336

3437
# Parse a file
35-
npx tree-sitter parse examples/basic.conf
38+
tree-sitter parse examples/basic.conf
3639
```
3740

3841
## Building

Taskfile.yaml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# https://taskfile.dev
2+
3+
version: "3"
4+
5+
vars:
6+
TS: tree-sitter
7+
8+
# Editor install tasks are intentionally omitted.
9+
#
10+
# All supported editors (Neovim, Helix, Emacs, VS Code, Zed, Nova) require
11+
# editing user configuration files (init.lua, languages.toml, init.el, etc.)
12+
# in addition to copying files. Because there is no safe, idempotent way to
13+
# merge into an arbitrary user config, and getting it wrong could break the
14+
# user's editor setup, we do not automate these installs. See docs/editors/
15+
# for per-editor instructions.
16+
17+
tasks:
18+
default:
19+
desc: List available tasks
20+
cmds:
21+
- task --list
22+
23+
# ── Internal ───────────────────────────────────────────────────────
24+
25+
_check-tools:
26+
internal: true
27+
preconditions:
28+
- sh: command -v node
29+
msg: "node is not installed — install Node.js 22 LTS (see .tool-versions)"
30+
- sh: |
31+
major=$(node -p "process.versions.node.split(\".\")[0]")
32+
test "$major" -ge 22 -a "$major" -lt 24
33+
msg: >-
34+
Node.js >=22, <24 is required (found {{.NODE_VERSION}}).
35+
tree-sitter-cli 0.25.x does not work with Node 24+.
36+
Use asdf, fnm, or nvm to switch: see .tool-versions
37+
- sh: command -v tree-sitter
38+
msg: >-
39+
tree-sitter CLI is not installed.
40+
Install via: cargo install tree-sitter-cli
41+
vars:
42+
NODE_VERSION:
43+
sh: node --version 2>/dev/null || echo "not found"
44+
45+
_npm-deps:
46+
internal: true
47+
sources:
48+
- package.json
49+
- package-lock.json
50+
generates:
51+
- node_modules/.package-lock.json
52+
cmds:
53+
- npm ci
54+
55+
# ── Build ──────────────────────────────────────────────────────────
56+
57+
generate:
58+
desc: Regenerate the parser from the grammar
59+
deps: [_check-tools, _npm-deps]
60+
sources:
61+
- grammar.js
62+
generates:
63+
- src/parser.c
64+
cmds:
65+
- "{{.TS}} generate"
66+
67+
build:
68+
desc: Build the shared and static C libraries
69+
deps: [generate]
70+
cmds:
71+
- make
72+
73+
clean:
74+
desc: Remove build artifacts
75+
cmds:
76+
- make clean
77+
78+
# ── Test ───────────────────────────────────────────────────────────
79+
80+
test:
81+
desc: Run the tree-sitter test corpus
82+
deps: [_check-tools, _npm-deps, generate]
83+
cmds:
84+
- "{{.TS}} test"
85+
86+
test:parse-examples:
87+
desc: Parse all example files and report errors
88+
deps: [_check-tools, _npm-deps, generate]
89+
cmds:
90+
- "{{.TS}} parse examples/*.conf --stat"
91+
92+
# ── Install (system) ───────────────────────────────────────────────
93+
94+
install:
95+
desc: Install the C library and query files system-wide (may need sudo)
96+
deps: [build]
97+
cmds:
98+
- make install
99+
100+
uninstall:
101+
desc: Remove the system-wide installation (may need sudo)
102+
cmds:
103+
- make uninstall
104+
105+
# ── CI ─────────────────────────────────────────────────────────────
106+
107+
ci:
108+
desc: Run all CI checks
109+
cmds:
110+
- task: ci:test
111+
- task: ci:check-github
112+
113+
ci:test:
114+
desc: Build, test, and parse examples (used in CI)
115+
cmds:
116+
- task: test
117+
- task: test:parse-examples
118+
119+
ci:check-github:
120+
desc: Validate GitHub Actions workflows with zizmor
121+
preconditions:
122+
- sh: command -v zizmor
123+
msg: "zizmor is not installed — pip install zizmor"
124+
cmds:
125+
- zizmor --format plain .github/workflows/

docs/editors/vscode.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ This guide explains how to add NATS server configuration file support to Visual
66

77
The [anycode extension](https://marketplace.visualstudio.com/items?itemName=nicolo-ribaudo.vscode-anycode) provides tree-sitter support in VS Code.
88

9+
This relies upon the tree-sitter command (install however you wish, we show
10+
this assuming the `cargo` command) and the `tree-sitter build --wasm` step
11+
relies upon being able to run an OCI image (`emscripten/emsdk`); this will
12+
implicitly require `docker` or `podman` or some other command which
13+
tree-sitter supports for that invocation.
14+
915
### Setup
1016

1117
1. Install the anycode extension
@@ -15,8 +21,9 @@ The [anycode extension](https://marketplace.visualstudio.com/items?itemName=nico
1521
```
1622
3. Build the WASM module:
1723
```bash
18-
cd tree-sitter-nats-server-conf
19-
npx tree-sitter build --wasm
24+
cd treesitter-nats-server
25+
command -v tree-sitter || cargo install tree-sitter-cli
26+
tree-sitter build --wasm
2027
```
2128
4. Configure anycode in your VS Code `settings.json`:
2229
```json

package-lock.json

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)