Skip to content

Commit

Permalink
Merge branch 'main' into jhrcek/loadConfig-avoid-getCurrentDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Jan 17, 2025
2 parents cbe47ce + cdff43e commit 73e6bc0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 171 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/cabal.yml

This file was deleted.

81 changes: 20 additions & 61 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,34 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
stack: ["2.15.7"]
ghc: ["9.4", "9.6", "9.8"]

steps:
- name: Get the version
id: get_version
run: 'echo ::set-output name=version::${GITHUB_REF#refs/tags/}'

- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: haskell-actions/setup@v2
name: Setup Haskell Stack
id: setup
with:
enable-stack: true
stack-version: ${{ matrix.stack }}
stack-no-global: true
ghc-version: ${{ matrix.ghc }}

- uses: actions/cache@v2
name: Cache ~/.stack
- uses: actions/cache@v3
with:
path: ~/.stack
key: "${{ runner.os }}-v9-${{ hashFiles('stylish-haskell.cabal', 'stack.yaml', 'stack.yaml.lock') }}"

- name: Add ~/.local/bin to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-v1-${{ hashFiles('*.cabal') }}
restore-keys: |
${{ runner.os }}-${{ matrix.ghc }}-v1-
- name: Build
run: make build
id: build
- run: make build
- run: make test

- name: Test
run: make test

- name: Build artifact
if: startsWith(github.ref, 'refs/tags')
- if: startsWith(github.ref, 'refs/tags') && matrix.ghc == '9.6'
run: make artifact
env:
PATAT_TAG: ${{ steps.get_version.outputs.version }}

- uses: actions/upload-artifact@v2
if: startsWith(github.ref, 'refs/tags')
- uses: actions/upload-artifact@v4
if: startsWith(github.ref, 'refs/tags') && matrix.ghc == '9.6'
with:
path: artifacts/*
name: artifacts
name: artifacts-${{ runner.os }}

release:
name: Release
Expand All @@ -60,41 +45,15 @@ jobs:
if: startsWith(github.ref, 'refs/tags')

steps:
- name: Get the version
id: get_version
run: 'echo ::set-output name=version::${GITHUB_REF#refs/tags/}'

- uses: actions/download-artifact@v4
with:
name: artifacts

- name: Display structure of downloaded files
run: ls -R
pattern: artifacts-*

- uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: ${{ steps.get_version.outputs.version }}

- name: Upload Linux Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./stylish-haskell-${{ steps.get_version.outputs.version }}-linux-x86_64.tar.gz
asset_name: stylish-haskell-${{ steps.get_version.outputs.version }}-linux-x86_64.tar.gz
asset_content_type: application/gzip
- run: ls -R
- run: 'sha256sum artifacts-*/*'

- name: Upload MacOS Asset
uses: actions/upload-release-asset@v1
- uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./stylish-haskell-${{ steps.get_version.outputs.version }}-darwin-x86_64.zip
asset_name: stylish-haskell-${{ steps.get_version.outputs.version }}-darwin-x86_64.zip
asset_content_type: application/zip
files: 'artifacts-*/stylish-haskell-*'
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
+format (UseConfig cfgFile) maybeFile content
```

* Bump `Cabal` lower bound to 3.14

- 0.14.6.0 (2024-01-19)
* #471 Support GHC 9.8 (by Michael Peyton Jones)
* #440 Fix dissappearing `DEPRECATED` pragma on module (by Lev Dvorkin)
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ COMPRESS_BIN_DEPS=$(UPX_BINARY)
COMPRESS_BIN=upx
endif

STACK=stack

# Default target.
.PHONY: build
build: $(STYLISH_BINARY)
Expand All @@ -49,7 +47,7 @@ $(STYLISH_PACKAGE).$(ARCHIVE): $(STYLISH_BINARY) $(COMPRESS_BIN_DEPS)
$(ARCHIVE_CREATE) $(STYLISH_PACKAGE).$(ARCHIVE) $(STYLISH_PACKAGE)

$(STYLISH_BINARY):
$(STACK) build --copy-bins
cabal install --installdir="$(dir $(STYLISH_BINARY))"

# UPX is used to compress the resulting binary. We currently don't use this on
# Mac OS.
Expand All @@ -62,4 +60,4 @@ $(UPX_BINARY):

.PHONY: test
test:
stack build --test
cabal test
31 changes: 19 additions & 12 deletions lib/Language/Haskell/Stylish/Config/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ module Language.Haskell.Stylish.Config.Cabal
--------------------------------------------------------------------------------
import Control.Monad (unless)
import qualified Data.ByteString.Char8 as BS
import Data.Either (isRight)
import Data.Foldable (traverse_)
import Data.List (nub)
import Data.Maybe (maybeToList)
import qualified Distribution.PackageDescription as Cabal
import qualified Distribution.PackageDescription.Parsec as Cabal
import qualified Distribution.Parsec as Cabal
import qualified Distribution.Simple.Utils as Cabal
import qualified Distribution.Utils.Path as Cabal
import qualified Distribution.Verbosity as Cabal
import qualified Language.Haskell.Extension as Language
import Language.Haskell.Stylish.Verbose
Expand All @@ -23,8 +23,8 @@ import System.Directory (doesFileExist,


--------------------------------------------------------------------------------
import GHC.Data.Maybe (mapMaybe)
import Language.Haskell.Stylish.Config.Internal
import GHC.Data.Maybe (mapMaybe)


--------------------------------------------------------------------------------
Expand All @@ -36,18 +36,25 @@ findLanguageExtensions verbose =

--------------------------------------------------------------------------------
-- | Find the closest .cabal file, possibly going up the directory structure.
-- TODO: use ConfigSearchStrategy here, too
findCabalFile :: Verbose -> IO (Maybe FilePath)
findCabalFile verbose = do
potentialProjectRoots <- ancestors <$> getCurrentDirectory
potentialCabalFile <- filter isRight <$>
traverse Cabal.findPackageDesc potentialProjectRoots
case potentialCabalFile of
[Right cabalFile] -> return (Just cabalFile)
_ -> do
verbose $ ".cabal file not found, directories searched: " <>
show potentialProjectRoots
verbose $ "Stylish Haskell will work basing on LANGUAGE pragmas in source files."
return Nothing
cwd <- getCurrentDirectory
go [] $ ancestors cwd
where
go :: [FilePath] -> [FilePath] -> IO (Maybe FilePath)
go searched [] = do
verbose $ ".cabal file not found, directories searched: " <>
show searched
verbose $ "Stylish Haskell will work basing on LANGUAGE pragmas in source files."
return Nothing
go searched (p : ps) = do
let projectRoot = Just $ Cabal.makeSymbolicPath p
potentialCabalFile <- Cabal.findPackageDesc projectRoot
case potentialCabalFile of
Right cabalFile -> pure $ Just $
Cabal.interpretSymbolicPath projectRoot cabalFile
_ -> go (p : searched) ps


--------------------------------------------------------------------------------
Expand Down
11 changes: 0 additions & 11 deletions stack.yaml

This file was deleted.

47 changes: 0 additions & 47 deletions stack.yaml.lock

This file was deleted.

2 changes: 1 addition & 1 deletion stylish-haskell.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Common depends
aeson >= 0.6 && < 2.3,
base >= 4.8 && < 5,
bytestring >= 0.9 && < 0.13,
Cabal >= 3.4 && < 4.0,
Cabal >= 3.14 && < 4.0,
containers >= 0.3 && < 0.7,
directory >= 1.2.3 && < 1.4,
filepath >= 1.1 && < 1.5,
Expand Down

0 comments on commit 73e6bc0

Please sign in to comment.