forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (78 loc) · 4.09 KB
/
code-formatting.yml
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
name: Create a PR with clang-format changes
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
# - name: Install clang format
# run: |
# sudo apt install -y clang-format-8
- name: Run clang format
id: clang_format
run: |
set -x
# We need to fetch the other commit.
git fetch --depth=1 origin ${{ github.event.pull_request.base.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 }}
BASE_COMMIT=${{ 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)"
git-clang-format-8 --commit $BASE_COMMIT --diff --binary `which clang-format-8` $COMMIT_FILES | patch -p1
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.
git diff $x | tail -n +5 | 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 origin :alibot-cleanup-${{ github.event.pull_request.number }} -f || true
echo ::set-output name=clean::true
else
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 push --set-upstream origin HEAD:refs/heads/alibot-cleanup-${{ github.event.pull_request.number }} -f
echo ::set-output name=clean::false
fi
- name: pull-request
uses: ktf/pull-request@master
with:
source_branch: 'ktf:alibot-cleanup-${{ github.event.pull_request.number }}'
destination_branch: '${{ github.event.pull_request.user.login }}:${{ github.event.pull_request.head.ref }}'
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_title: "Please consider the following formatting changes to #${{ github.event.pull_request.number }}"
pr_body: "Please consider the following formatting changes"
continue-on-error: true # We do not create PRs if the branch is not there.
# - name: Create Pull Request
# uses: peter-evans/create-pull-request@v3
# with:
# base: "${{ github.event.pull_request.head.ref }}"
# branch: "alibot-cleanup-${{ github.event.pull_request.number}}"
- 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