Skip to content

Commit 3b13288

Browse files
mergify[bot]mpickeringjasagredoulysses4ever
authored
ci: Fix --index-state for hackage roundtrip tests (backport #10285) (#10305)
* hackage-tests: Add --index-state argument to fix the cabal files We need to fix the index-state we test against so a new bad cabal file doesn't take down the CI for everyone. Towards #10284 (cherry picked from commit 8e4d167) * ci: Fix --index-state for hackage roundtrip tests As a principle, tests which are required for CI to pass should be reproducible and not depending on external resources changes or being modified. The hackage tests currently violate this by depending on the latest index state from hackage. This is problematic because until the test is fixed all merges into master are blocked. Even though the patches in question have nothing to do with the test. It would be more suitable for a nightly job to run on the latest index and for normal CI to run with a fixed index which is updated periodically in a controlled manner. Fixes #10284 (cherry picked from commit 31507b1) * Re-enable Windows CI (cherry picked from commit 4aade2d) * CI: skip cli-suite on Windows due to #9571 (#10257) (cherry picked from commit 30d2a38) --------- Co-authored-by: Matthew Pickering <[email protected]> Co-authored-by: Javier Sagredo <[email protected]> Co-authored-by: Artem Pelenitsyn <[email protected]>
1 parent 2e08b94 commit 3b13288

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

.github/workflows/validate.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ jobs:
7272
# support, so the PR *must* have a changelog entry.
7373
ghc: ['9.10.1', '9.8.2', '9.6.4', '9.4.8', '9.2.8', '9.0.2', '8.10.7', '8.8.4', '8.6.5']
7474
exclude:
75+
# Throws fatal "cabal-tests.exe: fd:8: hGetLine: end of file" exception
76+
# even with --io-manager=native
77+
- os: windows-latest
78+
ghc: "9.0.2"
7579
# corrupts GHA cache or the fabric of reality itself, see https://github.com/haskell/cabal/issues/8356
7680
- os: windows-latest
7781
ghc: '8.10.7'
@@ -204,6 +208,7 @@ jobs:
204208
run: sh validate.sh $FLAGS -s cli-tests
205209

206210
- name: Validate cli-suite
211+
if: runner.os != 'Windows'
207212
run: sh validate.sh $FLAGS -s cli-suite
208213

209214
- name: Validate solver-benchmarks-tests

Cabal-tests/Cabal-tests.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ test-suite hackage-tests
161161
, deepseq
162162
, directory
163163
, filepath
164+
, time
164165

165166
build-depends:
166167
base-compat >=0.11.0 && <0.14

Cabal-tests/tests/HackageTests.hs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import System.FilePath ((</>))
3333
import Data.Orphans ()
3434

3535
import qualified Codec.Archive.Tar as Tar
36+
import qualified Codec.Archive.Tar.Entry as Tar
3637
import qualified Data.ByteString as B
3738
import qualified Data.ByteString.Char8 as B8
3839
import qualified Data.ByteString.Lazy as BSL
@@ -56,11 +57,14 @@ import Data.TreeDiff.Instances.Cabal ()
5657
import Data.TreeDiff.Pretty (ansiWlEditExprCompact)
5758
#endif
5859

60+
import Data.Time.Clock.System
61+
import Data.Time.Format
62+
5963
-------------------------------------------------------------------------------
6064
-- parseIndex: Index traversal
6165
-------------------------------------------------------------------------------
6266

63-
parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool)
67+
parseIndex :: (Monoid a, NFData a) => (Tar.EpochTime -> FilePath -> Bool)
6468
-> (FilePath -> B.ByteString -> IO a) -> IO a
6569
parseIndex predicate action = do
6670
configPath <- getCabalConfigPath
@@ -99,7 +103,7 @@ parseIndex predicate action = do
99103

100104
parseIndex'
101105
:: (Monoid a, NFData a)
102-
=> (FilePath -> Bool)
106+
=> (Tar.EpochTime -> FilePath -> Bool)
103107
-> (FilePath -> B.ByteString -> IO a) -> FilePath -> IO a
104108
parseIndex' predicate action path = do
105109
putStrLn $ "Reading index from: " ++ path
@@ -110,7 +114,7 @@ parseIndex' predicate action path = do
110114

111115
where
112116
cons entry entries
113-
| predicate (Tar.entryPath entry) = entry : entries
117+
| predicate (Tar.entryTime entry) (Tar.entryPath entry) = entry : entries
114118
| otherwise = entries
115119

116120
f entry = case Tar.entryContent entry of
@@ -320,6 +324,13 @@ main = join (O.execParser opts)
320324
, O.progDesc "tests using Hackage's index"
321325
]
322326

327+
indexP =
328+
fmap cvt <$> O.optional (O.strOption (O.long "index-state" <> O.metavar "YYYY-MM-DD"))
329+
where
330+
cvt =
331+
systemSeconds . utcToSystemTime .
332+
parseTimeOrError False defaultTimeLocale "%Y-%m-%d"
333+
323334
optsP = subparser
324335
[ command "read-fields" readFieldsP
325336
"Parse outer format (to '[Field]', TODO: apply Quirks)"
@@ -330,20 +341,20 @@ main = join (O.execParser opts)
330341

331342
defaultA = do
332343
putStrLn "Default action: parsec k"
333-
parsecA (mkPredicate ["k"]) False
344+
parsecA ["k"] False Nothing
334345

335-
readFieldsP = readFieldsA <$> prefixP
336-
readFieldsA pfx = parseIndex pfx readFieldTest
346+
readFieldsP = readFieldsA <$> prefixP <*> indexP
347+
readFieldsA pfx idx = parseIndex (mkPredicate pfx idx) readFieldTest
337348

338-
parsecP = parsecA <$> prefixP <*> keepGoingP
349+
parsecP = parsecA <$> prefixP <*> keepGoingP <*> indexP
339350
keepGoingP =
340351
O.flag' True (O.long "keep-going") <|>
341352
O.flag' False (O.long "no-keep-going") <|>
342353
pure False
343354

344-
parsecA pfx keepGoing = do
355+
parsecA pfx keepGoing idx = do
345356
begin <- Clock.getTime Clock.Monotonic
346-
ParsecResult n w f <- parseIndex pfx (parseParsecTest keepGoing)
357+
ParsecResult n w f <- parseIndex (mkPredicate pfx idx) (parseParsecTest keepGoing)
347358
end <- Clock.getTime Clock.Monotonic
348359
let diff = Clock.toNanoSecs $ Clock.diffTimeSpec end begin
349360

@@ -353,14 +364,14 @@ main = join (O.execParser opts)
353364
putStrLn $ showFFloat (Just 6) (fromInteger diff / 1e9 :: Double) " seconds elapsed"
354365
putStrLn $ showFFloat (Just 6) (fromInteger diff / 1e6 / fromIntegral n :: Double) " milliseconds per file"
355366

356-
roundtripP = roundtripA <$> prefixP <*> testFieldsP
357-
roundtripA pfx testFieldsTransform = do
358-
Sum n <- parseIndex pfx (roundtripTest testFieldsTransform)
367+
roundtripP = roundtripA <$> prefixP <*> testFieldsP <*> indexP
368+
roundtripA pfx testFieldsTransform idx = do
369+
Sum n <- parseIndex (mkPredicate pfx idx) (roundtripTest testFieldsTransform)
359370
putStrLn $ show n ++ " files processed"
360371

361-
checkP = checkA <$> prefixP
362-
checkA pfx = do
363-
CheckResult n w x a b c d e <- parseIndex pfx parseCheckTest
372+
checkP = checkA <$> prefixP <*> indexP
373+
checkA pfx idx = do
374+
CheckResult n w x a b c d e <- parseIndex (mkPredicate pfx idx) parseCheckTest
364375
putStrLn $ show n ++ " files processed"
365376
putStrLn $ show w ++ " files have lexer/parser warnings"
366377
putStrLn $ show x ++ " files have check warnings"
@@ -370,7 +381,7 @@ main = join (O.execParser opts)
370381
putStrLn $ show d ++ " build dist suspicious warning"
371382
putStrLn $ show e ++ " build dist inexcusable"
372383

373-
prefixP = fmap mkPredicate $ many $ O.strArgument $ mconcat
384+
prefixP = many $ O.strArgument $ mconcat
374385
[ O.metavar "PREFIX"
375386
, O.help "Check only files starting with a prefix"
376387
]
@@ -380,8 +391,14 @@ main = join (O.execParser opts)
380391
, O.help "Test also 'showFields . fromParsecFields . readFields' transform"
381392
]
382393

383-
mkPredicate [] = const True
384-
mkPredicate pfxs = \n -> any (`isPrefixOf` n) pfxs
394+
indexPredicate :: Maybe Tar.EpochTime -> (k -> Bool) -> (Tar.EpochTime -> k -> Bool)
395+
indexPredicate Nothing k = const k
396+
indexPredicate (Just indexDate) k =
397+
\e -> if (e <= indexDate) then k else const False
398+
399+
mkPredicate :: [String] -> Maybe Tar.EpochTime -> (Tar.EpochTime -> FilePath -> Bool)
400+
mkPredicate [] idx = indexPredicate idx (const True)
401+
mkPredicate pfxs idx = indexPredicate idx (\n -> any (`isPrefixOf` n) pfxs)
385402

386403
command name p desc = O.command name
387404
(O.info (p <**> O.helper) (O.progDesc desc))

validate.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ CABAL_TESTSUITE_BDIR="$(pwd)/$BUILDDIR/build/$ARCH/$BASEHC/cabal-testsuite-3"
324324
CABALNEWBUILD="${CABAL} build $JOBS -w $HC --builddir=$BUILDDIR --project-file=$PROJECTFILE"
325325
CABALLISTBIN="${CABAL} list-bin --builddir=$BUILDDIR --project-file=$PROJECTFILE"
326326

327+
# See https://github.com/haskell/cabal/issues/9571 for why we set this for Windows
328+
RTSOPTS="$([ $ARCH = "x86_64-windows" ] && [ "$($HC --numeric-version)" != "9.0.2" ] && [ "$(echo -e "$(ghc --numeric-version)\n9.0.2" | sort -V | head -n1)" = "9.0.2" ] && echo "+RTS --io-manager=native" || echo "")"
329+
327330
# header
328331
#######################################################################
329332

@@ -409,14 +412,18 @@ CMD="$($CABALLISTBIN Cabal-tests:test:rpmvercmp) $TESTSUITEJOBS --hide-successes
409412
CMD="$($CABALLISTBIN Cabal-tests:test:no-thunks-test) $TESTSUITEJOBS --hide-successes"
410413
(cd Cabal-tests && timed $CMD) || exit 1
411414

415+
416+
# See #10284 for why this value is pinned.
417+
HACKAGE_TESTS_INDEX_STATE="--index-state=2024-08-25"
418+
412419
CMD=$($CABALLISTBIN Cabal-tests:test:hackage-tests)
413-
(cd Cabal-tests && timed $CMD read-fields) || exit 1
420+
(cd Cabal-tests && timed $CMD read-fields $HACKAGE_TESTS_INDEX_STATE) || exit 1
414421
if $HACKAGETESTSALL; then
415-
(cd Cabal-tests && timed $CMD parsec) || exit 1
416-
(cd Cabal-tests && timed $CMD roundtrip) || exit 1
422+
(cd Cabal-tests && timed $CMD parsec $HACKAGE_TESTS_INDEX_STATE) || exit 1
423+
(cd Cabal-tests && timed $CMD roundtrip $HACKAGE_TESTS_INDEX_STATE) || exit 1
417424
else
418-
(cd Cabal-tests && timed $CMD parsec d) || exit 1
419-
(cd Cabal-tests && timed $CMD roundtrip k) || exit 1
425+
(cd Cabal-tests && timed $CMD parsec d $HACKAGE_TESTS_INDEX_STATE) || exit 1
426+
(cd Cabal-tests && timed $CMD roundtrip k $HACKAGE_TESTS_INDEX_STATE) || exit 1
420427
fi
421428
}
422429

0 commit comments

Comments
 (0)