Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,42 @@ jobs:
echo "Base Ref: $BASE_REF"
echo "PR DESCRIPTION: $PR_DESCRIPTION"
if [ "$EVENT_NAME" = "pull_request" ]; then
if [[ "$PR_DESCRIPTION" != *"Changelog-None"* && \
-z "$(git log origin/$BASE_REF..HEAD --oneline --grep='Changelog-')" && \
"$(git rev-parse --abbrev-ref HEAD)" != "$BASE_REF" ]]; then
echo "::error::'Changelog' entry is missing in all commits, and 'Changelog-None' not specified in the PR description"
on_base=0
if [ "$(git rev-parse --abbrev-ref HEAD)" = "$BASE_REF" ]; then
on_base=1
fi
found=0
if ! commits=$(git rev-list "origin/${BASE_REF}..HEAD"); then
echo "::error::Cannot list commits origin/${BASE_REF}..HEAD"
exit 1
else
if [[ "$PR_DESCRIPTION" == *"Changelog-None"* ]]; then
echo "Changelog found in PR description"
else
echo "Changelog found in Commit \"$(git log origin/$BASE_REF..HEAD --oneline --grep='Changelog-')\""
fi
# Same shape devtools/changelog.py keeps: class, colon, then space.
# A class with no colon or no space does not count. Changelog-None
# is the opt-out, in a commit or in the PR body.
while IFS= read -r sha; do
[ -n "$sha" ] || continue
msg=$(git show -s --format=%B "$sha")
shopt -s nocasematch
while IFS= read -r line; do
if [[ "$line" =~ ^[[:space:]]*Changelog-(Added|Changed|Deprecated|Fixed|Removed|Experimental):[[:space:]] ]] || [[ "$line" =~ ^[[:space:]]*Changelog-None[[:space:]]*$ ]] || [[ "$line" =~ ^[[:space:]]*Changelog-None: ]]; then
found=1
break
fi
done <<< "$msg"
shopt -u nocasematch
if [ "$found" -eq 1 ]; then
break
fi
done <<< "$commits"
if [[ "$PR_DESCRIPTION" == *"Changelog-None"* ]]; then
echo "Changelog found in PR description"
elif [ "$found" -eq 1 ]; then
echo "Changelog found in commit range origin/${BASE_REF}..HEAD"
elif [ "$on_base" -eq 1 ]; then
echo "HEAD is ${BASE_REF}; changelog check skipped"
else
echo "::error::'Changelog' entry is missing in all commits, and 'Changelog-None' not specified in the PR description"
exit 1
fi
else
echo "Not a PR event."
Expand Down
125 changes: 125 additions & 0 deletions .github/workflows/per-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
name: Per-commit checks
# Builds and tests every commit of a PR except the last, which the main CI
# workflow already covers.
#
# Off by default. A maintainer turns it on for all PRs by setting the
# repository variable PER_COMMIT_CHECKS to "true", for one PR by adding the
# "per-commit-checks" label, or runs it by hand on a branch.
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
workflow_dispatch:
inputs:
base:
description: Branch the commits are compared against
default: master
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
contents: read

env:
# Reduce size, as in the main CI workflow
RUST_PROFILE: small
SLOW_MACHINE: 1
SCCACHE_GHA_ENABLED: "true"
BASE_REF: ${{ github.base_ref || inputs.base }}
PASSED_KEY: check-commits-${{ github.event.pull_request.number || github.ref_name }}

jobs:
per-commit:
name: Build and test each commit
runs-on: ubuntu-24.04
timeout-minutes: 120
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.action == 'labeled' &&
github.event.label.name == 'per-commit-checks') ||
(github.event.action != 'labeled' &&
(vars.PER_COMMIT_CHECKS == 'true' ||
contains(github.event.pull_request.labels.*.name, 'per-commit-checks')))
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0

- name: Set up Python 3.10
uses: actions/setup-python@v7
with:
python-version: "3.10"

- name: Install uv
uses: astral-sh/setup-uv@v10.3.2

- uses: actions/cache@v6
with:
path: ~/ci-cache
key: apt-${{ runner.os }}

- name: Install dependencies
run: |
bash -x .github/scripts/setup.sh
# check-source checks BOLT quotes
git clone https://github.com/lightning/bolts.git ../bolts

- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.11

# Commits that passed on an earlier push of this PR are not rechecked.
- name: Restore list of commits that passed
uses: actions/cache/restore@v6
with:
path: ~/check-commits
key: ${{ env.PASSED_KEY }}-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: |
${{ env.PASSED_KEY }}-

# The Rust build is the slow part, and the main CI workflow builds the
# last commit with it anyway.
- name: Configure
run: |
git fetch origin "$BASE_REF"
rust=--disable-rust
if ! git diff --quiet "origin/$BASE_REF...HEAD" -- '*.rs' '*Cargo.toml' Cargo.lock cln-grpc/ cln-rpc/ contrib/msggen/ doc/schemas/; then
rust=--enable-rust
fi
./configure --enable-debugbuild --disable-valgrind "$rust" CC="sccache gcc"

- name: Check each commit
env:
COMPAT: 1
RUSTC_WRAPPER: sccache
PYTEST_OPTS: --timeout=1800
CHECK_COMMITS_SKIP_TIP: 1
CHECK_COMMITS_LOGDIR: ${{ runner.temp }}/check-commits-logs
run: |
mkdir -p ~/check-commits
touch ~/check-commits/passed
export CHECK_COMMITS_CACHE=~/check-commits/passed
export GRPC_BREAKING_BASE_REF="origin/$BASE_REF"
# Use the base branch's script, so a PR branched before a change
# to it is checked the same way as every other PR.
script="$RUNNER_TEMP/check-commits.sh"
git show "origin/$BASE_REF:tools/check-commits.sh" > "$script" 2>/dev/null || cp tools/check-commits.sh "$script"
chmod +x "$script"
sg wireshark "uv run eatmydata $script origin/$BASE_REF"

- name: Save list of commits that passed
if: always()
uses: actions/cache/save@v6
with:
path: ~/check-commits
key: ${{ env.PASSED_KEY }}-${{ github.run_id }}-${{ github.run_attempt }}

- name: Upload step logs
if: failure()
uses: actions/upload-artifact@v7
with:
name: check-commits-logs
path: ${{ runner.temp }}/check-commits-logs
if-no-files-found: ignore
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ repos:
exclude: ccan|contrib|tests/fuzz/corpora
stages: [ manual ]

- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.23.0
hooks:
- id: commitlint
stages: [ commit-msg ]

- repo: local
hooks:
# Reimplementation of `make check-amount-access` for pygrep.
Expand Down
32 changes: 31 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,41 @@ check-grpc-breaking:
echo "Checking gRPC protos against $$tag"; \
$(BUF) breaking cln-grpc/proto --against ".git#tag=$$tag,subdir=cln-grpc/proto"

# Only lines added since BASE_REF are checked (doc/Makefile sets the
# default): see tools/added-lines.sh.
check-xfail-strict:
@tools/check-xfail-strict.sh $(BASE_REF)

check-switch-default:
@tools/check-switch-default.py $(BASE_REF)

check-comments:
@tools/check-comments.py $(BASE_REF)

check-unused-functions:
@tools/check-unused-functions.py $(BASE_REF)

check-take-parent:
@tools/check-take-parent.py $(BASE_REF)

# The message of each commit since BASE_REF.
check-commit-msgs:
@tools/check-commit-msgs.py $(BASE_REF)

# This should NOT compile things!
check-source: check-makefile check-whitespace check-spelling check-python-flake8 check-includes check-shellcheck check-setup_locale check-tmpctx check-discouraged-functions check-amount-access check-bad-sprintf check-wire-format check-source-bolt check-security check-msggen-grpc check-grpc-breaking
check-source: check-makefile check-whitespace check-spelling check-python-flake8 check-includes check-shellcheck check-setup_locale check-tmpctx check-discouraged-functions check-amount-access check-bad-sprintf check-wire-format check-source-bolt check-security check-msggen-grpc check-grpc-breaking check-xfail-strict check-switch-default check-comments check-unused-functions check-take-parent check-commit-msgs

full-check: check check-source

# Build, check-source, unit tests and touched integration tests on each
# commit since BASE_REF: see tools/check-commits.sh.
check-commits:
@uv run tools/check-commits.sh $(BASE_REF)

# The same, with the whole integration suite on every commit.
check-commits-full:
@CHECK_COMMITS_PYTEST=all uv run tools/check-commits.sh $(BASE_REF)

# Simple target to be used on CI systems to check that all the derived
# files were checked in and updated. It depends on the generated
# targets, and checks if any of the tracked files changed. If they did
Expand Down
56 changes: 0 additions & 56 deletions commitlint.config.js

This file was deleted.

35 changes: 35 additions & 0 deletions tools/added-lines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Print "path:line" for every line the working tree adds since the merge
# base of BASE and HEAD, in files matching the pathspecs. A check built on
# this complains about new code only, not about what is already there.
#
# Usage: tools/added-lines.sh BASE [pathspec...]

set -o pipefail

base=${1:?usage: added-lines.sh BASE [pathspec...]}
shift

if ! mergebase=$(git merge-base "$base" HEAD 2> /dev/null); then
echo "added-lines: no merge base with '$base', so no lines are checked" >&2
exit 0
fi

# With -U0 a hunk is only removed and added lines; the +++ header is told
# apart from an added line by coming before the first hunk of its file.
git -c core.quotePath=false diff -U0 --no-color --no-ext-diff --no-prefix "$mergebase" -- "$@" | awk '
/^diff --git / { header = 1; next }
header && /^\+\+\+ / { file = substr($0, 5); next }
/^@@ / {
header = 0
split($3, range, ",")
line = substr(range[1], 2) + 0
next
}
!header && /^\+/ { print file ":" line; line++ }
' || exit 1

# A file git does not know yet is new in every line.
git ls-files --others --exclude-standard -- "$@" | while IFS= read -r file; do
awk -v file="$file" '{ print file ":" NR }' "$file"
done
Loading
Loading