Skip to content

Commit

Permalink
ci: add auto format
Browse files Browse the repository at this point in the history
  • Loading branch information
Khady committed Oct 19, 2024
1 parent 4933105 commit e8c6ede
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ on:
- pull_request

jobs:
lint-fmt:
# auto fix formatting, Thanks to robur.coop for the implementation
# https://discuss.ocaml.org/t/ocamlformat-and-github-actions/15464
lint-auto-fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -18,8 +20,25 @@ jobs:
dune-cache: true
allow-prerelease-opam: true

- name: Lint fmt
uses: ocaml/setup-ocaml/lint-fmt@v3
- 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 "[email protected]"
git add -A
git commit -m "formatted code"
git push
lint-opam:
runs-on: ubuntu-latest
Expand Down

2 comments on commit e8c6ede

@hannesm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you need "grep ^version .ocamlformat", since in your .ocamlformat you also have some ocaml-version...

@Khady
Copy link
Collaborator Author

@Khady Khady commented on e8c6ede Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that’s indeed the fix!

Please sign in to comment.