Skip to content

Commit 8685e49

Browse files
committed
feat: initial template-nim scaffold
Audit-driven Nim project template for axiomantic. Includes pre-commit (nph 0.7.0), mkdocs-material with mkdocstrings-nim, GH workflows (ci with [stable, 2.2.6, devel] matrix, pr-agent, release, template-cleanup, auto-tag, docs), justfile, CLAUDE.md/AGENTS.md scaffolds.
0 parents  commit 8685e49

23 files changed

Lines changed: 572 additions & 0 deletions

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 5

.github/template-cleanup-marker

Whitespace-only changes.

.github/workflows/auto-tag.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Auto Tag
2+
on:
3+
push:
4+
branches: [main]
5+
paths: ["*.nimble"]
6+
permissions:
7+
contents: write
8+
jobs:
9+
tag:
10+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with: { fetch-depth: 0, token: "${{ secrets.GITHUB_TOKEN }}" }
15+
- name: Extract version from .nimble
16+
id: ver
17+
run: |
18+
NIMBLE=$(ls *.nimble | head -1)
19+
VERSION=$(grep -m1 -E '^version\s*=\s*"' "$NIMBLE" | sed -E 's/^version\s*=\s*"([^"]+)".*/\1/')
20+
[ -z "$VERSION" ] && { echo "no version"; exit 1; }
21+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
22+
- name: Tag if not exists
23+
env: { VERSION: "${{ steps.ver.outputs.version }}" }
24+
run: |
25+
git rev-parse "v$VERSION" >/dev/null 2>&1 && { echo "Tag v$VERSION exists"; exit 0; }
26+
git config user.name "github-actions[bot]"
27+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
28+
git tag "v$VERSION"
29+
git push origin "v$VERSION"

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
on:
3+
push: { branches: [main] }
4+
pull_request:
5+
permissions:
6+
contents: read
7+
jobs:
8+
test:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu-latest]
14+
# To enable macOS testing (10x cost on private repos), add:
15+
# - macos-latest
16+
nim-version: [stable, "2.2.6", devel]
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: jiro4989/setup-nim-action@v2
20+
with:
21+
nim-version: ${{ matrix.nim-version }}
22+
- uses: actions/cache@v4
23+
with:
24+
path: ~/.nimble
25+
key: nimble-${{ runner.os }}-${{ hashFiles('**/*.nimble') }}
26+
- name: nimble install deps
27+
run: nimble install --depsOnly -y
28+
- name: nph format check
29+
run: |
30+
nimble install -y nph@0.7.0 # PIN: must match .pre-commit-config.yaml local nph hook
31+
nph --check .
32+
continue-on-error: ${{ matrix.nim-version == 'devel' }}
33+
- name: nimble check
34+
run: nimble check
35+
continue-on-error: ${{ matrix.nim-version == 'devel' }}
36+
- name: Test
37+
run: nimble test
38+
continue-on-error: ${{ matrix.nim-version == 'devel' }}

.github/workflows/docs.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Docs
2+
on:
3+
push:
4+
branches: [main]
5+
permissions:
6+
contents: write
7+
pages: write
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
with: { python-version: "3.12" }
15+
- uses: jiro4989/setup-nim-action@v2
16+
with: { nim-version: stable }
17+
- name: Install mkdocs (nim variant)
18+
run: pip install mkdocs-material mkdocstrings-nim
19+
- name: Build
20+
run: mkdocs build --strict
21+
- name: Deploy to gh-pages
22+
run: mkdocs gh-deploy --force

.github/workflows/pr-agent.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: PR Agent
2+
on:
3+
pull_request:
4+
issue_comment:
5+
permissions:
6+
contents: read
7+
pull-requests: write
8+
issues: write
9+
jobs:
10+
pr-agent:
11+
uses: axiomantic/.github/.github/workflows/pr-agent.yml@devel
12+
secrets:
13+
OPENROUTER_KEY: ${{ secrets.OPENROUTER_KEY }}

.github/workflows/release.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Release
2+
on:
3+
push:
4+
tags: ["v*"]
5+
permissions:
6+
contents: write
7+
jobs:
8+
github-release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: jiro4989/setup-nim-action@v2
13+
with: { nim-version: stable }
14+
- run: nimble build -d:release
15+
- uses: softprops/action-gh-release@v3
16+
with:
17+
generate_release_notes: true
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Template Cleanup
2+
on:
3+
push:
4+
branches: [main]
5+
permissions:
6+
contents: write
7+
jobs:
8+
cleanup:
9+
# Skip on the template repo itself
10+
if: github.repository != 'axiomantic/template-nim'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with: { token: "${{ secrets.GITHUB_TOKEN }}" }
15+
- name: Sentinel guard
16+
id: guard
17+
run: |
18+
if [ ! -f .github/template-cleanup-marker ]; then
19+
echo "Marker missing; cleanup already ran. Exiting."
20+
echo "skip=true" >> "$GITHUB_OUTPUT"
21+
fi
22+
- name: Compute new names
23+
if: steps.guard.outputs.skip != 'true'
24+
id: names
25+
run: |
26+
REPO_KEBAB="${GITHUB_REPOSITORY#*/}"
27+
REPO_SNAKE="${REPO_KEBAB//-/_}"
28+
echo "kebab=$REPO_KEBAB" >> "$GITHUB_OUTPUT"
29+
echo "snake=$REPO_SNAKE" >> "$GITHUB_OUTPUT"
30+
- name: Find/replace placeholders
31+
if: steps.guard.outputs.skip != 'true'
32+
env:
33+
KEBAB: ${{ steps.names.outputs.kebab }}
34+
SNAKE: ${{ steps.names.outputs.snake }}
35+
run: |
36+
set -euo pipefail
37+
# Rename source dir/file
38+
if [ -d src/project_name ]; then
39+
git mv src/project_name "src/${SNAKE}"
40+
fi
41+
if [ -f project_name.nimble ]; then
42+
git mv project_name.nimble "${SNAKE}.nimble"
43+
fi
44+
# Replace placeholders in tracked text files (python3 — portable across GNU/BSD sed)
45+
python3 - <<'PY'
46+
import os, pathlib, subprocess
47+
snake = os.environ["SNAKE"]
48+
kebab = os.environ["KEBAB"]
49+
tracked = subprocess.check_output(
50+
["git", "ls-files", "-z"]
51+
).split(b"\0")
52+
for raw in tracked:
53+
if not raw:
54+
continue
55+
p = pathlib.Path(raw.decode())
56+
if not p.is_file():
57+
continue
58+
try:
59+
text = p.read_text(encoding="utf-8")
60+
except (UnicodeDecodeError, OSError):
61+
continue # skip binary or unreadable files
62+
new = text.replace("project_name", snake).replace("project-name", kebab)
63+
if new != text:
64+
p.write_text(new, encoding="utf-8")
65+
PY
66+
# Remove the marker (idempotency)
67+
git rm -f .github/template-cleanup-marker
68+
- name: Commit and push
69+
if: steps.guard.outputs.skip != 'true'
70+
run: |
71+
git config user.name "github-actions[bot]"
72+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
73+
git add -A
74+
git commit -m "chore: template cleanup [skip ci]"
75+
git push

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
nimcache/
2+
*.exe
3+
*.out
4+
*.dll
5+
*.so
6+
*.dylib
7+
nimblecache/
8+
.nimble/
9+
htmldocs/
10+
site/
11+
.DS_Store
12+
.idea/
13+
.vscode/
14+
*.swp

0 commit comments

Comments
 (0)