diff --git a/native/.clang-format-ignore b/native/.clang-format-ignore new file mode 100644 index 0000000000..922b6065c5 --- /dev/null +++ b/native/.clang-format-ignore @@ -0,0 +1,2 @@ +# ignore third_party code from clang-format checks +./cocos/bindings/auto/* diff --git a/native/.github/workflows/clang-format.yml b/native/.github/workflows/clang-format.yml index c7bb86e731..013285edb4 100644 --- a/native/.github/workflows/clang-format.yml +++ b/native/.github/workflows/clang-format.yml @@ -2,29 +2,38 @@ name: Apply Clang Format #on: [push, pull_request] on: - pull_request: + pull_request_target: types: [closed] jobs: Clang-Format: - if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true + if: github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: - token: ${{secrets.GITHUB_TOKEN }} + token: ${{ github.token }} ref: ${{ github.head_ref }} - - name: install clang-format + - id: get_change_files + uses: fish9167/file-changes-action@v1.2.3 + with: + output: ' ' + fileOutput: ' ' + + - name: get change files run: | - sudo apt-get install clang-format git - - - name: apply clang-format - run: | - SRC=$(git ls-tree --full-tree -r HEAD | grep -e "\.\(c\|h\|hpp\|cpp\|cxx\)\$" | cut -f 2) - clang-format -style=file -i $SRC + cat $HOME/files.txt + mv $HOME/files.txt ${{github.workspace}}/files.txt + - uses: fish9167/clang-format-lint-action@master + with: + exclude: .clang-format-ignore + extensions: 'c,h,hpp,cpp,cxx' + style: file + inplace: True + - uses: fish9167/git-auto-commit-action@v4 with: commit_message: Apply clang-format @@ -32,3 +41,4 @@ jobs: commit_user_email: cocos-robot@cocos.com commit_author: cocos-robot push_options: --force +