|
1 | | -name: Check PR with clang-format |
| 1 | +--- |
| 2 | +name: Formatting |
2 | 3 |
|
3 | | -on: [pull_request_target] |
| 4 | +'on': [pull_request_target] |
4 | 5 |
|
5 | 6 | jobs: |
6 | | - build: |
7 | | - # We need at least 20.04 to install clang-format-11. |
8 | | - runs-on: ubuntu-20.04 |
9 | | - |
10 | | - steps: |
11 | | - - uses: actions/checkout@v2 |
12 | | - with: |
13 | | - ref: ${{ github.event.pull_request.head.sha }} |
14 | | - persist-credentials: false |
15 | | - # We need the history of the dev branch all the way back to where the PR |
16 | | - # diverged. We're fetching everything here, as we don't know how many |
17 | | - # commits back that point is. |
18 | | - fetch-depth: 0 |
19 | | - |
20 | | - - name: Install prerequisites |
21 | | - env: |
22 | | - DEBIAN_FRONTEND: noninteractive |
23 | | - run: | |
24 | | - sudo apt update -y |
25 | | - sudo apt install -y clang-format-11 |
26 | | - sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100 |
27 | | - sudo update-alternatives --install /usr/bin/git-clang-format git-clang-format /usr/bin/git-clang-format-11 100 |
28 | | -
|
29 | | - - name: Run clang format |
30 | | - id: clang_format |
31 | | - env: |
32 | | - ALIBUILD_GITHUB_TOKEN: ${{secrets.ALIBUILD_GITHUB_TOKEN}} |
33 | | - run: | |
34 | | - set -x |
35 | | - # We need to fetch the other commit. |
36 | | - git fetch origin ${{ github.event.pull_request.base.ref }} \ |
37 | | - pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }} |
38 | | -
|
39 | | - # We create a new branch which we will use for the eventual PR. |
40 | | - git config --global user.email "alibuild@cern.ch" |
41 | | - git config --global user.name "ALICE Action Bot" |
42 | | - git checkout -b alibot-cleanup-${{ github.event.pull_request.number }} ${{ github.event.pull_request.head.sha }} |
43 | | -
|
44 | | - # github.event.pull_request.base.sha is the latest commit on the branch |
45 | | - # the PR will be merged into, NOT the commit this PR derives from! For |
46 | | - # that, we need to find the latest common ancestor between the PR and |
47 | | - # the branch we are merging into. |
48 | | - BASE_COMMIT=$(git merge-base HEAD ${{ github.event.pull_request.base.sha }}) |
49 | | - echo "Running clang-format against branch ${{ github.event.pull_request.base.ref }}, with hash ${{ github.event.pull_request.base.sha }}" |
50 | | - COMMIT_FILES=$(git diff --diff-filter d --name-only $BASE_COMMIT | grep -ivE 'LinkDef|Utilities/PCG/') |
51 | | - [ "X$COMMIT_FILES" = X ] && { echo "No files to check" ; exit 0; } |
52 | | - RESULT_OUTPUT="$(git-clang-format --commit $BASE_COMMIT --diff --style file $COMMIT_FILES)" |
53 | | -
|
54 | | - for x in $COMMIT_FILES; do |
55 | | - case $x in |
56 | | - *.hxx|*.cc|*.hpp) echo "$x uses non-allowed extension." && exit 1 ;; |
57 | | - *) ;; |
58 | | - esac |
59 | | - done |
60 | | -
|
61 | | - if [ "$RESULT_OUTPUT" == 'no modified files to format' ] || |
62 | | - [ "$RESULT_OUTPUT" == 'clang-format did not modify any files' ] |
63 | | - then |
64 | | - echo "clang-format passed." |
65 | | - git push --set-upstream https://alibuild:$ALIBUILD_GITHUB_TOKEN@github.com/alibuild/AliceO2.git :alibot-cleanup-${{ github.event.pull_request.number }} -f || true |
66 | | - echo ::set-output name=clean::true |
67 | | - else |
68 | | - git-clang-format --diff --commit $BASE_COMMIT --style file $COMMIT_FILES | |
69 | | - patch -p1 |
70 | | - echo "clang-format failed." |
71 | | - echo "To reproduce it locally please run" |
72 | | - echo -e "\tgit checkout ${{ github.event.pull_request.head.ref }}" |
73 | | - echo -e "\tgit-clang-format --commit $BASE_COMMIT --diff --style file" |
74 | | - echo "Note: using clang-format version $(clang-format --version)" |
75 | | - echo "Opening a PR to your branch with the fixes" |
76 | | - git commit -m "Please consider the following formatting changes" -a |
77 | | - git show | cat |
78 | | - git fetch https://github.com/AliceO2Group/AliceO2.git pull/${{ github.event.pull_request.number }}/head |
79 | | - 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 |
80 | | - echo ::set-output name=clean::false |
81 | | - fi |
82 | | -
|
83 | | - - name: pull-request |
84 | | - uses: alisw/pull-request@master |
85 | | - with: |
86 | | - source_branch: 'alibuild:alibot-cleanup-${{ github.event.pull_request.number }}' |
87 | | - destination_branch: '${{ github.event.pull_request.head.label }}' |
88 | | - github_token: ${{ secrets.ALIBUILD_GITHUB_TOKEN }} |
89 | | - pr_title: "Please consider the following formatting changes to #${{ github.event.pull_request.number }}" |
90 | | - pr_body: | |
91 | | - 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. |
92 | | - You can find AliceO2 coding conventions at http://github.com/AliceO2Group/CodingGuidelines. |
93 | | - continue-on-error: true # We do not create PRs if the branch is not there. |
94 | | - |
95 | | - - name: Exit with error if the PR is not clean |
96 | | - run: | |
97 | | - case ${{ steps.clang_format.outputs.clean }} in |
98 | | - true) echo "PR clean" ; exit 0 ;; |
99 | | - false) echo "PR not clean" ; exit 1 ;; |
100 | | - esac |
| 7 | + formatting: |
| 8 | + name: PR formatting |
| 9 | + uses: alisw/ali-bot/.github/workflows/c++-code-formatting.yml@master |
| 10 | + secrets: |
| 11 | + alibuild_github_token: ${{ secrets.ALIBUILD_GITHUB_TOKEN }} |
0 commit comments