Skip to content

Commit d781653

Browse files
committed
chore: add ci, publish workflow, and git hooks
1 parent 1e04fe7 commit d781653

5 files changed

Lines changed: 172 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Deno
17+
uses: denoland/setup-deno@v2
18+
with:
19+
deno-version: v2.x
20+
21+
- name: Verify formatting
22+
run: deno fmt --check
23+
24+
- name: Run linter
25+
run: deno lint
26+
27+
- name: Run tests
28+
run: deno test --ignore=npm

.github/workflows/publish.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
publish-jsr:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup Node
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 20
25+
26+
- name: Setup Deno
27+
uses: denoland/setup-deno@v2
28+
with:
29+
deno-version: v2.x
30+
31+
- name: Verify tag matches deno.json version
32+
shell: bash
33+
run: |
34+
set -euo pipefail
35+
tag="${GITHUB_REF_NAME}"
36+
version="${tag#v}"
37+
deno_version="$(node -p "require('./deno.json').version")"
38+
if [[ "${deno_version}" != "${version}" ]]; then
39+
echo "Tag '${tag}' does not match deno.json version '${deno_version}'."
40+
exit 1
41+
fi
42+
43+
- name: Verify formatting
44+
run: deno fmt --check
45+
46+
- name: Lint
47+
run: deno lint
48+
49+
- name: Test
50+
run: deno test --ignore=npm
51+
52+
- name: Publish to JSR
53+
run: npx jsr publish
54+
55+
github-release:
56+
runs-on: ubuntu-latest
57+
needs: [publish-jsr]
58+
59+
permissions:
60+
contents: write
61+
62+
steps:
63+
- uses: actions/checkout@v4
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Generate changelog
68+
shell: bash
69+
run: |
70+
set -euo pipefail
71+
tag="${GITHUB_REF_NAME}"
72+
73+
prev_tag="$(
74+
git tag --list "v*" --sort=-version:refname \
75+
| grep -v "^${tag}$" \
76+
| head -n 1 || true
77+
)"
78+
79+
{
80+
echo "# ${tag}"
81+
echo
82+
if [[ -n "${prev_tag}" ]]; then
83+
echo "Changes since ${prev_tag}:"
84+
echo
85+
git log --no-merges --pretty=format:"- %s (%h)" "${prev_tag}..${tag}"
86+
else
87+
echo "Changes:"
88+
echo
89+
git log --no-merges --pretty=format:"- %s (%h)" "${tag}"
90+
fi
91+
echo
92+
} > RELEASE_NOTES.md
93+
94+
- name: Create GitHub release
95+
uses: softprops/action-gh-release@v2
96+
with:
97+
name: ${{ github.ref_name }}
98+
tag_name: ${{ github.ref_name }}
99+
body_path: RELEASE_NOTES.md

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,25 @@ import { formatCaret } from "jsr:@claudiu-ceia/exp";
394394
console.log(formatCaret("1 + ", 4));
395395
```
396396

397+
This package also exports a richer report-style formatter (used by the CLI):
398+
399+
```ts
400+
import { formatDiagnosticReport } from "jsr:@claudiu-ceia/exp";
401+
402+
console.log(
403+
formatDiagnosticReport("1 + ", {
404+
message: "expected expression at 1:4",
405+
index: 4,
406+
}),
407+
);
408+
```
409+
410+
Diagnostics helpers exported from `mod.ts`:
411+
412+
- `formatCaret` / `formatSpanCaret`
413+
- `formatDiagnosticCaret` (prefers `index`, falls back to `span.start`)
414+
- `formatDiagnosticReport` (Elm/OCaml-inspired report output)
415+
397416
- `ExpParseError`: includes `index` (byte index into the input string)
398417
- `ExpEvalError`: includes `span` (AST span) and `steps` (budget counter)
399418

deno.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@
66
},
77
"publish": {
88
"exclude": [
9+
".github/",
910
"bench/",
11+
"cli/",
12+
"coverage/",
13+
"scripts/",
1014
"tests/",
1115
"npm/"
1216
]
1317
},
1418
"tasks": {
19+
"fmt": "deno fmt",
20+
"lint": "deno lint",
21+
"test": "deno test --ignore=npm",
1522
"check": "deno fmt && deno lint && deno test --ignore=npm",
1623
"build:npm": "deno run -A scripts/build-npm.ts",
1724
"exp": "deno run -A cli/exp.ts",
18-
"repl": "deno task exp -- repl"
25+
"repl": "deno task exp -- repl",
26+
"hooks:install": "ln -sf ../../scripts/pre-commit .git/hooks/pre-commit && chmod +x scripts/pre-commit",
27+
"hooks:uninstall": "rm -f .git/hooks/pre-commit"
1928
},
2029
"imports": {
2130
"@std/assert": "jsr:@std/assert@^1.0.17",

scripts/pre-commit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
echo "Running pre-commit checks..."
6+
7+
echo "Formatting..."
8+
deno fmt --check
9+
10+
echo "Linting..."
11+
deno lint
12+
13+
echo "Testing..."
14+
deno test --ignore=npm
15+
16+
echo "All checks passed!"

0 commit comments

Comments
 (0)