Skip to content

Commit a793898

Browse files
authored
fix: workspace-clean install, robust Markdown and outputs, fork-PR docs (#279)
1 parent 046b66d commit a793898

7 files changed

Lines changed: 466 additions & 280 deletions

File tree

‎README.md‎

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Used by](https://img.shields.io/static/v1?label=Used%20by&message=165&color=informational&logo=slickpic)](https://github.com/commit-check/commit-check-action/network/dependents)<!-- used by badge -->
55
[![GitHub marketplace](https://img.shields.io/badge/Marketplace-commit--check--action-blue)](https://github.com/marketplace/actions/commit-check-action)
66
[![commit-check](https://img.shields.io/badge/commit--check-enabled-brightgreen?logo=Git&logoColor=white&color=%232c9ccd)](https://github.com/commit-check/commit-check)
7-
[![slsa-badge](https://slsa.dev/images/gh-badge-level3.svg?color=blue)](https://github.com/commit-check/commit-check-action/blob/a2873ca0482dd505c93fb51861c953e82fd0a186/action.yml#L59-L69)
7+
[![slsa-badge](https://slsa.dev/images/gh-badge-level3.svg?color=blue)](https://github.com/commit-check/commit-check-action/blob/main/action.yml#L84-L94)
88
[![codecov](https://codecov.io/gh/commit-check/commit-check-action/graph/badge.svg?token=QHUDSMJGS7)](https://codecov.io/gh/commit-check/commit-check-action)
99

1010
A GitHub Action for checking commit message formatting, branch naming, committer name, email, commit signoff, and more.
@@ -24,11 +24,12 @@ A GitHub Action for checking commit message formatting, branch naming, committer
2424
## Table of Contents
2525

2626
* [Usage](#usage)
27+
* [Action, pre-commit hook, or GitHub App — which to use?](#action-pre-commit-hook-or-github-app--which-to-use)
2728
* [Optional Inputs](#optional-inputs)
2829
* [GitHub Action Job Summary](#github-action-job-summary)
2930
* [GitHub Pull Request Comments](#github-pull-request-comments)
3031
* [Advanced Configuration](#advanced-configuration)
31-
* [Fork PR Comments](docs/fork-pr-comments.md)
32+
* [Fork Pull Requests](docs/fork-pr-comments.md)
3233
* [Badging Your Repository](#badging-your-repository)
3334
* [Versioning](#versioning)
3435

@@ -52,7 +53,10 @@ jobs:
5253
steps:
5354
- uses: actions/checkout@v7
5455
with:
55-
fetch-depth: 0 # With a shallow clone only HEAD, the merge commit, is checked
56+
# Required. With the default fetch-depth: 1 the clone holds only GitHub's
57+
# merge commit: the PR's own commits cannot be listed, author checks are
58+
# skipped, and the action warns and falls back to checking HEAD alone.
59+
fetch-depth: 0
5660
- uses: commit-check/commit-check-action@v2
5761
with:
5862
message: true
@@ -63,9 +67,52 @@ jobs:
6367
pr-comments: true
6468
```
6569
70+
> [!WARNING]
71+
> Without `fetch-depth: 0` the action still runs, but it cannot see the pull
72+
> request's commits. It posts `::warning title=commit-check::Could not list the
73+
> pull request's commits (is actions/checkout using fetch-depth: 0?); only HEAD
74+
> was checked` and checks only the synthetic merge commit — whose subject
75+
> `Merge <sha> into <sha>` passes the default rules — so a shallow clone makes
76+
> every PR look green. Author checks are skipped (`⊘`) for the same reason. On
77+
> `pull_request_target`, also check out `refs/pull/<number>/merge`.
78+
6679
> [!NOTE]
6780
> This action supports running on Linux, macOS, and Windows (`ubuntu-latest`, `macos-latest`, `windows-latest`).
6881

82+
### Runner requirements
83+
84+
The action is a composite step and uses what the runner already has:
85+
86+
- **Python 3.10 or newer** on `PATH` (`python3`, or `python` on Windows). No
87+
`setup-python` step is needed on GitHub-hosted runners. Everything the action
88+
installs goes under `$RUNNER_TEMP`, never into your checkout.
89+
- **`gh` CLI** — used to verify the build-provenance attestation of the
90+
`commit-check` wheel before installing it. Present on GitHub-hosted images;
91+
install it on self-hosted runners or the attestation step fails.
92+
Only the `commit-check` wheel is attested; PyGithub and the transitive
93+
dependencies are pinned by `requirements.txt` but not verified.
94+
- **Network access to PyPI and `api.github.com`** — the pinned wheels are
95+
downloaded once per run and the attestation is fetched from GitHub.
96+
- **`git`** on `PATH`, and a checkout with `fetch-depth: 0` (see above).
97+
98+
There is currently no input to skip attestation verification.
99+
100+
## Action, pre-commit hook, or GitHub App — which to use?
101+
102+
All three run the same `commit-check` engine against the same
103+
`commit-check.toml` / `cchk.toml`; they differ in where they run and what they
104+
can see.
105+
106+
| | GitHub Action (this repo) | [pre-commit hook](https://github.com/commit-check/commit-check#use-with-pre-commit) | [Commit Check GitHub App](https://github.com/marketplace/commit-check) |
107+
|---|---|---|---|
108+
| **Where it runs** | In your workflow, on the runner, after the push | On the contributor's machine, at `git commit` / `git push` | Hosted by commit-check; installed on the repository, no workflow file |
109+
| **What it checks** | Every PR commit's message, plus the PR title, branch and author checks you enable; renders a job summary, annotations, a PR comment and the `result` output | Message (`commit-msg` stage), branch, author; tag, force-push and files (`pre-push`) — one commit at a time, before it exists | Every commit of a push or pull request: message, branch, author (the PR title only in squash mode); reported as one **Commit Check** check run per commit |
110+
| **When to pick it** | You want enforcement in CI that a contributor cannot skip, per-rule outputs for later steps, or you run on GitHub Enterprise Server / need `CCHK_*` overrides | You want the fastest feedback and to stop bad commits before they are pushed; pair it with the Action, since hooks are opt-in | You want zero YAML and no Actions minutes, or feedback on [fork pull requests](docs/fork-pr-comments.md) without the Action's read-only-token limits |
111+
112+
Most teams pair the pre-commit hook (fast, local) with the Action (enforced):
113+
the hook catches a bad message before it is pushed, and the Action is why CI
114+
fails when a contributor did not install the hook.
115+
69116
## Used By
70117

71118
<p align="center">
@@ -133,9 +180,19 @@ jobs:
133180
> [!NOTE]
134181
> `pr-comments` is disabled by default.
135182
>
136-
> PR comments are skipped for pull requests from forked repositories. See
137-
> [docs/fork-pr-comments.md](docs/fork-pr-comments.md) for details on how to enable
138-
> this feature for fork contributions.
183+
> PR comments are skipped for pull requests from forked repositories, whose
184+
> `GITHUB_TOKEN` is read-only. Everything else still works there: the check
185+
> status, the annotations and the job summary. See
186+
> [Fork pull requests](docs/fork-pr-comments.md).
187+
>
188+
> **Dependabot pull requests** are not forks, but GitHub gives their
189+
> `pull_request` runs a read-only `GITHUB_TOKEN` by default. The `permissions`
190+
> key is honoured for them, so the `pull-requests: write` grant in the
191+
> [usage example](#usage) is enough; without it the action logs a
192+
> `::warning::` on the 403 and leaves the report in the job summary. Note that
193+
> Actions secrets are not available in Dependabot-triggered runs. Adding
194+
> `dependabot[bot]` to `ignore_authors` skips the checks for those PRs
195+
> altogether.
139196
>
140197
> Note: write-access to pull-requests requires the `pull-requests: write` permission.
141198
> See [usage example](#usage).
@@ -463,10 +520,13 @@ By default, commit-check-action handles this gracefully:
463520
- A **notice is added to the Job Summary** explaining why and how to fix it
464521
- The commit checks themselves **still run normally**
465522

466-
> **For most projects, this is sufficient** — contributors can see check results in the
467-
> action Job Summary. But if you *must* have PR comments on fork contributions, see
468-
> the **[Fork PR Comments](docs/fork-pr-comments.md)** documentation for
469-
> two recommended approaches with ready-to-use workflow examples.
523+
> **For most projects, this is sufficient** — a fork contributor already gets the red
524+
> check, the per-finding annotations on their diff and the full report in the job
525+
> summary. If you want feedback on the pull request itself, the
526+
> [Commit Check GitHub App](https://github.com/marketplace/commit-check) posts a check
527+
> run per commit with no workflow file (free on public repositories), or you can run
528+
> this action on `pull_request_target`. Both are covered in
529+
> **[Fork pull requests](docs/fork-pr-comments.md)**.
470530

471531
## Badging Your Repository
472532

‎action.yml‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,43 @@ runs:
5555
# Platform-specific settings
5656
if [[ "$RUNNER_OS" == "Windows" ]]; then
5757
PYTHON_CMD="python"
58-
VENV_ACTIVATE="venv/Scripts/activate"
5958
else
6059
if [[ "$RUNNER_OS" == "Linux" ]]; then
6160
# https://github.com/pypa/setuptools/issues/3269
6261
export DEB_PYTHON_INSTALL_LAYOUT=deb
6362
fi
6463
PYTHON_CMD="python3"
65-
VENV_ACTIVATE="venv/bin/activate"
6664
fi
6765
68-
# Set up virtual environment
69-
$PYTHON_CMD -m venv venv
70-
source "$VENV_ACTIVATE"
66+
# Everything the action installs lives under $RUNNER_TEMP, never in the
67+
# caller's checkout: a later `git status`, linter or upload-artifact step
68+
# must not see our venv or wheels.
69+
WORK="$RUNNER_TEMP/commit-check-action"
70+
rm -rf "$WORK" # a second invocation in the same job starts clean, so the wheel glob below matches exactly one file
71+
mkdir -p "$WORK/wheels"
72+
$PYTHON_CMD -m venv "$WORK/venv"
73+
if [[ "$RUNNER_OS" == "Windows" ]]; then
74+
source "$WORK/venv/Scripts/activate"
75+
else
76+
source "$WORK/venv/bin/activate"
77+
fi
7178
72-
# Download artifact
73-
$PYTHON_CMD -m pip download -r "$GITHUB_ACTION_PATH/requirements.txt"
79+
# One download of the pinned closure, into the scratch dir. Wheels only:
80+
# the offline install below cannot build an sdist, so a platform without
81+
# binary wheels fails here, with pip's message, rather than later.
82+
$PYTHON_CMD -m pip download -q --only-binary=:all: -d "$WORK/wheels" -r "$GITHUB_ACTION_PATH/requirements.txt"
7483
75-
# Verify artifact attestations
76-
if ! gh attestation verify commit_check-*.whl -R commit-check/commit-check; then
77-
echo "Artifact verification failed. Aborting installation."
78-
exit 1
84+
# Verify the commit-check wheel's build provenance (PyGithub and the
85+
# transitive wheels are pinned but not attested; see README "Runner requirements").
86+
WHEEL=$(ls "$WORK"/wheels/commit_check-*.whl) # exactly one: pip download of a == pin
87+
if ! gh attestation verify "$WHEEL" -R commit-check/commit-check; then
88+
echo "::error::Attestation verification failed for $(basename "$WHEEL") (self-hosted runners need the gh CLI). Aborting installation."
89+
exit 1
7990
fi
8091
81-
# Install artifact
82-
$PYTHON_CMD -m pip install commit_check-*.whl pygithub-*.whl
92+
# Install offline from the wheels we already downloaded and verified:
93+
# no second trip to PyPI, and the installed set is exactly the downloaded set.
94+
$PYTHON_CMD -m pip install -q --no-cache-dir --no-index --find-links "$WORK/wheels" -r "$GITHUB_ACTION_PATH/requirements.txt"
8395
8496
$PYTHON_CMD "$GITHUB_ACTION_PATH/main.py"
8597
env:

0 commit comments

Comments
 (0)