WebPlatformForEmbedded / libwpe

General-purpose library specifically developed for the WPE-flavored port of WebKit.
BSD 2-Clause "Simplified" License
49 stars 36 forks source link

CI: Add a job that runs clang-format on PR changes #99

Closed aperezdc closed 2 years ago

aperezdc commented 2 years ago

Introduce a script to check the coding style, and a CI worflow which runs it only on the changes introduced by a PR. The goal of checking only the changed code is to avoid having to run a full reformatting of the tree: instead, changes that modified existing code will slowly make the tree drift towards the desired status without introducing noise in the repository history.

There are is some trickery involved in getting this to work reliably:

As a bonus, the check-style script can be run by developers locally from the command line in order to verify their changes prior to filing merge requests, e.g:

git switch -c my-feature
$EDITOR src/loader.c
git commit -m'Awesome improvements'
scripts/check-style master

The output from the script is an unified diff, which can be piped back into patch or git apply to get the suggested changes applied to the tree:

scripts/check-style master | git apply -p0 -
git add -p && git commit --amend
aperezdc commented 2 years ago

The suggestion of adding a CI build for this came from @donny-dont and I agree it is a very good idea.

The check-style scripts and GitHub Actions config is shamelessly pulled from https://github.com/Igalia/cog/pull/279 (also by me) 📜