diff --git a/.github/workflows/auto-format.yml b/.github/workflows/auto-format.yml new file mode 100644 index 0000000..03ad811 --- /dev/null +++ b/.github/workflows/auto-format.yml @@ -0,0 +1,38 @@ +# automatically format code using clang-format when a pull request is merged or manually triggered +name: format-code + +on: + pull_request: + types: [closed] # on merge pull request + workflow_dispatch: # allows manual triggering + +permissions: + contents: write + +jobs: + format: + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Format code # Outputs the correctly formatted code + uses: DoozyX/clang-format-lint-action@v0.18 + with: + source: './src/lemlib ./include/lemlib' + extensions: 'hpp,cpp' + clangFormatVersion: 18 + inplace: true # Same as `clang-format -i` + + # Commits the correctly formatted files to the repository + - name: Commit changes + uses: EndBug/add-and-commit@v9 + with: + author_name: GitHub Action + author_email: action@github.com + message: Automated code formatting + push: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file