name: Format

on:
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}

      - name: Set up OCaml
        uses: avsm/setup-ocaml@v1
        with:
          # Version of the OCaml compiler to initialise
          ocaml-version: 4.11.1
          
      - name: install dependencies
        run: opam install ocamlformat.0.16.0 dune
        
      - name: format
        run: |
          opam exec -- dune build @fmt --auto-promote || true
          
      - name: commit
        uses: stefanzweifel/git-auto-commit-action@v4.11.0
        with:
          commit_message: Apply formatting changes
          branch: ${{ github.head_ref }}
