ci(hooks): run ansible-test sanity before a push
Add a pre-push hook that runs scripts/ansible-test-sanity.sh, so the Build job's sanity check, which ruff and the other hooks do not cover (it failed on a name only its pylint disallows), stops a push instead of the pull request. It is pre-push and not pre-commit because a cold run builds virtualenvs and needs the network; CI's pre-commit run does not run that stage, and a local system hook builds no environment. pre-push joins default_install_hook_types, and dev-setup.sh and its test treat it like the other two hook types, so its hook script also gets the virtualenv on PATH. Verified through git push --dry-run in a throwaway clone: a commit with a disallowed name inside a function is blocked (exit 1, the same pylint message as CI, failed to push), and the push passes once it is removed. Image input: .pre-commit-config.yaml is baked into the ci image, so ci 0.2.17 -> 0.2.18 (scripts/bump_image_versions.py). The new hook adds no hook environment and no layer size; the merge builds 0.2.18 and a pin PR follows. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
This commit is contained in:
1 parent
574c0d00f9
commit
18a7e26e4f
6 files changed
+24
-6
No files matched your search
@@ -87,7 +87,7 @@ jobs:
|
||||
dockerfile: Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:6a06111c3b0a8600feadb270aec771dc239bf407b25625f93f44ab00e11f4d3c
|
||||
- name: ci
|
||||
version: 0.2.17
|
||||
version: 0.2.18
|
||||
subpath: ""
|
||||
dockerfile: images/ci/Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:6a06111c3b0a8600feadb270aec771dc239bf407b25625f93f44ab00e11f4d3c
|
||||
|
||||
+15
-1
@@ -1,4 +1,4 @@
|
||||
default_install_hook_types: [pre-commit, commit-msg]
|
||||
default_install_hook_types: [pre-commit, commit-msg, pre-push]
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/compilerla/conventional-pre-commit
|
||||
@@ -83,6 +83,20 @@ repos:
|
||||
stages: ['pre-commit']
|
||||
pass_filenames: false
|
||||
|
||||
# Pre-push only: the Build job's ansible-test sanity run, on HEAD (scripts/ansible-test-sanity.sh).
|
||||
# The sanity tests carry their own pylint, pep8 and shellcheck settings, which the hooks above do
|
||||
# not, and a cold run builds virtualenvs, so it is not a commit hook. CI's pre-commit run does not
|
||||
# run this stage (the Build job runs sanity itself), and no hook environment is built for it.
|
||||
- id: ansible-test-sanity
|
||||
name: ansible-test sanity
|
||||
description: ansible-test sanity on HEAD, as the Build job runs it
|
||||
entry: scripts/ansible-test-sanity.sh
|
||||
language: system
|
||||
pass_filenames: false
|
||||
always_run: true
|
||||
require_serial: true
|
||||
stages: ['pre-push']
|
||||
|
||||
- id: ansible-lint
|
||||
name: ansible-lint
|
||||
description: ansible-lint production profile, offline
|
||||
|
||||
@@ -27,6 +27,8 @@ or create tags: those are the operator's.
|
||||
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.
|
||||
`git push` also runs `ansible-test sanity` on HEAD (`scripts/ansible-test-sanity.sh`, the Build
|
||||
job's check, which ruff and the other hooks do not cover); its first run builds virtualenvs and takes minutes.
|
||||
- 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.
|
||||
|
||||
+3
-1
@@ -19,7 +19,9 @@
|
||||
(`requirements.yml`, into `.ansible/collections`, so local lint resolves the versions CI does)
|
||||
and installs git hooks that find the tools (the `ansible-lint` hook, `scripts/ansible-lint.sh`, uses those
|
||||
collections, also from a bare `pre-commit run`). Then
|
||||
`pre-commit run --all-files` before pushing.
|
||||
`pre-commit run --all-files` before pushing. A `git push` runs `ansible-test sanity` on HEAD
|
||||
(`scripts/ansible-test-sanity.sh`, the Build job's check; the first run builds virtualenvs and
|
||||
takes minutes), so a finding only that test reports stops the push, not the Build check.
|
||||
- Never commit credentials, tokens or key material.
|
||||
- Releases are cut by the maintainer: bump `version` in `galaxy.yml`, add a
|
||||
`release_summary:` fragment, run `antsibull-changelog release` in a release PR
|
||||
|
||||
@@ -133,7 +133,7 @@ ANSIBLE_COLLECTIONS_PATH="$collections" .venv/bin/ansible-galaxy collection inst
|
||||
|
||||
marker="# kamino-dev-setup: virtualenv first on PATH"
|
||||
# default_install_hook_types in .pre-commit-config.yaml names these; keep in step.
|
||||
for hook in pre-commit commit-msg; do
|
||||
for hook in pre-commit commit-msg pre-push; do
|
||||
file="$(git -C "$root" rev-parse --path-format=absolute --git-path "hooks/$hook")"
|
||||
if [ ! -f "$file" ]; then
|
||||
echo "error: $file was not installed by 'pre-commit install'; check default_install_hook_types in .pre-commit-config.yaml." >&2
|
||||
|
||||
@@ -52,7 +52,7 @@ if git config --get-all core.hooksPath >/dev/null 2>&1; then
|
||||
echo "Cannot install: core.hooksPath is set" >&2
|
||||
exit 1
|
||||
fi
|
||||
for h in pre-commit commit-msg; do
|
||||
for h in pre-commit commit-msg pre-push; do
|
||||
f="$(git rev-parse --path-format=absolute --git-path "hooks/$h")"
|
||||
mkdir -p "$(dirname "$f")"
|
||||
printf '#!/usr/bin/env bash\\necho "hook-ran"\\necho "$PATH"\\n' > "$f"
|
||||
@@ -143,7 +143,7 @@ class DevSetupTest(unittest.TestCase):
|
||||
repo = self.make_repo()
|
||||
result = self.run_setup(repo)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
for name in ("pre-commit", "commit-msg"):
|
||||
for name in ("pre-commit", "commit-msg", "pre-push"):
|
||||
text = self.hook(repo, name).read_text()
|
||||
self.assertIn("# kamino-dev-setup: virtualenv first on PATH", text)
|
||||
self.assertEqual(self.hooks_z(repo), b"")
|
||||
|
||||
Reference in new issue
Block a user