Skip to content

Commit f978b41

Browse files
mokevninclaude
andcommitted
chore(guardrails): hk, commitlint, ty, hadolint, sqruff, typos, rumdl, lychee, osv-scanner
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 8d53dbf commit f978b41

9 files changed

Lines changed: 193 additions & 0 deletions

File tree

‎.github/jactionlint.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Профиль по умолчанию. Числа ниже нужны только --fix: без них jactionlint
2+
# не выбирает срок и таймаут сам.
3+
rules:
4+
dependabot-cooldown:
5+
default-days: 7
6+
missing-timeout:
7+
default-minutes: 15

‎.github/workflows/check.yml‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Check
2+
3+
# Проверки dev-guardrails: форматы, ссылки, опечатки, workflows, секреты,
4+
# уязвимости лока и заголовки коммитов. Заголовки коммитов проверяются здесь
5+
# по диапазону пуша, потому что коммиты уходят прямо в main и pr-title.yml их
6+
# не видит, а release-please читает именно историю.
7+
on:
8+
push:
9+
branches:
10+
- main
11+
pull_request:
12+
branches:
13+
- main
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
cancel-in-progress: true
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
check:
24+
runs-on: ubuntu-latest
25+
timeout-minutes: 15
26+
steps:
27+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
28+
with:
29+
fetch-depth: 0
30+
persist-credentials: false
31+
32+
- uses: jdx/mise-action@82a612c5ab8bcda7cc5db6b7e81a8e7584c3dc6e # v5.2.3
33+
34+
- name: Install
35+
run: make install
36+
37+
- name: Run checks
38+
run: mise run check
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Commit messages
43+
env:
44+
FROM: ${{ github.event.pull_request.base.sha || github.event.before }}
45+
TO: ${{ github.event.pull_request.head.sha || github.sha }}
46+
run: |
47+
if [ "$FROM" = "0000000000000000000000000000000000000000" ]; then
48+
FROM="$TO~1"
49+
fi
50+
commitlint --from "$FROM" --to "$TO"
51+
52+
- name: Secrets
53+
run: betterleaks git --log-opts="$FROM..$TO" --no-banner .
54+
env:
55+
FROM: ${{ github.event.pull_request.base.sha || github.event.before }}
56+
TO: ${{ github.event.pull_request.head.sha || github.sha }}
57+
58+
- name: Vulnerabilities
59+
run: osv-scanner scan source --lockfile uv.lock

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ dist/
55
.venv/
66
.coverage
77
.pytest_cache/
8+
.lycheecache

‎.rumdl.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Абзацы не переносятся по ширине (MD013), CHANGELOG ведёт release-please.
2+
[global]
3+
disable = ["MD013", "MD033", "MD041"]
4+
exclude = ["node_modules"]

‎.sqruff‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[sqruff]
2+
dialect = postgres

‎commitlint.config.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { extends: ['@commitlint/config-conventional'] };

‎hk.pkl‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Хуки ставит `hk install`: на git 2.54+ это записи hook.* в .git/config,
2+
// общий core.hooksPath дерева кита они не трогают.
3+
amends "package://github.com/jdx/hk/releases/download/v2.8.1/hk@2.8.1#/Config.pkl"
4+
import "package://github.com/jdx/hk/releases/download/v2.8.1/hk@2.8.1#/Builtins.pkl"
5+
6+
// Быстрые проверки идут на каждый коммит. Сеть нужна только lychee, поэтому
7+
// ссылки проверяются в check и перед пушем.
8+
local fast = new Mapping<String, Step> {
9+
["ruff-format"] {
10+
glob = List("**/*.py")
11+
check = "uv run ruff format --check {{files}}"
12+
fix = "uv run ruff format {{files}}"
13+
}
14+
["ruff"] {
15+
glob = List("**/*.py")
16+
check = "uv run ruff check {{files}}"
17+
fix = "uv run ruff check --fix {{files}}"
18+
}
19+
["ty"] {
20+
glob = List("**/*.py")
21+
check = "uv run ty check"
22+
}
23+
["deptry"] {
24+
glob = List("**/*.py", "pyproject.toml")
25+
check = "uv run deptry ."
26+
}
27+
["hadolint"] {
28+
glob = List("Dockerfile*")
29+
check = "hadolint {{files}}"
30+
}
31+
["shellcheck"] {
32+
glob = List("**/*.sh")
33+
check = "shellcheck {{files}}"
34+
}
35+
["sqruff"] {
36+
glob = List("**/*.sql")
37+
check = "sqruff lint {{files}}"
38+
fix = "sqruff fix {{files}}"
39+
}
40+
["rumdl"] = Builtins.rumdl
41+
["typos"] = Builtins.typos
42+
["jactionlint"] = Builtins.jactionlint
43+
}
44+
45+
local all = (fast) {
46+
["lychee"] {
47+
glob = List("**/*.md")
48+
check = "lychee --config lychee.toml --no-progress {{files}}"
49+
}
50+
}
51+
52+
hooks {
53+
// stash выключен: на время хука он откатывает непроиндексированные файлы
54+
// рабочего дерева, в том числе чужие правки параллельной сессии.
55+
["pre-commit"] {
56+
fix = true
57+
stash = "none"
58+
steps = fast
59+
}
60+
// История читается release-please, поэтому заголовок коммита проверяется
61+
// до записи. В CI тот же commitlint гоняется по диапазону пуша.
62+
["commit-msg"] {
63+
steps {
64+
["commitlint"] {
65+
check = "commitlint --edit {{commit_msg_file}}"
66+
}
67+
}
68+
}
69+
["pre-push"] {
70+
steps = all
71+
}
72+
["check"] { steps = all }
73+
["fix"] {
74+
fix = true
75+
steps = all
76+
}
77+
}

‎lychee.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# GITHUB_TOKEN берётся из окружения и снимает лимит запросов github.com.
2+
max_concurrency = 8
3+
max_retries = 3
4+
retry_wait_time = 5
5+
timeout = 30
6+
cache = true
7+
max_cache_age = "1d"
8+
accept = ["200..=204", "429"]
9+
exclude_path = ["LICENSE", "node_modules"]
10+
# npmjs.com отвечает CI кодом 403 (защита от ботов), в браузере ссылки живые.
11+
exclude = ["^https://www.npmjs.com/"]

‎mise.toml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Тулинг репозитория для хоста и CI (jdx/mise-action). Версию питона держит
2+
# .python-version, зависимости проекта ставит uv. Версии проверок не пиним: latest.
3+
[tools]
4+
node = "26"
5+
uv = "latest"
6+
hk = "2"
7+
pkl = "latest"
8+
ty = "latest"
9+
hadolint = "latest"
10+
shellcheck = "latest"
11+
"github:quarylabs/sqruff" = "latest"
12+
typos = "latest"
13+
rumdl = "latest"
14+
lychee = "latest"
15+
jactionlint = "latest"
16+
betterleaks = "latest"
17+
osv-scanner = "latest"
18+
"npm:@commitlint/cli" = "latest"
19+
"npm:@commitlint/config-conventional" = "latest"
20+
21+
[tasks.setup]
22+
description = "Поставить зависимости и git-хуки"
23+
run = ["uv sync", "hk install"]
24+
25+
[tasks.check]
26+
description = "Все проверки, тот же набор, что гоняет CI"
27+
run = "hk check --all"
28+
29+
[tasks.fix]
30+
description = "Применить автоисправления"
31+
run = "hk fix --all"

0 commit comments

Comments
 (0)