Files
buryan-infra/.gitea/workflows/lint.yml
T

58 lines
2.6 KiB
YAML

name: lint
on: [push, pull_request]
jobs:
hygiene:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: YAML и compose
run: |
python3 -c 'import yaml' 2>/dev/null || (apt-get update -qq && apt-get install -y -qq python3-yaml >/dev/null 2>&1)
python3 - <<'PY'
import glob, sys, yaml
bad=[]
for p in glob.glob('**/*.yml', recursive=True)+glob.glob('**/*.yaml', recursive=True):
try:
yaml.safe_load(open(p, encoding='utf-8'))
except Exception as e:
bad.append(f"{p}: {str(e)[:80]}")
print("проверено файлов:", len(glob.glob('**/*.yml', recursive=True)))
if bad:
print("\n".join(bad)); sys.exit(1)
PY
- name: Секреты в коммите
run: |
python3 - <<'PY'
import re, subprocess, sys
rules = {
"name": re.compile(r"(?i)\b(pass|passwd|password|pwd|pw|secret|token|api[_-]?key|apikey)[a-z0-9_]{0,16}[\"']?\s*[:=]\s*[\"']?([A-Za-z0-9_\-]{16,})"),
"dsn": re.compile(r"://[^:/\s@]{1,32}:([^@\s'\"%]{12,})@"),
}
def placeholder(v):
v = v.strip().strip("'\"")
if not v: return True
if v.upper().startswith(("REMOVED", "EXAMPLE", "PLACEHOLDER", "CHANGEME", "XXX")): return True
if v.startswith(("{{", "${", "<")): return True
if re.fullmatch(r"[a-z][a-z0-9]*(_[a-z0-9]+)+", v): return True
return re.fullmatch(r"[A-Z0-9_]{6,}", v) is not None
files = subprocess.run(["git", "ls-files"], capture_output=True, text=True).stdout.split()
hits = []
for f in files:
if not f.endswith((".md", ".yml", ".yaml", ".py", ".sh", ".json", ".ini", ".conf", ".env")): continue
try: t = open(f, encoding="utf-8", errors="ignore").read()
except Exception: continue
for i, line in enumerate(t.splitlines(), 1):
for rule, rx in rules.items():
m = rx.search(line)
if m and not placeholder(m.group(m.lastindex)):
hits.append("%s:%d (%s)" % (f, i, rule))
print("файлов проверено:", len(files))
if hits:
print("\n".join(hits[:10])); sys.exit(1)
PY
- name: Обязательные файлы
run: |
for f in README.md docs/ARCHITECTURE.md ops; do
test -e "$f" || { echo "нет $f"; exit 1; }
done