Files
Kamino/.gitea/workflows/lint.yml
T
Defame1297 2c9221ef45
Build / build (pull_request) Successful in 36s
Lint / lint (pull_request) Successful in 3m7s
Molecule / select (pull_request) Successful in 6s
Molecule / scenarios (pull_request) Skipped
Lint / renovate-config (pull_request) Successful in 2m42s
Molecule / Result (pull_request) Successful in 1s
ci(lint): give renovate-config room for a cold image pull
Raise the renovate-config timeout to 15 minutes: after a self-bump the
runner pulls the large -full image first. The comment on the validator
step now says the clone credential is kept out of it, not the job token,
which the runner may still pass to every step. The workflow rules note
that renovate-config is the Lint job outside the ci image.

Refs: #188
Assisted-by: Claude Code
2026-12-06 17:35:28 +00:00

184 lines
9.2 KiB
YAML

name: Lint
# Runs only on the Collection's own runner (label kamino-docker, scoped to the mortis org).
# No org secret is used: the only credential is the
# job token (secrets.GITHUB_TOKEN), which is read-only for a fork pull request. No pull_request_target.
# The lint job's tools come from the ci image (images/ci, built by image.yml): the pinned Python
# tools of requirements-dev.txt, the collections of requirements.yml and the hook
# environments of .pre-commit-config.yaml are baked in. When a PR changes one of those
# files the checksum check below fails and the job installs the pinned tools and
# collections itself for this run (slower, same result).
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
workflow_dispatch: {}
permissions:
contents: read
# A newer push to the same pull request makes the running run obsolete. Other runs on one ref
# queue instead: a newer one waits for the running one and replaces one still waiting.
concurrency:
group: lint-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
lint:
runs-on: kamino-docker
# Ceiling only: the instance may cap job timeouts at app.ini's default.
timeout-minutes: 30
# The tag says which release, the digest is what is enforced (bump both together
# when image.yml publishes a new version).
container:
image: git.rkdr.net/mortis/ci:0.2.54@sha256:2742be4ba03f71f00b06f1d2b318e8fd3866a800247bbd7e52508dfb0da6312c
env:
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PRE_COMMIT_HOME: /opt/pre-commit
# Where the image bakes the collections of requirements.yml; ansible-lint --offline
# resolves the modules of the Collection's dependencies from here.
ANSIBLE_COLLECTIONS_PATH: /opt/collections
steps:
# The container has no Node, so JavaScript actions such as actions/checkout
# cannot run; clone with git and the job token.
- name: Checkout the commit under test
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: http.extraheader
GIT_CONFIG_VALUE_0: "AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}"
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
REF: ${{ github.ref }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
run: |
git clone "$REPO_URL" .
# A clone has no refs/pull/*: fetch the run's ref when the sha is not on a branch.
git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; }
echo "Checked out $(git rev-parse HEAD)"
- name: Check the baked tooling against the pins
run: |
if sha256sum --quiet -c /opt/ci-pins.sha256; then
echo "The pin files match the ci image; using the baked tools."
# A job container may not unshare, so the network is cut by environment: pip, curl,
# git over HTTPS and Python's urllib fail; a raw socket is not caught.
printf '%s\n' PIP_NO_INDEX=1 http_proxy=http://127.0.0.1:9 https_proxy=http://127.0.0.1:9 \
HTTP_PROXY=http://127.0.0.1:9 HTTPS_PROXY=http://127.0.0.1:9 no_proxy= NO_PROXY= >> "$GITHUB_ENV"
echo "::notice::Later steps run with a dead proxy; a download fails the job (bake it into images/ci)."
else
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml" \
"or .pre-commit-config.yaml differ from the ci image;" \
"installing the pinned tools and collections for this run."
/opt/venv/bin/pip install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
# --force: the baked copy of a changed pin is replaced, not kept as "already installed".
/opt/venv/bin/ansible-galaxy collection install --force -r requirements.yml -p "$ANSIBLE_COLLECTIONS_PATH"
fi
- name: Run pre-commit on all files
run: |
export PATH="/opt/venv/bin:$PATH"
pre-commit run --all-files --show-diff-on-failure
# Image pins (scripts/check_image_versions.py): a pin in a workflow must name an
# image of the matrix. Not a pre-commit hook: a change to .pre-commit-config.yaml
# is itself an input of the ci image and would force an image rebuild.
- name: Check image pins
run: |
export PATH="/opt/venv/bin:$PATH"
python3 scripts/check_image_versions.py pins
# A pull request from a renovate/ branch may only move version, tag, digest and pin
# lines (scripts/check_bot_pr_diff.py), so the bot's automerge cannot change workflow
# logic or reach the org secrets. The branch name is attacker-controlled: this only
# constrains the bot's own pull requests. The guard runs from origin/main, never from the
# pull request's own copy (a PR could weaken it); the whole scripts/ directory comes from
# the base because the guard imports check_image_versions. Not -I: that drops the
# script's directory from sys.path and the import would fail; -E -s ignore the
# environment and user site. Until origin/main has the script (the PR that introduces it)
# the PR copy runs, with a notice. The refs go through env:, never into run:.
- name: Check a bot pull request only moves pins
if: github.event_name == 'pull_request'
env:
HEAD_REF: ${{ github.head_ref }}
BASE_REF: origin/main
EVENT_NAME: ${{ github.event_name }}
run: |
export PATH="/opt/venv/bin:$PATH"
guard=scripts/check_bot_pr_diff.py
if git cat-file -e "$BASE_REF:scripts/check_bot_pr_diff.py" 2>/dev/null; then
base_dir="$(mktemp -d "${RUNNER_TEMP:-/tmp}/base.XXXXXX")"
git archive "$BASE_REF" scripts | tar -x -C "$base_dir"
guard="$base_dir/scripts/check_bot_pr_diff.py"
else
echo "::notice::$BASE_REF has no scripts/check_bot_pr_diff.py yet; running the pull request's copy"
fi
python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF"
# Without the guard: an empty no_proxy would send the fake registry on 127.0.0.1 to the dead proxy.
- name: Test the repository scripts
run: |
unset PIP_NO_INDEX http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
export PATH="/opt/venv/bin:$PATH"
python3 -m unittest discover -s tests/scripts
# The gitleaks hook scans --staged only, which is empty in a clean checkout,
# so scan the PR's commits explicitly with the binary pre-commit built.
- name: Scan PR commits for secrets
if: github.event_name == 'pull_request'
env:
SHA: ${{ github.event.pull_request.head.sha }}
run: |
GITLEAKS="$(find "$PRE_COMMIT_HOME" -type f -name gitleaks | sort | tail -n1)"
if [ ! -x "$GITLEAKS" ]; then
echo "gitleaks binary not found in the pre-commit cache" >&2
exit 1
fi
"$GITLEAKS" git --verbose --redact --log-opts="origin/main..$SHA"
# commit-msg stage hooks do not run under --all-files, so each commit's message is given to
# every commit-msg hook (Conventional Commits, refuse-agent-trailers); --no-verify skips them locally.
- name: Check commit messages
if: github.event_name == 'pull_request'
env:
SHA: ${{ github.event.pull_request.head.sha }}
run: |
export PATH="/opt/venv/bin:$PATH"
MSG_FILE="$(mktemp)"
for sha in $(git rev-list --no-merges "origin/main..$SHA"); do
git log -1 --format=%B "$sha" > "$MSG_FILE"
echo "Checking $sha"
pre-commit run --hook-stage commit-msg --commit-msg-filename "$MSG_FILE"
done
# renovate.json checked by the validator of the Renovate that runs it. The image is a copy of
# renovate.yml's pin (test_the_renovate_image_pins_are_the_same); the ci image has no Node.
renovate-config:
runs-on: kamino-docker
# Ceiling only: it includes a cold pull of the large -full image after a bump.
timeout-minutes: 15
container:
image: renovate/renovate:44.161.0-full@sha256:ddbf02e44b542343c9df696b88fd953f04cc3ee5f771221805ff8efb26595416
steps:
# The image runs as a non-root user, so the clone goes to the runner's temp directory.
- name: Checkout the commit under test
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: http.extraheader
GIT_CONFIG_VALUE_0: "AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}"
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
REF: ${{ github.ref }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
run: |
src="${RUNNER_TEMP:-/tmp}/renovate-config"
git clone "$REPO_URL" "$src"
cd "$src"
git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; }
echo "Checked out $(git rev-parse HEAD)"
# A step of its own, so the clone credential (http.extraheader) is not in the environment
# that reads renovate.json.
# --no-global: renovate.json is a repository config, not the bot's global one.
- name: Validate renovate.json
run: |
cd "${RUNNER_TEMP:-/tmp}/renovate-config"
renovate-config-validator --strict --no-global renovate.json