A tag run and the main run of the same commit shared the group keyed by the commit SHA, so one could wait on the other. Tag runs are now keyed by their ref. Cancellation stays limited to pull requests. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
100 lines
4.3 KiB
YAML
100 lines
4.3 KiB
YAML
name: Lint
|
|
|
|
# Runs on the Collection's own runner (label kamino-docker, scoped to the mortis org),
|
|
# never on the production runner. No secrets are used: the only credential is the
|
|
# job token, which is read-only for a fork pull request. No pull_request_target.
|
|
# The tools come from the ci image (images/ci, built by image.yml): the pinned Python
|
|
# tools of requirements-dev.txt 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 itself for this run (slower, same result).
|
|
on: # yamllint disable-line rule:truthy
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch: {}
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
# A newer push to the same pull request makes the running run obsolete. A push to main or a
|
|
# tag is never cancelled: each merge commit keeps its own result, and a tag run has its own
|
|
# group, so it never shares one with the main run of the same commit.
|
|
concurrency:
|
|
group: lint-${{ github.event_name == 'pull_request' && github.ref || (github.ref_type == 'tag' && github.ref || github.sha) }}
|
|
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.0@sha256:0eedfabb16fc95322b05b33917d2e551dccc6121c1537cef6a52cd5372a855eb
|
|
env:
|
|
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
|
PRE_COMMIT_HOME: /opt/pre-commit
|
|
steps:
|
|
# The container has no Node, so JavaScript actions such as actions/checkout
|
|
# cannot run; clone with git and the job token, as the environment repo does.
|
|
- 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."
|
|
else
|
|
echo "::warning::requirements-dev.txt or .pre-commit-config.yaml differ from the ci image; installing the pinned tools for this run."
|
|
/opt/venv/bin/pip install --quiet -r requirements-dev.txt
|
|
fi
|
|
|
|
- name: Run pre-commit on all files
|
|
run: |
|
|
export PATH="/opt/venv/bin:$PATH"
|
|
pre-commit run --all-files --show-diff-on-failure
|
|
|
|
# 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.
|
|
- name: Check Conventional Commits
|
|
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 conventional-pre-commit --hook-stage commit-msg \
|
|
--commit-msg-filename "$MSG_FILE"
|
|
done
|