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

Prefer snapshot to resolver #125

Merged
merged 1 commit into from
Feb 4, 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
22 changes: 11 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ jobs:
matrix:
os:
- ubuntu-latest
resolver:
snapshot:
- stack-ghc-9.4.8.yaml
- stack-ghc-9.6.4.yaml
- stack-ghc-9.8.1.yaml
include:
- os: macos-latest
resolver: stack-ghc-9.8.1.yaml
snapshot: stack-ghc-9.8.1.yaml
# macos-14 provides macOS/AArch64 (M1)
- os: macos-14
resolver: stack-ghc-9.8.1.yaml
snapshot: stack-ghc-9.8.1.yaml
- os: windows-latest
resolver: stack-ghc-9.8.1.yaml
snapshot: stack-ghc-9.8.1.yaml
steps:
- name: Clone project
uses: actions/checkout@v4
Expand All @@ -39,15 +39,15 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.stack
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.resolver }}
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.snapshot }}
- name: Cache dependencies on Windows
if: startsWith(runner.os, 'Windows')
uses: actions/cache@v4
with:
path: |
~\AppData\Roaming\stack
~\AppData\Local\Programs\stack
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.resolver }}
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.snapshot }}
- name: Build and run tests
shell: bash
run: |
Expand All @@ -59,7 +59,7 @@ jobs:
curl -sSL https://get.haskellstack.org/ | sh
fi

stack --resolver ${{ matrix.resolver }} test --bench --no-run-benchmarks --haddock --no-haddock-deps
stack --resolver ${{ matrix.snapshot }} test --bench --no-run-benchmarks --haddock --no-haddock-deps
test-pretty-exceptions:
name: Test build of test-pretty-exceptions
runs-on: ${{ matrix.os }}
Expand All @@ -69,7 +69,7 @@ jobs:
os:
- ubuntu-latest
- windows-latest
resolver:
snapshot:
- stack-ghc-9.8.1.yaml
steps:
- name: Clone project
Expand All @@ -79,17 +79,17 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.stack
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.resolver }}-pretty
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.snapshot }}-pretty
- name: Cache dependencies on Windows
if: startsWith(runner.os, 'Windows')
uses: actions/cache@v4
with:
path: |
~\AppData\Roaming\stack
~\AppData\Local\Programs\stack
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.resolver }}-pretty
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.snapshot }}-pretty
- name: Build test-pretty-exceptions
shell: bash
run: |
set -ex
stack --resolver ${{ matrix.resolver }} build --flag pantry:test-pretty-exceptions
stack --resolver ${{ matrix.snapshot }} build --flag pantry:test-pretty-exceptions
16 changes: 8 additions & 8 deletions int/Pantry/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ instance Display PantryException where
<> displayShow (toFilePath dir)
display (InvalidOverrideCompiler x y) =
"Error: [S-287]\n"
<> "Specified compiler for a resolver ("
<> "Specified compiler for a snapshot ("
<> display x
<> "), but also specified an override compiler ("
<> display y
Expand Down Expand Up @@ -1605,7 +1605,7 @@ instance Pretty PantryException where
"[S-287]"
<> line
<> fillSep
[ flow "Specified compiler for a resolver"
[ flow "Specified compiler for a snapshot"
, parens (style Shell (fromString . T.unpack $ textDisplay x))
, flow "but also specified an override compiler"
, parens (style Shell (fromString . T.unpack $ textDisplay y)) <> "."
Expand Down Expand Up @@ -3225,17 +3225,17 @@ instance ToJSON RawSnapshotLayer where
instance FromJSON (WithJSONWarnings (Unresolved RawSnapshotLayer)) where
parseJSON = withObjectWarnings "Snapshot" $ \o -> do
_ :: Maybe Text <- o ..:? "name" -- avoid warnings for old snapshot format
mcompiler <- o ..:? "compiler"
mresolver <- jsonSubWarningsT $ o ...:? ["snapshot", "resolver"]
mCompiler <- o ..:? "compiler"
mSnapshot <- jsonSubWarningsT $ o ...:? ["snapshot", "resolver"]
unresolvedSnapshotParent <-
case (mcompiler, mresolver) of
(Nothing, Nothing) -> fail "Snapshot must have either resolver or compiler"
case (mCompiler, mSnapshot) of
(Nothing, Nothing) -> fail "Snapshot must have either a compiler or a snapshot"
(Just compiler, Nothing) -> pure $ pure (RSLCompiler compiler, Nothing)
(_, Just (Unresolved usl)) -> pure $ Unresolved $ \mdir -> do
sl <- usl mdir
case (sl, mcompiler) of
case (sl, mCompiler) of
(RSLCompiler c1, Just c2) -> throwIO $ InvalidOverrideCompiler c1 c2
_ -> pure (sl, mcompiler)
_ -> pure (sl, mCompiler)

unresolvedLocs <- jsonSubWarningsT (o ..:? "packages" ..!= [])
rslDropPackages <- Set.map unCabalString <$> (o ..:? "drop-packages" ..!= Set.empty)
Expand Down
30 changes: 15 additions & 15 deletions test/Pantry/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Pantry.Types
( Tree (..), TreeEntry (..), parseTree, renderTree )
import RIO
import qualified RIO.Text as T
import RIO.Time ( Day (..) )
import RIO.Time ( Day (..), fromGregorian )
import Test.Hspec
import Text.RawString.QQ

Expand Down Expand Up @@ -108,20 +108,20 @@ spec = do
it "parses snapshot using 'resolver'" $ do
RawSnapshotLayer{..} <- parseSl $
"name: 'test'\n" ++
"resolver: lts-2.10\n"
rslParent `shouldBe` RSLSynonym (LTS 2 10)
"resolver: lts-22.9\n"
rslParent `shouldBe` RSLSynonym (LTS 22 9)

it "parses snapshot using 'snapshot'" $ do
RawSnapshotLayer{..} <- parseSl $
"name: 'test'\n" ++
"snapshot: lts-2.10\n"
rslParent `shouldBe` RSLSynonym (LTS 2 10)
"snapshot: lts-22.9\n"
rslParent `shouldBe` RSLSynonym (LTS 22 9)

it "throws if both 'resolver' and 'snapshot' are present" $ do
let go = parseSl $
"name: 'test'\n" ++
"resolver: lts-2.10\n" ++
"snapshot: lts-2.10\n"
"resolver: lts-22.9\n" ++
"snapshot: lts-22.9\n"
go `shouldThrow` anyException

it "throws if both 'snapshot' and 'compiler' are not present" $ do
Expand All @@ -131,8 +131,8 @@ spec = do
it "works if no 'snapshot' specified" $ do
RawSnapshotLayer{..} <- parseSl $
"name: 'test'\n" ++
"compiler: ghc-8.0.1\n"
rslParent `shouldBe` RSLCompiler (WCGhc (mkVersion [8, 0, 1]))
"compiler: ghc-9.6.4\n"
rslParent `shouldBe` RSLCompiler (WCGhc (mkVersion [9, 6, 4]))

hh "rendering the name of an LTS to JSON" $ property $ do
(major, minor) <- forAll $ (,)
Expand Down Expand Up @@ -211,14 +211,14 @@ spec = do
txt `shouldBe` txt''
sameUrl _ _ _ = liftIO $ error "Snapshot synonym did not complete as expected"

it "default location for nightly-2020-01-01" $ do
let sn = Nightly $ ModifiedJulianDay 58849
it "default location for nightly-2024-02-04" $ do
let sn = Nightly $ fromGregorian 2024 2 4
loc <- runPantryAppClean $ completeSnapshotLocation $ RSLSynonym sn
sameUrl loc (defaultSnapshotLocation sn)
"https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/1/1.yaml"
"https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2024/2/4.yaml"

it "default location for lts-15.1" $ do
let sn = LTS 15 1
it "default location for lts-22.9" $ do
let sn = LTS 22 9
loc <- runPantryAppClean $ completeSnapshotLocation $ RSLSynonym sn
sameUrl loc (defaultSnapshotLocation sn)
"https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/1.yaml"
"https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/9.yaml"