Skip to content

Commit

Permalink
Use ormolu from stackage in the CI (#2900)
Browse files Browse the repository at this point in the history
1. Adds the command `just format check`, which checks that all Haskell
files are formatted.
2. In CI, we use install ormolu from stackage and run it. This will
facilitate consistency between CI and local setups.

---------

Co-authored-by: Paul Cadman <[email protected]>
  • Loading branch information
janmasrovira and paulcadman authored Jul 19, 2024
1 parent 83837b9 commit 3609b21
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
38 changes: 27 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,36 @@ jobs:

ormolu:
runs-on: ubuntu-latest
env:
STACK_RESOLVER: lts-21.25
steps:
- uses: actions/checkout@v3
- uses: mrkkrp/ormolu-action@v11
- uses: extractions/setup-just@v2

- name: Install hpack
run: sudo apt install -y hpack

- name: Generate juvix.cabal
run: hpack

- name: Cache ormolu
id: ormolu-cache
uses: actions/cache@v3
with:
version: 0.5.3.0
extra-args: >-
--ghc-opt -XDerivingStrategies
--ghc-opt -XImportQualifiedPost
--ghc-opt -XMultiParamTypeClasses
--ghc-opt -XPatternSynonyms
--ghc-opt -XStandaloneDeriving
--ghc-opt -XTemplateHaskell
--ghc-opt -XUnicodeSyntax
--ghc-opt -XBangPatterns
path: |
~/.local/bin/ormolu
key: ${{ runner.os }}-ormolu-${{ env.STACK_RESOLVER }}

- name: Install ormolu
if: steps.ormolu-cache.outputs.cache-hit != 'true'
run: stack install ormolu --resolver=${{ env.STACK_RESOLVER }}

- name: Run ormolu
run: just format check

- name: Report formatting error
if: failure()
run: echo "Some Haskell files are not formatted. Please run 'just format'"

build-and-test-linux:
runs-on: ubuntu-22.04
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,7 @@ ORMOLUMODE?=inplace
.PHONY: ormolu
ormolu:
@${ORMOLU} ${ORMOLUFLAGS} \
--ghc-opt -XStandaloneDeriving \
--ghc-opt -XUnicodeSyntax \
--ghc-opt -XDerivingStrategies \
--ghc-opt -XPatternSynonyms \
--ghc-opt -XMultiParamTypeClasses \
--ghc-opt -XTemplateHaskell \
--ghc-opt -XImportQualifiedPost \
--ghc-opt -XBangPatterns \
--mode ${ORMOLUMODE} \
--mode ${ORMOLUMODE} \
$(ORMOLUFILES)

.PHONY: format
Expand Down
12 changes: 8 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ bashDebugArg := if enableDebug == '' { '' } else { 'x' }
default:
@just --list

@_ormoluCmd filesCmd:
@_ormoluCmd filesCmd mode:
{{ trim(filesCmd) }} \
| xargs -r {{ ormolu }} --mode inplace
| xargs -r {{ ormolu }} --mode {{ mode }}

# Formats all Haskell files in the project. `format changed` formats only changed files. `format FILES` formats individual files.
format *opts:
Expand All @@ -74,11 +74,15 @@ format *opts:

case $opts in
"")
just _ormoluCmd "git ls-files '*.hs'"
just _ormoluCmd "git ls-files '*.hs'" inplace
;;
changed)
just _ormoluCmd \
"(git --no-pager diff --name-only --diff-filter=AM && git --no-pager diff --cached --name-only --diff-filter=AM) | grep '\\.hs\$'"
"(git --no-pager diff --name-only --diff-filter=AM && git --no-pager diff --cached --name-only --diff-filter=AM) | grep '\\.hs\$'" \
inplace
;;
check)
just _ormoluCmd "git ls-files '*.hs'" check
;;
*)
just _ormoluCmd "echo {{ opts }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,8 @@ checkSections sec = topBindings helper
failMaybe $
mkRec
^? constructorRhs
. _ConstructorRhsRecord
. to mkRecordNameSignature
. _ConstructorRhsRecord
. to mkRecordNameSignature
let info =
RecordInfo
{ _recordInfoSignature = fs,
Expand Down

0 comments on commit 3609b21

Please sign in to comment.