Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Fourmolu as formatter #582

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Stylish Haskell
name: Check Fourmolu

on:
merge_group:
Expand All @@ -19,64 +19,55 @@ concurrency:
cancel-in-progress: true

jobs:
check-stylish-haskell:
check-fourmolu:
runs-on: ubuntu-latest

strategy:
fail-fast: false

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2023-07-12"

STYLISH_HASKELL_VERSION: "0.14.4.0"

STYLISH_HASKELL_PATHS: >
cardano-api
FOURMOLU_VERSION: "0.16.2.0"

steps:
- name: Download stylish-haskell
- name: Download Fourmolu
run: |
version="${{ env.STYLISH_HASKELL_VERSION }}"

fourmolu_path="$(mktemp -d)"
version="${{env.FOURMOLU_VERSION}}"
curl -sL \
"https://github.com/haskell/stylish-haskell/releases/download/v$version/stylish-haskell-v$version-linux-x86_64.tar.gz" \
| tar -C "/tmp" -xz

echo "PATH=/tmp/stylish-haskell-v$version-linux-x86_64:$PATH" >> "$GITHUB_ENV"
"https://github.com/fourmolu/fourmolu/releases/download/v$version/fourmolu-$version-linux-x86_64" > "$fourmolu_path/fourmolu"
echo "PATH=$fourmolu_path:$PATH" >> "$GITHUB_ENV"
chmod u+rwx "$fourmolu_path/fourmolu"

- uses: actions/checkout@v3

- name: Run stylish-haskell over all Haskell files (always succeeds)
- name: Run Fourmolu over all Haskell files (always succeeds)
run: |
git add .
git stash

for x in $(git ls-tree --full-tree --name-only -r HEAD ${{ env.STYLISH_HASKELL_PATHS }}); do
for x in $(git ls-tree --full-tree --name-only -r HEAD); do
if [ "${x##*.}" == "hs" ]; then
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
stylish-haskell -i "$x"
fourmolu -q -i "$x"
fi
fi
done

git --no-pager diff

- name: Run stylish-haskell over all modified files
- name: Run Fourmolu over all modified files
run: |
git add .
git stash
git fetch origin ${{ github.base_ref }} --unshallow
for x in $(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }}..HEAD ${{ env.STYLISH_HASKELL_PATHS }}); do
for x in $(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }}..HEAD); do
if [ "${x##*.}" == "hs" ]; then
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
stylish-haskell -i "$x"
fourmolu -q -i "$x"
fi
fi
done

git --no-pager diff --exit-code

114 changes: 0 additions & 114 deletions .stylish-haskell.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion cardano-api-gen/src/Test/Gen/Cardano/Api/Empty.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Test.Gen.Cardano.Api.Empty where

import Test.Gen.Cardano.Api ()
import Test.Gen.Cardano.Api ()

-- | This module is empty, but it is needed to prevent unused-packages warning
57 changes: 29 additions & 28 deletions cardano-api/gen/Test/Gen/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
module Test.Gen.Cardano.Api
( genMetadata
, genAlonzoGenesis
) where
)
where

import qualified Cardano.Ledger.Alonzo.Core as Ledger
import qualified Cardano.Ledger.Alonzo.Genesis as Alonzo
Expand All @@ -15,21 +16,18 @@ import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Coin as Ledger
import qualified Cardano.Ledger.Plutus.CostModels as Plutus
import qualified Cardano.Ledger.Plutus.Language as Alonzo
import Cardano.Ledger.Shelley.TxAuxData (Metadatum (..), ShelleyTxAuxData (..))

import Cardano.Ledger.Shelley.TxAuxData (Metadatum (..), ShelleyTxAuxData (..))
import qualified Data.Map.Strict as Map
import Data.Word (Word64)

import Test.Gen.Cardano.Api.Typed (genCostModel, genRational)

import Hedgehog (Gen, Range)
import Data.Word (Word64)
import Hedgehog (Gen, Range)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Internal.Range as Range
import Test.Gen.Cardano.Api.Typed (genCostModel, genRational)

genMetadata :: Ledger.Era era => Gen (ShelleyTxAuxData era)
genMetadata = do
numberOfIndices <- Gen.integral (Range.linear 1 15)
let indices = map (\i -> fromIntegral i :: Word64) [1..numberOfIndices]
let indices = map (\i -> fromIntegral i :: Word64) [1 .. numberOfIndices]
mData <- Gen.list (Range.singleton numberOfIndices) genMetadatum
return . ShelleyTxAuxData . Map.fromList $ zip indices mData

Expand Down Expand Up @@ -63,22 +61,24 @@ genPrice = do

genPrices :: Gen Alonzo.Prices
genPrices = do
prMem' <- genPrice
prMem' <- genPrice
prSteps' <- genPrice

return Alonzo.Prices
{ Alonzo.prMem = prMem'
, Alonzo.prSteps = prSteps'
}
return
Alonzo.Prices
{ Alonzo.prMem = prMem'
, Alonzo.prSteps = prSteps'
}

genExUnits :: Gen Alonzo.ExUnits
genExUnits = do
exUnitsMem' <- Gen.integral (Range.linear 0 10)
exUnitsSteps' <- Gen.integral (Range.linear 0 10)
return Alonzo.ExUnits
{ Alonzo.exUnitsMem = exUnitsMem'
, Alonzo.exUnitsSteps = exUnitsSteps'
}
return
Alonzo.ExUnits
{ Alonzo.exUnitsMem = exUnitsMem'
, Alonzo.exUnitsSteps = exUnitsSteps'
}

genCostModels :: Gen Alonzo.CostModels
genCostModels = do
Expand All @@ -101,13 +101,14 @@ genAlonzoGenesis = do
collateralPercentage' <- Gen.integral (Range.linear 0 10)
maxCollateralInputs' <- Gen.integral (Range.linear 0 10)

return Alonzo.AlonzoGenesis
{ Alonzo.agCoinsPerUTxOWord = Ledger.CoinPerWord coinsPerUTxOWord
, Alonzo.agCostModels = mempty
, Alonzo.agPrices = prices'
, Alonzo.agMaxTxExUnits = maxTxExUnits'
, Alonzo.agMaxBlockExUnits = maxBlockExUnits'
, Alonzo.agMaxValSize = maxValSize'
, Alonzo.agCollateralPercentage = collateralPercentage'
, Alonzo.agMaxCollateralInputs = maxCollateralInputs'
}
return
Alonzo.AlonzoGenesis
{ Alonzo.agCoinsPerUTxOWord = Ledger.CoinPerWord coinsPerUTxOWord
, Alonzo.agCostModels = mempty
, Alonzo.agPrices = prices'
, Alonzo.agMaxTxExUnits = maxTxExUnits'
, Alonzo.agMaxBlockExUnits = maxBlockExUnits'
, Alonzo.agMaxValSize = maxValSize'
, Alonzo.agCollateralPercentage = collateralPercentage'
, Alonzo.agMaxCollateralInputs = maxCollateralInputs'
}
37 changes: 18 additions & 19 deletions cardano-api/gen/Test/Gen/Cardano/Api/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

module Test.Gen.Cardano.Api.Byron
( tests
) where

import Cardano.Api hiding (txIns)
import Cardano.Api.Byron

import Data.Proxy

import Test.Gen.Cardano.Api.Typed

import Hedgehog
import Test.Hedgehog.Roundtrip.CBOR
import Test.Tasty
import Test.Tasty.Hedgehog
)
where

import Cardano.Api hiding (txIns)
import Cardano.Api.Byron
import Data.Proxy
import Hedgehog
import Test.Gen.Cardano.Api.Typed
import Test.Hedgehog.Roundtrip.CBOR
import Test.Tasty
import Test.Tasty.Hedgehog

prop_byron_roundtrip_txbody_CBOR :: Property
prop_byron_roundtrip_txbody_CBOR = property $ do
Expand All @@ -35,9 +33,10 @@ prop_byron_roundtrip_Tx_Cddl = property $ do
tripping x serializeByronTx deserialiseByronTxCddl

tests :: TestTree
tests = testGroup "Test.Gen.Cardano.Api.Byron"
[ testProperty "Byron roundtrip txbody CBOR" prop_byron_roundtrip_txbody_CBOR
, testProperty "Byron roundtrip witness CBOR" prop_byron_roundtrip_witness_CBOR
, testProperty "Byron roundtrip tx CBOR" prop_byron_roundtrip_Tx_Cddl
]

tests =
testGroup
"Test.Gen.Cardano.Api.Byron"
[ testProperty "Byron roundtrip txbody CBOR" prop_byron_roundtrip_txbody_CBOR
, testProperty "Byron roundtrip witness CBOR" prop_byron_roundtrip_witness_CBOR
, testProperty "Byron roundtrip tx CBOR" prop_byron_roundtrip_Tx_Cddl
]
Loading
Loading