Skip to content

Commit

Permalink
Fixing clang-format style
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqwang committed Nov 1, 2021
1 parent 02812f1 commit 79229b5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 44 deletions.
88 changes: 46 additions & 42 deletions .github/workflows/code-format.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
name: code-format
name: Code format

on: [push, pull_request, pull_request_target]
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
code-format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: cache-clang-format
id: cache-clang-format
uses: actions/[email protected]
with:
path: clang-format-install
key: clang-format-install-4
- name: clang-format
if: steps.cache-clang-format.outputs.cache-hit != 'true'
run: |
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/llvm-project-10.0.1.tar.xz
tar -xf llvm-project-10.0.1.tar.xz
cd llvm-project-10.0.1
mkdir build
cd build
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/
make -j2 clang-format
mkdir $GITHUB_WORKSPACE/clang-format-install
cp -r bin/clang-format $GITHUB_WORKSPACE/clang-format-install
cd ../../
rm -rf llvm-project-10.0.1
rm llvm-project-10.0.1.tar.xz
- name: Cache clang format
id: cache-clang-format
uses: actions/[email protected]
with:
path: clang-format-install
key: clang-format-install-4
- name: Install clang format
if: steps.cache-clang-format.outputs.cache-hit != 'true'
run: |
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/llvm-project-10.0.1.tar.xz
tar -xf llvm-project-10.0.1.tar.xz
cd llvm-project-10.0.1
mkdir build
cd build
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/
make -j2 clang-format
mkdir $GITHUB_WORKSPACE/clang-format-install
cp -r bin/clang-format $GITHUB_WORKSPACE/clang-format-install
cd ../../
rm -rf llvm-project-10.0.1
rm llvm-project-10.0.1.tar.xz
- name: astyle
run: |
sudo apt-get update
sudo apt-get install -y astyle
- name: Install astyle
run: |
sudo apt-get update
sudo apt-get install -y astyle
- name: code-format
run: |
mkdir -p ~/bin
mv $GITHUB_WORKSPACE/clang-format-install/clang-format ~/bin/clang-format
rm -rf $GITHUB_WORKSPACE/clang-format-install
export PATH=~/bin:$PATH
sh codeformat.sh
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply code-format changes
- name: code-format
run: |
mkdir -p ~/bin
mv $GITHUB_WORKSPACE/clang-format-install/clang-format ~/bin/clang-format
rm -rf $GITHUB_WORKSPACE/clang-format-install
export PATH=~/bin:$PATH
sh codeformat.sh
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply code-format changes

- name: restore-clang-format-cache
run: |
mkdir $GITHUB_WORKSPACE/clang-format-install
cp -r ~/bin/clang-format $GITHUB_WORKSPACE/clang-format-install
- name: Restore clang-format cache
run: |
mkdir $GITHUB_WORKSPACE/clang-format-install
cp -r ~/bin/clang-format $GITHUB_WORKSPACE/clang-format-install
4 changes: 2 additions & 2 deletions codeformat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# we run clang-format and astyle twice to get stable format output

find deployment/ tools/ test/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' | xargs -i clang-format -i {}
find deployment/ tools/ test/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' | xargs -i clang-format -style=file -i {}
astyle -n -r "test/*.h,*.cpp,*.cc" "tools/*.h,*.cpp,*.cc"
astyle -n -r "deployment/*.h,*.cpp,*.cc"

find deployment/ tools/ test/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' | xargs -i clang-format -i {}
find deployment/ tools/ test/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' | xargs -i clang-format -style=file -i {}
astyle -n -r "test/*.h,*.cpp,*.cc" "tools/*.h,*.cpp,*.cc"
astyle -n -r "deployment/*.h,*.cpp,*.cc"

0 comments on commit 79229b5

Please sign in to comment.