From 85c8b7a661e503f974e311d4ae5a06b68a1ad50b Mon Sep 17 00:00:00 2001 From: Pierre Alain Date: Wed, 12 Mar 2025 11:57:13 +0100 Subject: [PATCH] add ocamlformat and autoformat in github action --- .github/workflows/format.yml | 45 ++++++++++++++++++++++++++++++++++++ .ocamlformat | 3 +++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/format.yml create mode 100644 .ocamlformat diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..f5ebd58 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,45 @@ +name: ocamlformat + +on: [pull_request] + +jobs: + format: + name: ocamlformat + + strategy: + fail-fast: false + matrix: + ocaml-version: ["4.14.2"] + operating-system: [ubuntu-latest] + + runs-on: ${{ matrix.operating-system }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - name: Use OCaml ${{ matrix.ocaml-version }} + uses: ocaml/setup-ocaml@v3 + with: + ocaml-compiler: ${{ matrix.ocaml-version }} + + - name: Install ocamlformat + run: grep ^version .ocamlformat | cut -d '=' -f 2 | xargs -I V opam install ocamlformat=V + + - 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 diff --git a/.ocamlformat b/.ocamlformat new file mode 100644 index 0000000..d6d9647 --- /dev/null +++ b/.ocamlformat @@ -0,0 +1,3 @@ +version = 0.27.0 +profile = conventional +parse-docstrings = true