Skip to content
Open
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
75 changes: 28 additions & 47 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,33 @@ on:
pull_request: { branches: [main] }
create: { tags: [v*] }

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
cancel:
name: Cancel redundant actions already in progress
runs-on: ubuntu-latest
steps:
- name: Cancel actions in progress of same workflow and same branch
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

# Check that Haskell code is formatted.
code-formatter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: mrkkrp/ormolu-action@v2
- uses: actions/checkout@v4
- uses: haskell-actions/run-ormolu@v17

build:
name: Build StrongPath
runs-on: ${{ matrix.os }}
needs: code-formatter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it that we dropped this line? Was it never needed?


strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
# macos-latest is only ARM, when we update to a newer haskell we can run on it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# macos-latest is only ARM, when we update to a newer haskell we can run on it
# We don't currently run on macos-latest since it is ARM and GHC version we use is too old for it. We can add it once we update GHC.

- macos-13
- windows-latest
stack-resolver:
- from-stack-yaml
Expand All @@ -48,10 +45,10 @@ jobs:

steps:
- name: Checkout the repo
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache (Unix)
uses: actions/cache@v2
uses: actions/cache@v4
if: runner.os == 'Linux' || runner.os == 'macOS'
with:
path: |
Expand All @@ -73,11 +70,13 @@ jobs:
# making it even slower to test and fix (uffff).
# When they fix this, we should remove ${{ github.run_id }} from the end of the key
# and also remove restore-keys.
key: haskell-${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{ github.run_id }}
key:
haskell-${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{
github.run_id }}
restore-keys: |
haskell-${{ runner.os }}-${{ hashFiles('stack.yaml') }}-
- name: Cache (Windows)
uses: actions/cache@v2
uses: actions/cache@v4
if: runner.os == 'Windows'
with:
# C\:sr is where stack installs compiled dependencies.
Expand All @@ -87,40 +86,22 @@ jobs:
path: |
C:\sr
# TODO: Check TODO in caching for Unix above.
key: haskell-${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{ github.run_id }}
key:
haskell-${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{
github.run_id }}
restore-keys: |
haskell-${{ runner.os }}-${{ hashFiles('stack.yaml') }}-
# TODO: Remove this step once https://github.com/actions/cache/issues/445 is resolved.
- name: Fix MacOS problem with corrupt cached executable
if: runner.os == 'macOS'
run: rm -rf ~/.stack/setup-exe-cache

# We are setting up haskell via ghcup instead of using haskell/actions/setup
# because the mentioned gh action can be months late with the latest versions
# of Stack.
Comment on lines -98 to -100
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this reason not valid anymore? Of the action in question easily being late for months with the latest version of Stack?

- name: Set up Haskell (Stack) via ghcup (Unix)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
export BOOTSTRAP_HASKELL_NONINTERACTIVE=1
export BOOTSTRAP_HASKELL_INSTALL_STACK=1
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

- name: Set up Haskell (Stack) via ghcup (Win)
if: runner.os == 'Windows'
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Command -ScriptBlock ([ScriptBlock]::Create(".{$(Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing)} -InstallStack"))
shell: powershell

# NOTE: I commented out this in favor of manual setup above, since with this action we
# couldn't get the latest version of Stack.
# - name: Set up Haskell (Stack)
# uses: haskell/actions/setup@v1
# with:
# ghc-version: latest
# enable-stack: true
# stack-version: latest
- name: Set up Haskell
uses: haskell-actions/setup@v2
with:
ghc-version: latest
enable-stack: true
stack-version: latest

- name: Set Stack resolver
if: matrix.stack-resolver != 'from-stack-yaml'
Expand All @@ -134,10 +115,10 @@ jobs:
stack path --stack-root
stack ghc -- --version
ghc --version
- name: Build dependencies

- name: Build dependencies
run: stack --install-ghc test --only-dependencies

- name: Build StrongPath & Run tests
run: stack test

Expand Down
24 changes: 12 additions & 12 deletions src/StrongPath/FilePath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ import qualified System.FilePath.Windows as FPW
-- and work both on Linux and Windows when using `System` as a standard.
-- So Posix becames a kind of \"universal\" language for hardcoding the paths.

parseRelDir :: MonadThrow m => FilePath -> m (Path System (Rel d1) (Dir d2))
parseRelFile :: MonadThrow m => FilePath -> m (Path System (Rel d) (File f))
parseAbsDir :: MonadThrow m => FilePath -> m (Path System Abs (Dir d))
parseAbsFile :: MonadThrow m => FilePath -> m (Path System Abs (File f))
parseRelDirW :: MonadThrow m => FilePath -> m (Path Windows (Rel d1) (Dir d2))
parseRelFileW :: MonadThrow m => FilePath -> m (Path Windows (Rel d) (File f))
parseAbsDirW :: MonadThrow m => FilePath -> m (Path Windows Abs (Dir d))
parseAbsFileW :: MonadThrow m => FilePath -> m (Path Windows Abs (File f))
parseRelDirP :: MonadThrow m => FilePath -> m (Path Posix (Rel d1) (Dir d2))
parseRelFileP :: MonadThrow m => FilePath -> m (Path Posix (Rel d) (File f))
parseAbsDirP :: MonadThrow m => FilePath -> m (Path Posix Abs (Dir d))
parseAbsFileP :: MonadThrow m => FilePath -> m (Path Posix Abs (File f))
parseRelDir :: (MonadThrow m) => FilePath -> m (Path System (Rel d1) (Dir d2))
parseRelFile :: (MonadThrow m) => FilePath -> m (Path System (Rel d) (File f))
parseAbsDir :: (MonadThrow m) => FilePath -> m (Path System Abs (Dir d))
parseAbsFile :: (MonadThrow m) => FilePath -> m (Path System Abs (File f))
parseRelDirW :: (MonadThrow m) => FilePath -> m (Path Windows (Rel d1) (Dir d2))
parseRelFileW :: (MonadThrow m) => FilePath -> m (Path Windows (Rel d) (File f))
parseAbsDirW :: (MonadThrow m) => FilePath -> m (Path Windows Abs (Dir d))
parseAbsFileW :: (MonadThrow m) => FilePath -> m (Path Windows Abs (File f))
parseRelDirP :: (MonadThrow m) => FilePath -> m (Path Posix (Rel d1) (Dir d2))
parseRelFileP :: (MonadThrow m) => FilePath -> m (Path Posix (Rel d) (File f))
parseAbsDirP :: (MonadThrow m) => FilePath -> m (Path Posix Abs (Dir d))
parseAbsFileP :: (MonadThrow m) => FilePath -> m (Path Posix Abs (File f))
---- System
parseRelDir = parseRelDirFP RelDir [FP.pathSeparator, FPP.pathSeparator] P.parseRelDir

Expand Down
2 changes: 1 addition & 1 deletion src/StrongPath/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ instance Hashable (Path s b t) where

-- Paths can be compared
instance Ord (Path s b t) where
compare p1 p2 = compare (toFilePath p1) (toFilePath p2)
compare p1 p2 = compare (toFilePath p1) (toFilePath p2)
10 changes: 5 additions & 5 deletions src/StrongPath/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type File' = File ()
-- TODO: Extract `parseRelFileFP`, `parseRelDirFP`, `parseRelFP` and `extractRelPathPrefix` into StrongPath.FilePath.Internals?

parseRelFileFP ::
MonadThrow m =>
(MonadThrow m) =>
(p -> RelPathPrefix -> Path s (Rel d) (File f)) ->
[Char] ->
(FilePath -> m p) ->
Expand All @@ -157,7 +157,7 @@ parseRelFileFP _ _ _ "" = throwM (P.InvalidRelFile "")
parseRelFileFP constructor validSeparators pathParser fp = parseRelFP constructor validSeparators pathParser fp

parseRelDirFP ::
MonadThrow m =>
(MonadThrow m) =>
(p -> RelPathPrefix -> Path s (Rel d1) (Dir d2)) ->
[Char] ->
(FilePath -> m p) ->
Expand All @@ -169,7 +169,7 @@ parseRelDirFP constructor validSeparators pathParser fp = parseRelFP constructor
-- Helper function for the parseRelFileFP and parseRelDirFP, should not be used called directly but only
-- by parseRelFileFP and parseRelDirFP.
parseRelFP ::
MonadThrow m =>
(MonadThrow m) =>
(p -> RelPathPrefix -> Path s (Rel d1) t) ->
[Char] ->
(FilePath -> m p) ->
Expand Down Expand Up @@ -198,8 +198,8 @@ extractRelPathPrefix validSeparators path =
dropParentDirs :: FilePath -> (Int, FilePath)
dropParentDirs p
| pathStartsWithParentDir p =
let (n, p') = dropParentDirs (drop 3 p)
in (1 + n, p')
let (n, p') = dropParentDirs (drop 3 p)
in (1 + n, p')
| p == ".." = (1, "")
| otherwise = (0, p)

Expand Down
4 changes: 2 additions & 2 deletions src/StrongPath/Operations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ castFile _ = impossible
-- Works well for \"normal\" relative paths like @\"a\\b\\c\"@ (Win) or @\"a\/b\/c\"@ (Posix).
-- If path is weird but still considered relative, like just @\"C:\"@ on Win,
-- results can be unexpected, most likely resulting with error thrown.
relDirToPosix :: MonadThrow m => Path s (Rel d1) (Dir d2) -> m (Path Posix (Rel d1) (Dir d2))
relDirToPosix :: (MonadThrow m) => Path s (Rel d1) (Dir d2) -> m (Path Posix (Rel d1) (Dir d2))
relDirToPosix sp@(RelDir _ _) = parseRelDirP $ FPP.joinPath $ FP.splitDirectories $ toFilePath sp
relDirToPosix sp@(RelDirW _ _) = parseRelDirP $ FPP.joinPath $ FPW.splitDirectories $ toFilePath sp
relDirToPosix (RelDirP p pr) = return $ RelDirP p pr
relDirToPosix _ = impossible

-- | Converts relative file path to posix, if it is not already posix.
-- Check 'relDirToPosix' for more details, they behave the same.
relFileToPosix :: MonadThrow m => Path s (Rel d1) (File f) -> m (Path Posix (Rel d1) (File f))
relFileToPosix :: (MonadThrow m) => Path s (Rel d1) (File f) -> m (Path Posix (Rel d1) (File f))
relFileToPosix sp@(RelFile _ _) = parseRelFileP $ FPP.joinPath $ FP.splitDirectories $ toFilePath sp
relFileToPosix sp@(RelFileW _ _) = parseRelFileP $ FPP.joinPath $ FPW.splitDirectories $ toFilePath sp
relFileToPosix (RelFileP p pr) = return $ RelFileP p pr
Expand Down
2 changes: 1 addition & 1 deletion test/StrongPath/InstanceTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ test_StrongPathInstance = testSpec "StrongPath.Instance" $ do
aPath <- parseRelDir "a"
bPath <- parseRelDir "b"
abPath <- parseRelDir "a/b"
sort [bPath, abPath, aPath] `shouldBe` [aPath, abPath, bPath]
sort [bPath, abPath, aPath] `shouldBe` [aPath, abPath, bPath]