chore: add scripts/dev-setup.sh and a CLAUDE.md for working in this repository #12

Merged
Defame1297 merged 1 commits from chore/dev-setup-and-claude-md into main 2026-10-25 16:40:27 +00:00
3 changed files with 97 additions and 2 deletions

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
# CLAUDE.md
Guidance for Claude Code (claude.ai/code) in this repository.
## What this is
`mortis.kamino`: an Ansible Collection (GPL-3.0-or-later, REUSE-compliant), extracted role by
role from the author's homelab Environment repo (`Defame1297/ansible-homelab-mono`). The
design contract is ADR 0004 in that repo (`docs/adr/0004-collection-consumption-and-release.md`)
and the tracking issue is its epic #486. There are no roles here yet: wave 1 arrives with the
extraction.
The repo is **private and takes no fork pull requests** until the author has verified the
isolation of its CI runner. Do not change visibility, repository settings, branch or tag
protection, or create tags: those are the operator's.
## Working here
- Set up once per clone: `scripts/dev-setup.sh` (a virtualenv with the pinned tools and git
hooks that find them). The `language: system` hooks run `reuse`, `ansible-lint` and
`antsibull-changelog` by name, so a hook run without that virtualenv on `PATH` fails.
- **Commit with git in a clone, never through the Gitea API.** The hooks (REUSE, yamllint,
actionlint, ansible-lint, gitleaks, changelog lint, Conventional Commits) only run in
`git commit`; an API commit skips them and CI finds the problem after the push. The first
hook run builds the Go hook environments and takes minutes: run commits in the background.
- Feature branch and pull request; `main` and `v*` tags are protected. Never push to `main`.
Releases are the operator's: annotated `vX.Y.Z` tags equal to `galaxy.yml`'s version.
- Conventional Commits. A PR says what was verified and what was not.
- There is no local molecule and no container runtime on the control host: do not install one.
Molecule runs in CI, on the repository's own runner (label `kamino-molecule`).
- Changes that can affect a consumer need a changelog fragment (`changelogs/fragments/`).
New files are covered by `REUSE.toml`; third-party-derived content needs its own annotation.
## Workflows (`.gitea/workflows/`)
- Never `pull_request_target`. No secrets on `pull_request`. Pass ref, repo and name values to
scripts through `env:`, never interpolate `${{ github.* }}` into a `run:` block.
- Runner labels are `kamino-docker` and `kamino-molecule` only (`.gitea/actionlint.yaml`). Use
the `github.*` contexts, which Gitea aliases; actionlint does not know `gitea.*`.
- Lint and Build run in the `ci` image. After the checkout they compare the pin files with the
checksums baked into the image: a PR that changes `requirements-dev.txt` or
`.pre-commit-config.yaml` takes the slower path that installs the pinned tools.
- Molecule discovers `extensions/molecule/*/` and `roles/*/molecule/*/`. The `image-smoke`
scenario tests the molecule image itself.
## Images (`images/`)
- `ci` and `molecule-ubuntu2404`, built by `image.yml` with kaniko on push to `main` (never on
pull requests) and pushed to `git.rkdr.net/mortis/<name>`.
- Each has a semver `version:` in the workflow's build matrix. A published version tag is never
moved (the job looks it up in the registry first): bump the version in the PR that changes
the image.
- Consumers pin `image:<version>@sha256:<digest>` (`lint.yml`, `build.yml`, `molecule.yml`).
A build prints the new digest; moving a pin is a reviewed edit, and every build has a new
digest.
- Each pushed layer must stay below 100 MB: Cloudflare rejects larger request bodies with
HTTP 413. That is why the `ci` image deletes the Go toolchains from the hook cache.
- The push credential is the org Actions secrets `PACKAGE_PUSH_USER` and `PACKAGE_PUSH_TOKEN`.
Never print or use them anywhere else.
+2 -2
View File
@@ -12,8 +12,8 @@
- Role variables carry the role name as a prefix (`<role>_<name>`).
- Third-party material needs an SPDX header, a `REUSE.toml` annotation (it
overrides file headers) and an entry in `NOTICE`.
- Set up the tooling with `pip install -r requirements-dev.txt` in a virtualenv,
then run `pre-commit install --install-hooks` once and
- Set up the tooling once per clone with `scripts/dev-setup.sh`: it creates a virtualenv with
the pinned tools (`requirements-dev.txt`) and installs git hooks that find them. Then
`pre-commit run --all-files` before pushing.
- Never commit credentials, tokens or key material.
- Releases are cut by the maintainer: bump `version` in `galaxy.yml`, add a
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Sets up a local checkout for development: a virtualenv with the pinned tools
# (requirements-dev.txt, the versions CI runs) and git hooks that find them.
#
# scripts/dev-setup.sh
#
# Some hooks of .pre-commit-config.yaml are `language: system` (REUSE, changelog lint,
# ansible-lint): they run their tools by name, so the tools must be on PATH when git
# runs the hook. `pre-commit install` does not arrange that, so this script puts the
# virtualenv first on PATH inside the installed hook scripts. It is idempotent; run it
# again after changing requirements-dev.txt or the hook types.
set -euo pipefail
root="$(git rev-parse --show-toplevel)"
cd "$root"
python3 -m venv .venv
.venv/bin/pip install --quiet --disable-pip-version-check -r requirements-dev.txt
.venv/bin/pre-commit install --install-hooks
marker="# kamino-dev-setup: virtualenv first on PATH"
for hook in pre-commit commit-msg; do
file="$(git rev-parse --git-path "hooks/$hook")"
if ! grep -qxF "$marker" "$file"; then
tmp="$(mktemp)"
{
head -n 1 "$file"
printf '%s\n' "$marker" "export PATH=\"$root/.venv/bin:\$PATH\""
tail -n +2 "$file"
} > "$tmp"
cat "$tmp" > "$file" # keeps the file mode of the hook
rm -f "$tmp"
fi
done
echo "Done: git commit now runs the hooks with the tools in $root/.venv/bin."