Skip to content

Commit 0437c3b

Browse files
authored
Fix code-formatting workflow (AliceO2Group#4553)
* code-formatting workflow: get the correct commit to compare against * code-formatting workflow: adapt line-length detection "git diff $x" doesn't do anything as there are no unstaged changes. We need to tell it what to compare against. The header is also 4 or 5 lines long, depending on whether a file is completely new or not. If we chop 5 lines off, it'll always catch the +++ line and may chop the first @@ line too, which we don't care about.
1 parent 13c008b commit 0437c3b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

.github/workflows/code-formatting.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ jobs:
2626
git config --global user.name "ALICE Action Bot"
2727
git checkout -b alibot-cleanup-${{ github.event.pull_request.number }} ${{ github.event.pull_request.head.sha }}
2828
29-
BASE_COMMIT=${{ github.event.pull_request.base.sha }}
29+
# github.event.pull_request.base.sha is the latest commit on the branch
30+
# the PR will be merged into, NOT the commit this PR derives from! For
31+
# that, we need to find the latest common ancestor between the PR and
32+
# the branch we are merging into.
33+
BASE_COMMIT=$(git merge-base HEAD ${{ github.event.pull_request.base.sha }})
3034
echo "Running clang-format-8 against branch ${{ github.event.pull_request.base.ref }} , with hash ${{ github.event.pull_request.base.sha }}"
3135
COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -ivE 'LinkDef|Utilities/PCG/')
3236
RESULT_OUTPUT="$(git-clang-format-8 --commit $BASE_COMMIT --diff --binary `which clang-format-8` $COMMIT_FILES)"
@@ -41,7 +45,7 @@ jobs:
4145
# to avoid extra work.
4246
# 120 characters are allowed, meaning the error should start with 122,
4347
# to allow for the starting + at the end of the line.
44-
git diff $x | tail -n +5 | grep -e '^+' | grep '.\{122,\}' && { echo "Line longer than 120 chars in $x." && exit 1; } || true ;;
48+
git diff $BASE_COMMIT $x | tail -n +6 | grep -e '^+' | grep '.\{122,\}' && { echo "Line longer than 120 chars in $x." && exit 1; } || true ;;
4549
*.hxx|*.cc|*.hpp) echo "$x uses non-allowed extension." && exit 1 ;;
4650
*) ;;
4751
esac

0 commit comments

Comments
 (0)