| 1 | name: code-format |
| 2 | |
| 3 | on: [push, pull_request, pull_request_target] |
| 4 | |
| 5 | concurrency: |
| 6 | group: code-format-${{ github.ref }} |
| 7 | cancel-in-progress: true |
| 8 | |
| 9 | permissions: |
| 10 | contents: read |
| 11 | |
| 12 | jobs: |
| 13 | code-format: |
| 14 | permissions: |
| 15 | contents: write # for stefanzweifel/git-auto-commit-action to push code in repo |
| 16 | runs-on: ubuntu-20.04 |
| 17 | steps: |
| 18 | - uses: actions/checkout@v4 |
| 19 | |
| 20 | - name: cache-clang-format |
| 21 | id: cache-clang-format |
| 22 | uses: actions/cache@v4 |
| 23 | with: |
| 24 | path: clang-format-install |
| 25 | key: clang-format-install-4 |
| 26 | - name: clang-format |
| 27 | if: steps.cache-clang-format.outputs.cache-hit != 'true' |
| 28 | run: | |
| 29 | wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/llvm-project-10.0.1.tar.xz |
| 30 | tar -xf llvm-project-10.0.1.tar.xz |
| 31 | cd llvm-project-10.0.1 |
| 32 | mkdir build |
| 33 | cd build |
| 34 | cmake -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_TARGETS_TO_BUILD="" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_DOCS=OFF ../llvm/ |
| 35 | make -j2 clang-format |
| 36 | mkdir $GITHUB_WORKSPACE/clang-format-install |
| 37 | cp -r bin/clang-format $GITHUB_WORKSPACE/clang-format-install |
| 38 | cd ../../ |
| 39 | rm -rf llvm-project-10.0.1 |
| 40 | rm llvm-project-10.0.1.tar.xz |
| 41 | |
| 42 | - name: astyle |
| 43 | run: | |
| 44 | sudo apt-get update |
| 45 | sudo apt-get install -y astyle |
| 46 | |
| 47 | - name: code-format |
| 48 | run: | |
| 49 | mkdir -p ~/bin |
| 50 | mv $GITHUB_WORKSPACE/clang-format-install/clang-format ~/bin/clang-format |
| 51 | rm -rf $GITHUB_WORKSPACE/clang-format-install |
| 52 | export PATH=~/bin:$PATH |
| 53 | sh codeformat.sh |
| 54 | - uses: stefanzweifel/git-auto-commit-action@v5 |
| 55 | with: |
| 56 | commit_message: apply code-format changes |
| 57 | |
| 58 | - name: restore-clang-format-cache |
| 59 | run: | |
| 60 | mkdir $GITHUB_WORKSPACE/clang-format-install |
| 61 | cp -r ~/bin/clang-format $GITHUB_WORKSPACE/clang-format-install |