From 3609b213f6e9065cd76b17abf9c22af856df38b2 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Fri, 19 Jul 2024 10:38:39 +0200 Subject: [PATCH] Use ormolu from stackage in the CI (#2900) 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 --- .github/workflows/ci.yml | 38 +++++++++++++------ Makefile | 10 +---- justfile | 12 ++++-- .../FromParsed/Analysis/Scoping.hs | 4 +- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f221d50b87..721dc5afe2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Makefile b/Makefile index 4912bdfd53..87e1a562c0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/justfile b/justfile index c8f2bba6df..cf20c2ce80 100644 --- a/justfile +++ b/justfile @@ -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: @@ -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 }}" diff --git a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs index 6e94de77ad..38a81039b2 100644 --- a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs +++ b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs @@ -1563,8 +1563,8 @@ checkSections sec = topBindings helper failMaybe $ mkRec ^? constructorRhs - . _ConstructorRhsRecord - . to mkRecordNameSignature + . _ConstructorRhsRecord + . to mkRecordNameSignature let info = RecordInfo { _recordInfoSignature = fs,