forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 1
97 lines (88 loc) · 5.13 KB
/
code-formatting.yml
File metadata and controls
97 lines (88 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Check PR with clang-format
on: [pull_request_target]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
# We need the history of the dev branch all the way back to where the PR
# diverged. We're fetching everything here, as we don't know how many
# commits back that point is.
fetch-depth: 0
- name: Run clang format
id: clang_format
env:
ALIBUILD_GITHUB_TOKEN: ${{secrets.ALIBUILD_GITHUB_TOKEN}}
run: |
set -x
# We need to fetch the other commit.
git fetch origin ${{ github.event.pull_request.base.ref }}
git fetch origin pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }}
# We create a new branch which we will use for the eventual PR.
git config --global user.email "alibuild@cern.ch"
git config --global user.name "ALICE Action Bot"
git checkout -b alibot-cleanup-${{ github.event.pull_request.number }} ${{ github.event.pull_request.head.sha }}
# github.event.pull_request.base.sha is the latest commit on the branch
# the PR will be merged into, NOT the commit this PR derives from! For
# that, we need to find the latest common ancestor between the PR and
# the branch we are merging into.
BASE_COMMIT=$(git merge-base HEAD ${{ github.event.pull_request.base.sha }})
echo "Running clang-format-8 against branch ${{ github.event.pull_request.base.ref }} , with hash ${{ github.event.pull_request.base.sha }}"
COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -ivE 'LinkDef|Utilities/PCG/')
RESULT_OUTPUT="$(git-clang-format-8 --commit $BASE_COMMIT --diff --binary `which clang-format-8` $COMMIT_FILES)"
for x in $COMMIT_FILES; do
case $x in
# *.h|*.cxx)
# We remove the header from the diff as it contains +++ then
# we only select the added lines to check for the long ones.
# We do not need to check for the lines which have been removed
# and we do not want to check for the lines which were not changed
# to avoid extra work.
# 120 characters are allowed, meaning the error should start with 122,
# to allow for the starting + at the end of the line.
# Disabled for now, since people don't like the convention.
# git diff $BASE_COMMIT $x | tail -n +6 | grep -e '^+' | grep '.\{122,\}' && { echo "Line longer than 120 chars in $x." && exit 1; } || true ;;
*.hxx|*.cc|*.hpp) echo "$x uses non-allowed extension." && exit 1 ;;
*) ;;
esac
done
if [ "$RESULT_OUTPUT" == "no modified files to format" ] \
|| [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ] ; then
echo "clang-format passed."
git push --set-upstream https://alibuild:$ALIBUILD_GITHUB_TOKEN@github.com/alibuild/AliceO2.git :alibot-cleanup-${{ github.event.pull_request.number }} -f || true
echo ::set-output name=clean::true
else
git-clang-format-8 --commit $BASE_COMMIT \
--diff --binary `which \
clang-format-8` $COMMIT_FILES | patch -p1
echo "clang-format failed."
echo "To reproduce it locally please run"
echo -e "\tgit checkout $TRAVIS_BRANCH"
echo -e "\tgit-clang-format --commit $BASE_COMMIT --diff --binary $(which clang-format)"
echo "Opening a PR to your branch with the fixes"
git commit -m "Please consider the following formatting changes" -a
git show | cat
git fetch https://github.com/AliceO2Group/AliceO2.git pull/${{ github.event.pull_request.number }}/head
git push --set-upstream https://alibuild:$ALIBUILD_GITHUB_TOKEN@github.com/alibuild/AliceO2.git HEAD:refs/heads/alibot-cleanup-${{ github.event.pull_request.number }} -f
echo ::set-output name=clean::false
fi
- name: pull-request
uses: alisw/pull-request@master
with:
source_branch: 'alibuild:alibot-cleanup-${{ github.event.pull_request.number }}'
destination_branch: '${{ github.event.pull_request.user.login }}:${{ github.event.pull_request.head.ref }}'
github_token: ${{ secrets.ALIBUILD_GITHUB_TOKEN }}
pr_title: "Please consider the following formatting changes to #${{ github.event.pull_request.number }}"
pr_body: |
This PR cannot be merged as is. You should either run clang-format yourself and update the pull request, or merge this PR in yours.
You can find AliceO2 coding conventions at http://github.com/AliceO2Group/CodingGuidelines.
continue-on-error: true # We do not create PRs if the branch is not there.
- name: Exit with error if the PR is not clean
run: |
case ${{ steps.clang_format.outputs.clean }} in
true) echo "PR clean" ; exit 0 ;;
false) echo "PR not clean" ; exit 1 ;;
esac