Skip to content

Commit

Permalink
Add a CI check for code formatting (#151)
Browse files Browse the repository at this point in the history
This PR adds a GitHub action (🎉) that checks for the latest refmt syntax.

This is done thanks to @thomsj which brought up the problems with formatting in the repo! 👏 #105 (comment)

The current implementation is not ideal: it installs esy and then installs OCaml and @esy-ocaml/reason. A better way to do it is to distribute refmt as a standalone binary from the latest Reason release. This will be fast to install and therefore fast to integrate with CI.

An approach to do so is to add an artifact to the CircleCI runs, and then use something like circleci-artifacts.now.sh to fetch the artifact, extract it and profit 💰

In the meantime, it takes <4m to run it, which is much faster than the Azure Linux build, not to mention the Windows one.
  • Loading branch information
Schniz authored Oct 8, 2019
1 parent 65c6d56 commit c5048fc
Show file tree
Hide file tree
Showing 27 changed files with 1,836 additions and 6 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/refmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Check formatting
on: [push]

# consider using docker: ocaml/opam2:4.06
# - sudo apt-get update && apt-get install -y m4
# - opam update && opam install reason
# - refmt # is new

jobs:
# build:
# name: build project
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@master
# with:
# fetch-depth: 1
# - uses: actions/setup-node@v1
# with:
# node-version: '10.x'
# - run: npm install -g esy@latest
# - run: esy i
# - run: esy b
# - run: esy export-dependencies
# - run: tar -czf build.tar.gz _export
# - uses: actions/upload-artifact@master
# with:
# name: cache-linux-build-dependencies
# path: build.tar.gz

test_refmt:
name: run refmt
runs-on: ubuntu-latest
# needs: [build]
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- uses: actions/setup-node@v1
with:
node-version: '10.x'
# - run: npm install -g esy@latest
# - uses: actions/download-artifact@master
# with:
# name: cache-linux-build-dependencies
# - run: tar -xzf cache-linux-build-dependencies/build.tar.gz
# - run: esy import-build _export/*
# - run: esy i
# - run: esy fmt
- run: npm i -g esy@latest
- run: esy @fmt i
- run: esy @fmt refmt --in-place */*.re
# - run: ./scripts/fmt_all.sh
# name: refmt all the files
- run: |
if [ -n "$(git status --porcelain)" ]; then
echo "There are differences:"
git status --porcelain
echo "----"
echo ""
echo 'Please run `esy fmt` locally to fix the issues.'
exit 1
fi
name: "Throw if something changed"
3 changes: 3 additions & 0 deletions fmt.esy.lock/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Set eol to LF so files aren't converted to CRLF-eol on Windows.
* text eol=lf
3 changes: 3 additions & 0 deletions fmt.esy.lock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Reset any possible .gitignore, we want all esy.lock to be un-ignored.
!*
Loading

0 comments on commit c5048fc

Please sign in to comment.