From 421f6fe7cd412002778f7dbe1b9bf6625342e0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20Roch=C3=A9?= Date: Sat, 19 Oct 2024 20:44:14 +0800 Subject: [PATCH] add ocamlformat auto fix in CI https://discuss.ocaml.org/t/ocamlformat-and-github-actions/15464 --- .github/workflows/lint.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 41523a6..6d7523b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,6 +21,23 @@ jobs: - name: Lint fmt uses: ocaml/setup-ocaml/lint-fmt@v3 + - name: Format code + run: | + git ls-files '*.ml' '*.mli' | xargs opam exec -- ocamlformat --inplace + + - name: Check for modified files + id: git-check + run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT + + - name: Commit and push changes + if: ${{ steps.git-check.outputs.modified == 'true' }} + run: | + git config --global user.name "Automated ocamlformat GitHub action, developed by robur.coop" + git config --global user.email "autoformat@robur.coop" + git add -A + git commit -m "formatted code" + git push + lint-opam: runs-on: ubuntu-latest steps: