-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor clang-format, add Github Action Remove clang-format step from travis
- Loading branch information
Showing
4 changed files
with
74 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Check all pull requests against the clang-format rules. | ||
|
||
name: Clang Format | ||
|
||
# Controls when the action will run. | ||
# Run clang-format checks on all pull-requests | ||
on: | ||
pull_request: | ||
paths: | ||
- 'src/**.cpp' | ||
- 'src/**.h' | ||
|
||
paths-ignore: | ||
- 'contrib/' | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
clang-format-check: | ||
timeout-minutes: 5 | ||
|
||
# Ubuntu 18.04 at the time of writing includes clang-format-9 as default | ||
runs-on: [ubuntu-18.04] | ||
|
||
# We want to check all changed files between the pull-request base and the head of the pull request | ||
env: | ||
FORMAT_BASE: ${{ github.base_ref }} | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
|
||
# Checkout the repository as $GITHUB_WORKSPACE | ||
- uses: actions/checkout@v2 | ||
|
||
# Make sure to include the base we want to merge into | ||
- run: | | ||
git fetch --no-tags --depth=1 origin ${{ github.base_ref }} | ||
# Run the clang-format command (in $GITHUB_WORKSPACE, which is where the repo is checked out to) | ||
- name: Run clang-format | ||
run: ./scripts/clang-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
#!/bin/sh | ||
#!/bin/bash | ||
|
||
./scripts/clang-format.sh "$@" | ||
|
||
./scripts/clang-format.sh | ||
# Run clang-format, storing the output in MSG | ||
# Git runs hooks in the base directory, so we don't need to do any fancy dirname stuff. | ||
# $? will be non-zero if clang-format detected formatting issues. | ||
if [ "$?" != 0 ]; then | ||
format_ok=$? | ||
if ((format_ok == 1)); then | ||
# We've had a major malfunction! | ||
read -p "Do you want to automatically apply these changes (y/N)?" apply | ||
case $apply in | ||
y|Y) | ||
# Get the patch info from the message and apply it to the staged changes. | ||
PATCH_MODE=1 ./scripts/clang-format.sh | git apply --index - | ||
PATCH_MODE=1 ./scripts/clang-format.sh "$@" | git apply --index - | ||
;; | ||
*) exit 1;; | ||
esac | ||
else | ||
# All good, carry on. | ||
exit 0 | ||
exit $format_ok | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters