2021-05-04 18:16:00 +02:00
#! / usr / bin / env nix - shell
#! nix - shell - p " haskellPackages.ghcWithPackages (p: [p.aeson p.req]) "
2022-05-20 21:27:31 +02:00
#! nix - shell - p hydra - unstable
2021-05-04 18:16:00 +02:00
#! nix - shell - i runhaskell
{-
The purpose of this script is
1 ) download the state of the nixpkgs / haskell - updates job from hydra ( with get - report )
2 ) print a summary of the state suitable for pasting into a github comment ( with ping - maintainers )
3 ) print a list of broken packages suitable for pasting into configuration - hackage2nix . yaml
2021-05-08 07:15:20 +02:00
Because step 1 ) is quite expensive and takes roughly ~ 5 minutes the result is cached in a json file in XDG_CACHE .
2021-05-04 18:16:00 +02:00
- }
{- # LANGUAGE BlockArguments # -}
{- # LANGUAGE DeriveAnyClass # -}
{- # LANGUAGE DeriveGeneric # -}
2021-05-15 08:53:19 +02:00
{- # LANGUAGE DerivingStrategies # -}
2021-05-04 18:16:00 +02:00
{- # LANGUAGE DuplicateRecordFields # -}
2023-03-25 10:21:55 +01:00
{- # LANGUAGE FlexibleContexts # -}
2023-03-25 11:24:13 +01:00
{- # LANGUAGE GeneralizedNewtypeDeriving # -}
2021-05-04 18:16:00 +02:00
{- # LANGUAGE LambdaCase # -}
{- # LANGUAGE NamedFieldPuns # -}
{- # LANGUAGE OverloadedStrings # -}
{- # LANGUAGE ScopedTypeVariables # -}
{- # LANGUAGE TupleSections # -}
2021-09-10 00:55:12 +02:00
{- # LANGUAGE ViewPatterns # -}
2022-05-20 21:41:30 +02:00
{- # OPTIONS_GHC - Wall # -}
2023-02-20 00:20:42 +01:00
{- # LANGUAGE DataKinds # -}
2021-05-04 18:16:00 +02:00
2023-09-03 21:54:03 +02:00
import Control.Monad ( forM_ , forM , ( <=< ) )
2021-05-04 18:16:00 +02:00
import Control.Monad.Trans ( MonadIO ( liftIO ) )
import Data.Aeson (
FromJSON ,
2023-03-25 11:24:13 +01:00
FromJSONKey ,
2021-05-04 18:16:00 +02:00
ToJSON ,
decodeFileStrict' ,
eitherDecodeStrict' ,
encodeFile ,
)
2021-05-09 00:37:05 +02:00
import Data.Foldable ( Foldable ( toList ) , foldl' )
2021-05-04 18:16:00 +02:00
import Data.List.NonEmpty ( NonEmpty , nonEmpty )
import qualified Data.List.NonEmpty as NonEmpty
import Data.Map.Strict ( Map )
import qualified Data.Map.Strict as Map
2021-09-18 19:39:26 +02:00
import Data.Maybe ( fromMaybe , mapMaybe , isNothing )
2021-05-04 18:16:00 +02:00
import Data.Monoid ( Sum ( Sum , getSum ) )
import Data.Sequence ( Seq )
import qualified Data.Sequence as Seq
import Data.Set ( Set )
import qualified Data.Set as Set
import Data.Text ( Text )
import qualified Data.Text as Text
import Data.Text.Encoding ( encodeUtf8 )
2023-03-25 09:44:26 +01:00
import qualified Data.Text.IO as Text
2021-05-04 18:16:00 +02:00
import Data.Time ( defaultTimeLocale , formatTime , getCurrentTime )
import Data.Time.Clock ( UTCTime )
import GHC.Generics ( Generic )
import Network.HTTP.Req (
2023-02-20 00:20:42 +01:00
GET ( GET ) ,
HttpResponse ( HttpResponseBody ) ,
NoReqBody ( NoReqBody ) ,
Option ,
Req ,
Scheme ( Https ) ,
bsResponse ,
defaultHttpConfig ,
header ,
https ,
jsonResponse ,
req ,
responseBody ,
responseTimeout ,
runReq ,
( /: ) ,
2021-05-04 18:16:00 +02:00
)
import System.Directory ( XdgDirectory ( XdgCache ) , getXdgDirectory )
import System.Environment ( getArgs )
2024-03-30 13:53:20 +01:00
import System.Exit ( die )
2021-05-04 18:16:00 +02:00
import System.Process ( readProcess )
2021-05-09 00:37:05 +02:00
import Prelude hiding ( id )
2021-09-10 00:55:12 +02:00
import Data.List ( sortOn )
import Control.Concurrent.Async ( concurrently )
import Control.Exception ( evaluate )
2024-01-14 17:46:48 +01:00
import qualified Data.IntMap.Lazy as IntMap
2021-09-10 00:55:12 +02:00
import qualified Data.IntSet as IntSet
import Data.Bifunctor ( second )
2023-02-20 00:20:42 +01:00
import Data.Data ( Proxy )
import Data.ByteString ( ByteString )
import qualified Data.ByteString.Char8 as ByteString
import Distribution.Simple.Utils ( safeLast , fromUTF8BS )
2021-05-04 18:16:00 +02:00
newtype JobsetEvals = JobsetEvals
{ evals :: Seq Eval
}
2023-03-25 11:24:13 +01:00
deriving stock ( Generic , Show )
deriving anyclass ( ToJSON , FromJSON )
2021-05-04 18:16:00 +02:00
newtype Nixpkgs = Nixpkgs { revision :: Text }
2023-03-25 11:24:13 +01:00
deriving stock ( Generic , Show )
deriving anyclass ( ToJSON , FromJSON )
2021-05-04 18:16:00 +02:00
newtype JobsetEvalInputs = JobsetEvalInputs { nixpkgs :: Nixpkgs }
2023-03-25 11:24:13 +01:00
deriving stock ( Generic , Show )
deriving anyclass ( ToJSON , FromJSON )
2021-05-04 18:16:00 +02:00
data Eval = Eval
2021-05-08 07:15:20 +02:00
{ id :: Int
2021-05-04 18:16:00 +02:00
, jobsetevalinputs :: JobsetEvalInputs
2023-09-03 21:54:03 +02:00
, builds :: Seq Int
2021-05-04 18:16:00 +02:00
}
deriving ( Generic , ToJSON , FromJSON , Show )
2023-03-25 11:24:13 +01:00
-- | Hydra job name.
--
-- Examples:
-- - @"haskellPackages.lens.x86_64-linux"@
-- - @"haskell.packages.ghc925.cabal-install.aarch64-darwin"@
-- - @"pkgsMusl.haskell.compiler.ghc90.x86_64-linux"@
-- - @"arion.aarch64-linux"@
newtype JobName = JobName { unJobName :: Text }
deriving stock ( Generic , Show )
deriving newtype ( Eq , FromJSONKey , FromJSON , Ord , ToJSON )
2023-03-25 09:44:26 +01:00
-- | Datatype representing the result of querying the build evals of the
-- haskell-updates Hydra jobset.
--
-- The URL <https://hydra.nixos.org/eval/EVAL_ID/builds> (where @EVAL_ID@ is a
-- value like 1792418) returns a list of 'Build'.
2021-05-04 18:16:00 +02:00
data Build = Build
2023-03-25 11:24:13 +01:00
{ job :: JobName
2021-05-08 07:13:20 +02:00
, buildstatus :: Maybe Int
2023-03-25 09:44:26 +01:00
-- ^ Status of the build. See 'getBuildState' for the meaning of each state.
2021-05-04 18:16:00 +02:00
, finished :: Int
2023-03-25 09:44:26 +01:00
-- ^ Whether or not the build is finished. @0@ if finished, non-zero otherwise.
2021-05-04 18:16:00 +02:00
, id :: Int
, nixname :: Text
2023-03-25 09:44:26 +01:00
-- ^ Nix name of the derivation.
--
-- Examples:
-- - @"lens-5.2.1"@
-- - @"cabal-install-3.8.0.1"@
-- - @"lens-static-x86_64-unknown-linux-musl-5.1.1"@
2021-05-04 18:16:00 +02:00
, system :: Text
2023-03-25 09:44:26 +01:00
-- ^ System
--
-- Examples:
-- - @"x86_64-linux"@
-- - @"aarch64-darwin"@
2021-05-04 18:16:00 +02:00
, jobsetevals :: Seq Int
}
deriving ( Generic , ToJSON , FromJSON , Show )
2023-09-03 21:54:03 +02:00
data HydraSlownessWorkaroundFlag = HydraSlownessWorkaround | NoHydraSlownessWorkaround
2023-09-03 21:39:04 +02:00
data RequestLogsFlag = RequestLogs | NoRequestLogs
2024-03-30 13:53:20 +01:00
usage :: IO a
usage = die " Usage: get-report [--slow] [EVAL-ID] | ping-maintainers | mark-broken-list [--no-request-logs] | eval-info "
2021-05-04 18:16:00 +02:00
main :: IO ()
main = do
args <- getArgs
case args of
2024-03-30 13:53:20 +01:00
" get-report " : " --slow " : id -> getBuildReports HydraSlownessWorkaround id
" get-report " : id -> getBuildReports NoHydraSlownessWorkaround id
2021-05-04 18:16:00 +02:00
[ " ping-maintainers " ] -> printMaintainerPing
2023-09-03 21:39:04 +02:00
[ " mark-broken-list " , " --no-request-logs " ] -> printMarkBrokenList NoRequestLogs
[ " mark-broken-list " ] -> printMarkBrokenList RequestLogs
2023-01-10 00:34:51 +01:00
[ " eval-info " ] -> printEvalInfo
2024-03-30 13:53:20 +01:00
_ -> usage
2021-05-04 18:16:00 +02:00
reportFileName :: IO FilePath
reportFileName = getXdgDirectory XdgCache " haskell-updates-build-report.json "
showT :: Show a => a -> Text
showT = Text . pack . show
2024-03-30 13:53:20 +01:00
getBuildReports :: HydraSlownessWorkaroundFlag -> [ String ] -> IO ()
getBuildReports opt args = runReq defaultHttpConfig do
eval @ Eval { id } <- case args of
[ id ] -> hydraJSONQuery mempty [ " eval " , Text . pack id ]
[] -> do
evalMay <- Seq . lookup 0 . evals <$> hydraJSONQuery mempty [ " jobset " , " nixpkgs " , " haskell-updates " , " evals " ]
maybe ( liftIO $ fail " No Evaluation found " ) pure evalMay
_ -> liftIO usage
2021-05-08 07:15:20 +02:00
liftIO . putStrLn $ " Fetching evaluation " <> show id <> " from Hydra. This might take a few minutes... "
2024-03-30 13:54:38 +01:00
buildReports <- getEvalBuilds opt eval
2021-05-08 07:15:20 +02:00
liftIO do
fileName <- reportFileName
putStrLn $ " Finished fetching all builds from Hydra, saving report as " <> fileName
now <- getCurrentTime
encodeFile fileName ( eval , now , buildReports )
2023-02-20 00:20:42 +01:00
2024-03-30 13:54:38 +01:00
getEvalBuilds :: HydraSlownessWorkaroundFlag -> Eval -> Req ( Seq Build )
getEvalBuilds NoHydraSlownessWorkaround Eval { id } =
2023-11-02 02:27:03 +01:00
hydraJSONQuery mempty [ " eval " , showT id , " builds " ]
2024-03-30 13:54:38 +01:00
getEvalBuilds HydraSlownessWorkaround Eval { builds } = do
2023-09-03 21:54:03 +02:00
forM builds $ \ buildId -> do
liftIO $ putStrLn $ " Querying build " <> show buildId
hydraJSONQuery mempty [ " build " , showT buildId ]
2023-02-20 00:20:42 +01:00
hydraQuery :: HttpResponse a => Proxy a -> Option 'Https -> [ Text ] -> Req ( HttpResponseBody a )
2023-11-02 02:27:03 +01:00
hydraQuery responseType option query = do
let customHeaderOpt =
header
" User-Agent "
" hydra-report.hs/v1 (nixpkgs;maintainers/scripts/haskell) pls fix https://github.com/NixOS/nixos-org-configurations/issues/270 "
customTimeoutOpt = responseTimeout 900 _000_000 -- 15 minutes
opts = customHeaderOpt <> customTimeoutOpt <> option
url = foldl' ( /: ) ( https " hydra.nixos.org " ) query
responseBody <$> req GET url NoReqBody responseType opts
2023-02-20 00:20:42 +01:00
hydraJSONQuery :: FromJSON a => Option 'Https -> [ Text ] -> Req a
hydraJSONQuery = hydraQuery jsonResponse
hydraPlainQuery :: [ Text ] -> Req ByteString
hydraPlainQuery = hydraQuery bsResponse mempty
2021-05-04 18:16:00 +02:00
2021-05-09 00:37:05 +02:00
hydraEvalCommand :: FilePath
2021-05-04 18:16:00 +02:00
hydraEvalCommand = " hydra-eval-jobs "
2021-05-15 08:53:19 +02:00
2021-05-09 00:37:05 +02:00
hydraEvalParams :: [ String ]
2021-05-04 18:16:00 +02:00
hydraEvalParams = [ " -I " , " . " , " pkgs/top-level/release-haskell.nix " ]
2021-05-15 08:53:19 +02:00
2021-09-10 00:55:12 +02:00
nixExprCommand :: FilePath
nixExprCommand = " nix-instantiate "
2021-05-15 08:53:19 +02:00
2021-09-10 00:55:12 +02:00
nixExprParams :: [ String ]
nixExprParams = [ " --eval " , " --strict " , " --json " ]
2021-05-04 18:16:00 +02:00
2021-05-16 03:43:39 +02:00
-- | This newtype is used to parse a Hydra job output from @hydra-eval-jobs@.
-- The only field we are interested in is @maintainers@, which is why this
-- is just a newtype.
--
2021-09-10 00:55:12 +02:00
-- Note that there are occasionally jobs that don't have a maintainers
2021-05-16 03:43:39 +02:00
-- field, which is why this has to be @Maybe Text@.
newtype Maintainers = Maintainers { maintainers :: Maybe Text }
deriving stock ( Generic , Show )
2021-05-15 08:53:19 +02:00
deriving anyclass ( FromJSON , ToJSON )
-- | This is a 'Map' from Hydra job name to maintainer email addresses.
--
-- It has values similar to the following:
--
-- @@
-- fromList
2021-05-16 03:43:39 +02:00
-- [ ("arion.aarch64-linux", Maintainers (Just "robert@example.com"))
-- , ("bench.x86_64-linux", Maintainers (Just ""))
-- , ("conduit.x86_64-linux", Maintainers (Just "snoy@man.com, web@ber.com"))
-- , ("lens.x86_64-darwin", Maintainers (Just "ek@category.com"))
2021-05-15 08:53:19 +02:00
-- ]
-- @@
--
-- Note that Hydra jobs without maintainers will have an empty string for the
-- maintainer list.
2023-03-25 11:24:13 +01:00
type HydraJobs = Map JobName Maintainers
2021-05-15 08:53:19 +02:00
-- | Map of email addresses to GitHub handles.
-- This is built from the file @../../maintainer-list.nix@.
--
-- It has values similar to the following:
--
-- @@
-- fromList
-- [ ("robert@example.com", "rob22")
-- , ("ek@category.com", "edkm")
-- ]
-- @@
type EmailToGitHubHandles = Map Text Text
-- | Map of Hydra jobs to maintainer GitHub handles.
--
-- It has values similar to the following:
--
-- @@
-- fromList
-- [ ("arion.aarch64-linux", ["rob22"])
-- , ("conduit.x86_64-darwin", ["snoyb", "webber"])
-- ]
-- @@
2023-03-25 11:24:13 +01:00
type MaintainerMap = Map JobName ( NonEmpty Text )
2021-05-04 18:16:00 +02:00
2021-09-10 00:55:12 +02:00
-- | Information about a package which lists its dependencies and whether the
-- package is marked broken.
data DepInfo = DepInfo {
2023-03-25 15:00:56 +01:00
deps :: Set PkgName ,
2021-09-10 00:55:12 +02:00
broken :: Bool
}
deriving stock ( Generic , Show )
deriving anyclass ( FromJSON , ToJSON )
-- | Map from package names to their DepInfo. This is the data we get out of a
-- nix call.
2023-03-25 15:00:56 +01:00
type DependencyMap = Map PkgName DepInfo
2021-09-10 00:55:12 +02:00
-- | Map from package names to its broken state, number of reverse dependencies (fst) and
-- unbroken reverse dependencies (snd).
2023-03-25 15:00:56 +01:00
type ReverseDependencyMap = Map PkgName ( Int , Int )
2021-09-10 00:55:12 +02:00
-- | Calculate the (unbroken) reverse dependencies of a package by transitively
-- going through all packages if it’ s a dependency of them.
calculateReverseDependencies :: DependencyMap -> ReverseDependencyMap
2023-03-25 15:00:56 +01:00
calculateReverseDependencies depMap =
Map . fromDistinctAscList $ zip keys ( zip ( rdepMap False ) ( rdepMap True ) )
2021-09-10 00:55:12 +02:00
where
-- This code tries to efficiently invert the dependency map and calculate
2024-01-14 17:46:48 +01:00
-- its transitive closure by internally identifying every pkg with its index
2021-09-10 00:55:12 +02:00
-- in the package list and then using memoization.
2023-03-25 15:00:56 +01:00
keys :: [ PkgName ]
2021-09-10 00:55:12 +02:00
keys = Map . keys depMap
2023-03-25 15:00:56 +01:00
pkgToIndexMap :: Map PkgName Int
2021-09-10 00:55:12 +02:00
pkgToIndexMap = Map . fromDistinctAscList ( zip keys [ 0 .. ] )
2023-03-25 15:00:56 +01:00
depInfos :: [ DepInfo ]
depInfos = Map . elems depMap
depInfoToIdx :: DepInfo -> ( Bool , [ Int ] )
depInfoToIdx DepInfo { broken , deps } =
( broken , mapMaybe ( ` Map . lookup ` pkgToIndexMap ) $ Set . toList deps )
intDeps :: [ ( Int , ( Bool , [ Int ] ) ) ]
intDeps = zip [ 0 .. ] ( fmap depInfoToIdx depInfos )
2024-01-14 17:46:48 +01:00
rdepMap onlyUnbroken = IntSet . size <$> IntMap . elems resultList
2021-09-10 00:55:12 +02:00
where
2024-01-14 17:46:48 +01:00
resultList = IntMap . fromDistinctAscList [ ( i , go i ) | i <- [ 0 .. length keys - 1 ] ]
2021-09-10 00:55:12 +02:00
oneStepMap = IntMap . fromListWith IntSet . union $ ( \ ( key , ( _ , deps ) ) -> ( , IntSet . singleton key ) <$> deps ) <=< filter ( \ ( _ , ( broken , _ ) ) -> not ( broken && onlyUnbroken ) ) $ intDeps
2024-01-14 17:46:48 +01:00
go pkg = IntSet . unions ( oneStep : ( ( resultList IntMap .! ) <$> IntSet . toList oneStep ) )
2021-09-10 00:55:12 +02:00
where oneStep = IntMap . findWithDefault mempty pkg oneStepMap
-- | Generate a mapping of Hydra job names to maintainer GitHub handles. Calls
-- hydra-eval-jobs and the nix script ./maintainer-handles.nix.
2021-05-04 18:16:00 +02:00
getMaintainerMap :: IO MaintainerMap
getMaintainerMap = do
2021-05-15 08:53:19 +02:00
hydraJobs :: HydraJobs <-
2021-09-10 00:55:12 +02:00
readJSONProcess hydraEvalCommand hydraEvalParams " Failed to decode hydra-eval-jobs output: "
2021-05-15 08:53:19 +02:00
handlesMap :: EmailToGitHubHandles <-
2021-09-10 00:55:12 +02:00
readJSONProcess nixExprCommand ( " maintainers/scripts/haskell/maintainer-handles.nix " : nixExprParams ) " Failed to decode nix output for lookup of github handles: "
2021-05-16 03:43:39 +02:00
pure $ Map . mapMaybe ( splitMaintainersToGitHubHandles handlesMap ) hydraJobs
2023-03-24 12:26:01 +01:00
where
2021-05-16 03:43:39 +02:00
-- Split a comma-spearated string of Maintainers into a NonEmpty list of
-- GitHub handles.
splitMaintainersToGitHubHandles
:: EmailToGitHubHandles -> Maintainers -> Maybe ( NonEmpty Text )
splitMaintainersToGitHubHandles handlesMap ( Maintainers maint ) =
nonEmpty . mapMaybe ( ` Map . lookup ` handlesMap ) . Text . splitOn " , " $ fromMaybe " " maint
2021-05-15 08:53:19 +02:00
2021-09-10 00:55:12 +02:00
-- | Get the a map of all dependencies of every package by calling the nix
-- script ./dependencies.nix.
getDependencyMap :: IO DependencyMap
getDependencyMap =
2023-03-25 15:00:56 +01:00
readJSONProcess
nixExprCommand
( " maintainers/scripts/haskell/dependencies.nix " : nixExprParams )
" Failed to decode nix output for lookup of dependencies: "
2021-09-10 00:55:12 +02:00
2021-05-15 08:53:19 +02:00
-- | Run a process that produces JSON on stdout and and decode the JSON to a
-- data type.
--
-- If the JSON-decoding fails, throw the JSON-decoding error.
readJSONProcess
:: FromJSON a
=> FilePath -- ^ Filename of executable.
-> [ String ] -- ^ Arguments
-> String -- ^ String to prefix to JSON-decode error.
-> IO a
2021-09-10 00:55:12 +02:00
readJSONProcess exe args err = do
output <- readProcess exe args " "
2021-05-15 08:53:19 +02:00
let eitherDecodedOutput = eitherDecodeStrict' . encodeUtf8 . Text . pack $ output
case eitherDecodedOutput of
Left decodeErr -> error $ err <> decodeErr <> " \ n Raw: ' " <> take 1000 output <> " ' "
Right decodedOutput -> pure decodedOutput
2021-05-04 18:16:00 +02:00
-- BuildStates are sorted by subjective importance/concerningness
2021-05-15 08:53:19 +02:00
data BuildState
= Failed
| DependencyFailed
| OutputLimitExceeded
| Unknown ( Maybe Int )
| TimedOut
| Canceled
| HydraFailure
| Unfinished
| Success
deriving stock ( Show , Eq , Ord )
2021-05-04 18:16:00 +02:00
icon :: BuildState -> Text
icon = \ case
2023-12-03 12:48:06 +01:00
Failed -> " ❌ "
DependencyFailed -> " ❗ "
OutputLimitExceeded -> " ⚠️ "
2021-05-04 18:16:00 +02:00
Unknown x -> " unknown code " <> showT x
2023-12-03 12:48:06 +01:00
TimedOut -> " ⌛🚫 "
Canceled -> " 🚫 "
Unfinished -> " ⏳ "
HydraFailure -> " 🚧 "
Success -> " ✅ "
2021-05-04 18:16:00 +02:00
platformIcon :: Platform -> Text
platformIcon ( Platform x ) = case x of
2023-12-03 12:48:06 +01:00
" x86_64-linux " -> " 🐧 "
" aarch64-linux " -> " 📱 "
" x86_64-darwin " -> " 🍎 "
" aarch64-darwin " -> " 🍏 "
2021-05-04 18:16:00 +02:00
_ -> x
2023-03-26 10:21:54 +02:00
platformIsOS :: OS -> Platform -> Bool
platformIsOS os ( Platform x ) = case ( os , x ) of
( Linux , " x86_64-linux " ) -> True
( Linux , " aarch64-linux " ) -> True
( Darwin , " x86_64-darwin " ) -> True
( Darwin , " aarch64-darwin " ) -> True
_ -> False
2023-03-25 15:00:56 +01:00
-- | A package name. This is parsed from a 'JobName'.
--
-- Examples:
--
-- - The 'JobName' @"haskellPackages.lens.x86_64-linux"@ produces the 'PkgName'
-- @"lens"@.
-- - The 'JobName' @"haskell.packages.ghc925.cabal-install.aarch64-darwin"@
-- produces the 'PkgName' @"cabal-install"@.
-- - The 'JobName' @"pkgsMusl.haskell.compiler.ghc90.x86_64-linux"@ produces
-- the 'PkgName' @"ghc90"@.
-- - The 'JobName' @"arion.aarch64-linux"@ produces the 'PkgName' @"arion"@.
--
-- 'PkgName' is also used as a key in 'DependencyMap' and 'ReverseDependencyMap'.
-- In this case, 'PkgName' originally comes from attribute names in @haskellPackages@
-- in Nixpkgs.
newtype PkgName = PkgName Text
deriving stock ( Generic , Show )
deriving newtype ( Eq , FromJSON , FromJSONKey , Ord , ToJSON )
-- | A package set name. This is parsed from a 'JobName'.
--
-- Examples:
--
-- - The 'JobName' @"haskellPackages.lens.x86_64-linux"@ produces the 'PkgSet'
-- @"haskellPackages"@.
-- - The 'JobName' @"haskell.packages.ghc925.cabal-install.aarch64-darwin"@
-- produces the 'PkgSet' @"haskell.packages.ghc925"@.
-- - The 'JobName' @"pkgsMusl.haskell.compiler.ghc90.x86_64-linux"@ produces
-- the 'PkgSet' @"pkgsMusl.haskell.compiler"@.
-- - The 'JobName' @"arion.aarch64-linux"@ produces the 'PkgSet' @""@.
--
-- As you can see from the last example, 'PkgSet' can be empty (@""@) for
-- top-level jobs.
newtype PkgSet = PkgSet Text
deriving stock ( Generic , Show )
deriving newtype ( Eq , FromJSON , FromJSONKey , Ord , ToJSON )
2021-05-04 18:16:00 +02:00
data BuildResult = BuildResult { state :: BuildState , id :: Int } deriving ( Show , Eq , Ord )
newtype Platform = Platform { platform :: Text } deriving ( Show , Eq , Ord )
2021-09-10 00:55:12 +02:00
data SummaryEntry = SummaryEntry {
2023-03-25 15:00:56 +01:00
summaryBuilds :: Table PkgSet Platform BuildResult ,
2021-09-10 00:55:12 +02:00
summaryMaintainers :: Set Text ,
summaryReverseDeps :: Int ,
summaryUnbrokenReverseDeps :: Int
}
2023-03-25 15:00:56 +01:00
type StatusSummary = Map PkgName SummaryEntry
2021-05-04 18:16:00 +02:00
2023-03-26 10:21:54 +02:00
data OS = Linux | Darwin
2023-03-25 10:21:55 +01:00
newtype Table row col a = Table ( Map ( row , col ) a )
singletonTable :: row -> col -> a -> Table row col a
singletonTable row col a = Table $ Map . singleton ( row , col ) a
unionTable :: ( Ord row , Ord col ) => Table row col a -> Table row col a -> Table row col a
unionTable ( Table l ) ( Table r ) = Table $ Map . union l r
2023-03-24 12:55:52 +01:00
2023-03-26 10:21:54 +02:00
filterWithKeyTable :: ( row -> col -> a -> Bool ) -> Table row col a -> Table row col a
filterWithKeyTable f ( Table t ) = Table $ Map . filterWithKey ( \ ( r , c ) a -> f r c a ) t
nullTable :: Table row col a -> Bool
nullTable ( Table t ) = Map . null t
2021-05-04 18:16:00 +02:00
instance ( Ord row , Ord col , Semigroup a ) => Semigroup ( Table row col a ) where
Table l <> Table r = Table ( Map . unionWith ( <> ) l r )
instance ( Ord row , Ord col , Semigroup a ) => Monoid ( Table row col a ) where
mempty = Table Map . empty
instance Functor ( Table row col ) where
fmap f ( Table a ) = Table ( fmap f a )
instance Foldable ( Table row col ) where
foldMap f ( Table a ) = foldMap f a
2023-02-20 00:20:42 +01:00
getBuildState :: Build -> BuildState
getBuildState Build { finished , buildstatus } = case ( finished , buildstatus ) of
( 0 , _ ) -> Unfinished
( _ , Just 0 ) -> Success
( _ , Just 1 ) -> Failed
( _ , Just 2 ) -> DependencyFailed
( _ , Just 3 ) -> HydraFailure
( _ , Just 4 ) -> Canceled
( _ , Just 7 ) -> TimedOut
( _ , Just 11 ) -> OutputLimitExceeded
( _ , i ) -> Unknown i
2023-03-25 10:21:55 +01:00
combineStatusSummaries :: Seq StatusSummary -> StatusSummary
combineStatusSummaries = foldl ( Map . unionWith unionSummary ) Map . empty
2021-05-04 18:16:00 +02:00
where
2023-03-24 12:55:52 +01:00
unionSummary :: SummaryEntry -> SummaryEntry -> SummaryEntry
2023-03-25 10:21:55 +01:00
unionSummary ( SummaryEntry lb lm lr lu ) ( SummaryEntry rb rm rr ru ) =
SummaryEntry ( unionTable lb rb ) ( lm <> rm ) ( max lr rr ) ( max lu ru )
2023-03-24 12:55:52 +01:00
2023-03-25 15:00:56 +01:00
buildToPkgNameAndSet :: Build -> ( PkgName , PkgSet )
buildToPkgNameAndSet Build { job = JobName jobName , system } = ( name , set )
2023-03-25 10:21:55 +01:00
where
packageName :: Text
2023-03-25 11:24:13 +01:00
packageName = fromMaybe jobName ( Text . stripSuffix ( " . " <> system ) jobName )
2023-03-24 12:55:52 +01:00
2023-03-25 10:21:55 +01:00
splitted :: Maybe ( NonEmpty Text )
splitted = nonEmpty $ Text . splitOn " . " packageName
2023-03-24 12:55:52 +01:00
2023-03-25 15:00:56 +01:00
name :: PkgName
name = PkgName $ maybe packageName NonEmpty . last splitted
2023-03-24 12:55:52 +01:00
2023-03-25 15:00:56 +01:00
set :: PkgSet
set = PkgSet $ maybe " " ( Text . intercalate " . " . NonEmpty . init ) splitted
buildToStatusSummary :: MaintainerMap -> ReverseDependencyMap -> Build -> StatusSummary
buildToStatusSummary maintainerMap reverseDependencyMap build @ Build { job , id , system } =
Map . singleton pkgName summaryEntry
where
( pkgName , pkgSet ) = buildToPkgNameAndSet build
2023-03-24 12:55:52 +01:00
2023-03-25 10:21:55 +01:00
maintainers :: Set Text
maintainers = maybe mempty ( Set . fromList . toList ) ( Map . lookup job maintainerMap )
2023-03-24 12:55:52 +01:00
2023-03-25 15:00:56 +01:00
( reverseDeps , unbrokenReverseDeps ) =
Map . findWithDefault ( 0 , 0 ) pkgName reverseDependencyMap
2021-05-04 18:16:00 +02:00
2023-03-25 15:00:56 +01:00
buildTable :: Table PkgSet Platform BuildResult
2023-03-25 10:21:55 +01:00
buildTable =
2023-03-25 15:00:56 +01:00
singletonTable pkgSet ( Platform system ) ( BuildResult ( getBuildState build ) id )
2023-03-24 12:55:52 +01:00
2023-03-25 10:21:55 +01:00
summaryEntry = SummaryEntry buildTable maintainers reverseDeps unbrokenReverseDeps
2023-03-24 12:55:52 +01:00
2021-05-04 18:16:00 +02:00
readBuildReports :: IO ( Eval , UTCTime , Seq Build )
readBuildReports = do
file <- reportFileName
fromMaybe ( error $ " Could not decode " <> file ) <$> decodeFileStrict' file
sep :: Text
sep = " | "
joinTable :: [ Text ] -> Text
joinTable t = sep <> Text . intercalate sep t <> sep
type NumSummary = Table Platform BuildState Int
printTable :: ( Ord rows , Ord cols ) => Text -> ( rows -> Text ) -> ( cols -> Text ) -> ( entries -> Text ) -> Table rows cols entries -> [ Text ]
printTable name showR showC showE ( Table mapping ) = joinTable <$> ( name : map showC cols ) : replicate ( length cols + sepsInName + 1 ) " --- " : map printRow rows
where
sepsInName = Text . count " | " name
printRow row = showR row : map ( \ col -> maybe " " showE ( Map . lookup ( row , col ) mapping ) ) cols
rows = toList $ Set . fromList ( fst <$> Map . keys mapping )
cols = toList $ Set . fromList ( snd <$> Map . keys mapping )
2023-03-25 15:00:56 +01:00
printJob :: Int -> PkgName -> ( Table PkgSet Platform BuildResult , Text ) -> [ Text ]
printJob evalId ( PkgName name ) ( Table mapping , maintainers ) =
2021-05-04 18:16:00 +02:00
if length sets <= 1
then map printSingleRow sets
2023-03-25 15:00:56 +01:00
else [ " - [ ] " <> makeJobSearchLink ( PkgSet " " ) name <> " " <> maintainers ] <> map printRow sets
2021-05-04 18:16:00 +02:00
where
2023-03-25 15:00:56 +01:00
printRow :: PkgSet -> Text
printRow ( PkgSet set ) =
" - " <> printState ( PkgSet set ) <> " " <>
makeJobSearchLink ( PkgSet set ) ( if Text . null set then " toplevel " else set )
printSingleRow set =
" - [ ] " <> printState set <> " " <>
makeJobSearchLink set ( makePkgName set ) <> " " <> maintainers
makePkgName :: PkgSet -> Text
makePkgName ( PkgSet set ) = ( if Text . null set then " " else set <> " . " ) <> name
printState set =
Text . intercalate " " $ map ( \ pf -> maybe " " ( label pf ) $ Map . lookup ( set , pf ) mapping ) platforms
makeJobSearchLink :: PkgSet -> Text -> Text
makeJobSearchLink set linkLabel = makeSearchLink evalId linkLabel ( makePkgName set )
sets :: [ PkgSet ]
2021-05-04 18:16:00 +02:00
sets = toList $ Set . fromList ( fst <$> Map . keys mapping )
2023-03-25 15:00:56 +01:00
platforms :: [ Platform ]
2021-05-04 18:16:00 +02:00
platforms = toList $ Set . fromList ( snd <$> Map . keys mapping )
2023-03-25 15:00:56 +01:00
2021-05-04 18:16:00 +02:00
label pf ( BuildResult s i ) = " [[ " <> platformIcon pf <> icon s <> " ]](https://hydra.nixos.org/build/ " <> showT i <> " ) "
2021-05-09 15:13:07 +02:00
makeSearchLink :: Int -> Text -> Text -> Text
makeSearchLink evalId linkLabel query = " [ " <> linkLabel <> " ]( " <> " https://hydra.nixos.org/eval/ " <> showT evalId <> " ?filter= " <> query <> " ) "
2021-05-04 18:16:00 +02:00
statusToNumSummary :: StatusSummary -> NumSummary
statusToNumSummary = fmap getSum . foldMap ( fmap Sum . jobTotals )
2021-09-10 00:55:12 +02:00
jobTotals :: SummaryEntry -> Table Platform BuildState Int
jobTotals ( summaryBuilds -> Table mapping ) = getSum <$> Table ( Map . foldMapWithKey ( \ ( _ , platform ) ( BuildResult buildstate _ ) -> Map . singleton ( platform , buildstate ) ( Sum 1 ) ) mapping )
2021-05-04 18:16:00 +02:00
details :: Text -> [ Text ] -> [ Text ]
details summary content = [ " <details><summary> " <> summary <> " </summary> " , " " ] <> content <> [ " </details> " , " " ]
2023-01-10 00:34:51 +01:00
evalLine :: Eval -> UTCTime -> Text
evalLine Eval { id , jobsetevalinputs = JobsetEvalInputs { nixpkgs = Nixpkgs { revision } } } fetchTime =
2023-03-24 12:26:01 +01:00
" *evaluation [ "
<> showT id
<> " ](https://hydra.nixos.org/eval/ "
<> showT id
<> " ) of nixpkgs commit [ "
<> Text . take 7 revision
<> " ](https://github.com/NixOS/nixpkgs/commits/ "
<> revision
<> " ) as of "
<> Text . pack ( formatTime defaultTimeLocale " %Y-%m-%d %H:%M UTC " fetchTime )
<> " * "
2023-01-10 00:34:51 +01:00
2023-03-25 15:00:56 +01:00
printBuildSummary :: Eval -> UTCTime -> StatusSummary -> [ ( PkgName , Int ) ] -> Text
2023-01-10 00:34:51 +01:00
printBuildSummary eval @ Eval { id } fetchTime summary topBrokenRdeps =
2023-03-24 12:26:01 +01:00
Text . unlines $
headline <> [ " " ] <> tldr <> ( ( " * " <> ) <$> ( errors <> warnings ) ) <> [ " " ]
<> totals
2023-03-26 10:21:54 +02:00
<> optionalList " #### Maintained Linux packages with build failure " ( maintainedList ( fails summaryLinux ) )
<> optionalList " #### Maintained Linux packages with failed dependency " ( maintainedList ( failedDeps summaryLinux ) )
<> optionalList " #### Maintained Linux packages with unknown error " ( maintainedList ( unknownErr summaryLinux ) )
<> optionalHideableList " #### Maintained Darwin packages with build failure " ( maintainedList ( fails summaryDarwin ) )
<> optionalHideableList " #### Maintained Darwin packages with failed dependency " ( maintainedList ( failedDeps summaryDarwin ) )
<> optionalHideableList " #### Maintained Darwin packages with unknown error " ( maintainedList ( unknownErr summaryDarwin ) )
<> optionalHideableList " #### Unmaintained packages with build failure " ( unmaintainedList ( fails summary ) )
<> optionalHideableList " #### Unmaintained packages with failed dependency " ( unmaintainedList ( failedDeps summary ) )
<> optionalHideableList " #### Unmaintained packages with unknown error " ( unmaintainedList ( unknownErr summary ) )
2023-03-24 12:26:01 +01:00
<> optionalHideableList " #### Top 50 broken packages, sorted by number of reverse dependencies " ( brokenLine <$> topBrokenRdeps )
2023-12-03 12:48:06 +01:00
<> [ " " , " *⤴️: The number of packages that depend (directly or indirectly) on this package (if any). If two numbers are shown the first (lower) number considers only packages which currently have enabled hydra jobs, i.e. are not marked broken. The second (higher) number considers all packages.* " , " " ]
2023-03-24 12:26:01 +01:00
<> footer
where
footer = [ " *Report generated with [maintainers/scripts/haskell/hydra-report.hs](https://github.com/NixOS/nixpkgs/blob/haskell-updates/maintainers/scripts/haskell/hydra-report.hs)* " ]
2023-03-25 15:00:56 +01:00
2023-03-24 12:26:01 +01:00
headline =
[ " ### [haskell-updates build report from hydra](https://hydra.nixos.org/jobset/nixpkgs/haskell-updates) "
2023-03-25 15:00:56 +01:00
, evalLine eval fetchTime
]
totals :: [ Text ]
2023-03-24 12:26:01 +01:00
totals =
[ " #### Build summary "
, " "
2023-03-25 15:00:56 +01:00
] <>
printTable
" Platform "
( \ x -> makeSearchLink id ( platform x <> " " <> platformIcon x ) ( " . " <> platform x ) )
( \ x -> showT x <> " " <> icon x )
showT
numSummary
brokenLine :: ( PkgName , Int ) -> Text
brokenLine ( PkgName name , rdeps ) =
" [ " <> name <> " ](https://packdeps.haskellers.com/reverse/ " <> name <>
2023-12-03 12:48:06 +01:00
" ) ⤴️ " <> Text . pack ( show rdeps ) <> " "
2023-03-25 15:00:56 +01:00
2023-03-24 12:26:01 +01:00
numSummary = statusToNumSummary summary
2023-03-24 12:55:52 +01:00
2023-03-26 10:21:54 +02:00
summaryLinux :: StatusSummary
summaryLinux = withOS Linux summary
summaryDarwin :: StatusSummary
summaryDarwin = withOS Darwin summary
-- Remove all BuildResult from the Table that have Platform that isn't for
-- the given OS.
tableForOS :: OS -> Table PkgSet Platform BuildResult -> Table PkgSet Platform BuildResult
tableForOS os = filterWithKeyTable ( \ _ platform _ -> platformIsOS os platform )
-- Remove all BuildResult from the StatusSummary that have a Platform that
-- isn't for the given OS. Completely remove all PkgName from StatusSummary
-- that end up with no BuildResults.
withOS
:: OS
-> StatusSummary
-> StatusSummary
withOS os =
Map . mapMaybe
( \ e @ SummaryEntry { summaryBuilds } ->
let buildsForOS = tableForOS os summaryBuilds
in if nullTable buildsForOS then Nothing else Just e { summaryBuilds = buildsForOS }
)
jobsByState :: ( BuildState -> Bool ) -> StatusSummary -> StatusSummary
jobsByState predicate = Map . filter ( predicate . worstState )
2023-03-24 12:55:52 +01:00
worstState :: SummaryEntry -> BuildState
2023-03-24 12:26:01 +01:00
worstState = foldl' min Success . fmap state . summaryBuilds
2023-03-24 12:55:52 +01:00
2023-03-26 10:21:54 +02:00
fails :: StatusSummary -> StatusSummary
2023-03-24 12:26:01 +01:00
fails = jobsByState ( == Failed )
2023-03-24 12:55:52 +01:00
2023-03-26 10:21:54 +02:00
failedDeps :: StatusSummary -> StatusSummary
2023-03-24 12:26:01 +01:00
failedDeps = jobsByState ( == DependencyFailed )
2023-03-25 15:00:56 +01:00
2023-03-26 10:21:54 +02:00
unknownErr :: StatusSummary -> StatusSummary
2023-03-24 12:26:01 +01:00
unknownErr = jobsByState ( \ x -> x > DependencyFailed && x < TimedOut )
2023-03-25 15:00:56 +01:00
withMaintainer :: StatusSummary -> Map PkgName ( Table PkgSet Platform BuildResult , NonEmpty Text )
withMaintainer =
Map . mapMaybe
( \ e -> ( summaryBuilds e , ) <$> nonEmpty ( Set . toList ( summaryMaintainers e ) ) )
withoutMaintainer :: StatusSummary -> StatusSummary
2023-03-24 12:26:01 +01:00
withoutMaintainer = Map . mapMaybe ( \ e -> if Set . null ( summaryMaintainers e ) then Just e else Nothing )
2023-03-25 15:00:56 +01:00
optionalList :: Text -> [ Text ] -> [ Text ]
2023-03-24 12:26:01 +01:00
optionalList heading list = if null list then mempty else [ heading ] <> list
2023-03-25 15:00:56 +01:00
optionalHideableList :: Text -> [ Text ] -> [ Text ]
2023-03-24 12:26:01 +01:00
optionalHideableList heading list = if null list then mempty else [ heading ] <> details ( showT ( length list ) <> " job(s) " ) list
2023-03-25 15:00:56 +01:00
maintainedList :: StatusSummary -> [ Text ]
2023-03-24 12:26:01 +01:00
maintainedList = showMaintainedBuild <=< Map . toList . withMaintainer
2023-03-25 15:00:56 +01:00
summaryEntryGetReverseDeps :: SummaryEntry -> ( Int , Int )
summaryEntryGetReverseDeps sumEntry =
( negate $ summaryUnbrokenReverseDeps sumEntry
, negate $ summaryReverseDeps sumEntry
)
sortOnReverseDeps :: [ ( PkgName , SummaryEntry ) ] -> [ ( PkgName , SummaryEntry ) ]
sortOnReverseDeps = sortOn ( \ ( _ , sumEntry ) -> summaryEntryGetReverseDeps sumEntry )
unmaintainedList :: StatusSummary -> [ Text ]
unmaintainedList = showBuild <=< sortOnReverseDeps . Map . toList . withoutMaintainer
showBuild :: ( PkgName , SummaryEntry ) -> [ Text ]
showBuild ( name , entry ) =
printJob
id
name
( summaryBuilds entry
, Text . pack
( if summaryReverseDeps entry > 0
then
2023-12-03 12:48:06 +01:00
" ⤴️ " <> show ( summaryUnbrokenReverseDeps entry ) <>
2023-03-25 15:00:56 +01:00
" | " <> show ( summaryReverseDeps entry )
else " "
)
)
showMaintainedBuild
:: ( PkgName , ( Table PkgSet Platform BuildResult , NonEmpty Text ) ) -> [ Text ]
showMaintainedBuild ( name , ( table , maintainers ) ) =
printJob
id
name
( table
, Text . intercalate " " ( fmap ( " @ " <> ) ( toList maintainers ) )
)
2023-03-24 12:26:01 +01:00
tldr = case ( errors , warnings ) of
2023-12-03 12:48:06 +01:00
( [] , [] ) -> [ " 🟢 **Ready to merge** (if there are no [evaluation errors](https://hydra.nixos.org/jobset/nixpkgs/haskell-updates)) " ]
( [] , _ ) -> [ " 🟡 **Potential issues** (and possibly [evaluation errors](https://hydra.nixos.org/jobset/nixpkgs/haskell-updates)) " ]
_ -> [ " 🔴 **Branch not mergeable** " ]
2023-03-24 12:26:01 +01:00
warnings =
if' ( Unfinished > maybe Success worstState maintainedJob ) " `maintained` jobset failed. " <>
if' ( Unfinished == maybe Success worstState mergeableJob ) " `mergeable` jobset is not finished. " <>
if' ( Unfinished == maybe Success worstState maintainedJob ) " `maintained` jobset is not finished. "
errors =
if' ( isNothing mergeableJob ) " No `mergeable` job found. " <>
if' ( isNothing maintainedJob ) " No `maintained` job found. " <>
if' ( Unfinished > maybe Success worstState mergeableJob ) " `mergeable` jobset failed. " <>
if' ( outstandingJobs ( Platform " x86_64-linux " ) > 100 ) " Too many outstanding jobs on x86_64-linux. " <>
2023-03-26 10:25:54 +02:00
if' ( outstandingJobs ( Platform " aarch64-linux " ) > 100 ) " Too many outstanding jobs on aarch64-linux. "
2023-03-24 12:26:01 +01:00
if' p e = if p then [ e ] else mempty
2023-03-26 10:25:54 +02:00
2023-03-24 12:26:01 +01:00
outstandingJobs platform | Table m <- numSummary = Map . findWithDefault 0 ( platform , Unfinished ) m
2023-03-26 10:25:54 +02:00
2023-03-25 15:00:56 +01:00
maintainedJob = Map . lookup ( PkgName " maintained " ) summary
mergeableJob = Map . lookup ( PkgName " mergeable " ) summary
2021-05-04 18:16:00 +02:00
2023-01-10 00:34:51 +01:00
printEvalInfo :: IO ()
printEvalInfo = do
( eval , fetchTime , _ ) <- readBuildReports
putStrLn ( Text . unpack $ evalLine eval fetchTime )
2021-05-04 18:16:00 +02:00
printMaintainerPing :: IO ()
printMaintainerPing = do
2021-09-10 00:55:12 +02:00
( maintainerMap , ( reverseDependencyMap , topBrokenRdeps ) ) <- concurrently getMaintainerMap do
depMap <- getDependencyMap
rdepMap <- evaluate . calculateReverseDependencies $ depMap
let tops = take 50 . sortOn ( negate . snd ) . fmap ( second fst ) . filter ( \ x -> maybe False broken $ Map . lookup ( fst x ) depMap ) . Map . toList $ rdepMap
pure ( rdepMap , tops )
2021-05-04 18:16:00 +02:00
( eval , fetchTime , buildReport ) <- readBuildReports
2023-03-25 10:21:55 +01:00
let statusSummaries =
fmap ( buildToStatusSummary maintainerMap reverseDependencyMap ) buildReport
buildSum :: StatusSummary
buildSum = combineStatusSummaries statusSummaries
2023-03-25 09:44:26 +01:00
textBuildSummary = printBuildSummary eval fetchTime buildSum topBrokenRdeps
Text . putStrLn textBuildSummary
2021-05-04 18:16:00 +02:00
2023-09-03 21:39:04 +02:00
printMarkBrokenList :: RequestLogsFlag -> IO ()
printMarkBrokenList reqLogs = do
2023-02-20 00:20:42 +01:00
( _ , fetchTime , buildReport ) <- readBuildReports
runReq defaultHttpConfig $ forM_ buildReport \ build @ Build { job , id } ->
2023-03-25 11:24:13 +01:00
case ( getBuildState build , Text . splitOn " . " $ unJobName job ) of
2023-02-20 00:20:42 +01:00
( Failed , [ " haskellPackages " , name , " x86_64-linux " ] ) -> do
-- We use the last probable error cause found in the build log file.
2023-09-03 21:39:04 +02:00
error_message <- fromMaybe " failure " <$>
case reqLogs of
NoRequestLogs -> pure Nothing
RequestLogs -> do
-- Fetch build log from hydra to figure out the cause of the error.
build_log <- ByteString . lines <$> hydraPlainQuery [ " build " , showT id , " nixlog " , " 1 " , " raw " ]
pure $ safeLast $ mapMaybe probableErrorCause build_log
2023-02-20 00:20:42 +01:00
liftIO $ putStrLn $ " - " <> Text . unpack name <> " # " <> error_message <> " in job https://hydra.nixos.org/build/ " <> show id <> " at " <> formatTime defaultTimeLocale " %Y-%m-%d " fetchTime
2021-05-04 18:16:00 +02:00
_ -> pure ()
2023-02-20 00:20:42 +01:00
{- | This function receives a line from a Nix Haskell builder build log and returns a possible error cause.
| We might need to add other causes in the future if errors happen in unusual parts of the builder .
- }
probableErrorCause :: ByteString -> Maybe String
probableErrorCause " Setup: Encountered missing or private dependencies: " = Just " dependency missing "
probableErrorCause " running tests " = Just " test failure "
probableErrorCause build_line | ByteString . isPrefixOf " Building " build_line = Just ( " failure building " <> fromUTF8BS ( fst $ ByteString . breakSubstring " for " $ ByteString . drop 9 build_line ) )
probableErrorCause build_line | ByteString . isSuffixOf " Phase " build_line = Just ( " failure in " <> fromUTF8BS build_line )
probableErrorCause _ = Nothing