packages feed

hercules-ci-api-agent 0.5.0.1 → 0.5.1.0

raw patch · 16 files changed

+136/−84 lines, 16 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Hercules.API.Agent.Build.BuildEvent.OutputInfo: OutputInfo :: Text -> Text -> Text -> Text -> Integer -> OutputInfo
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: [deriver] :: OutputInfo -> Text
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: [hash] :: OutputInfo -> Text
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: [name] :: OutputInfo -> Text
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: [path] :: OutputInfo -> Text
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: [size] :: OutputInfo -> Integer
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: data OutputInfo
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: instance Control.DeepSeq.NFData Hercules.API.Agent.Build.BuildEvent.OutputInfo.OutputInfo
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: instance Data.Aeson.Types.FromJSON.FromJSON Hercules.API.Agent.Build.BuildEvent.OutputInfo.OutputInfo
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: instance Data.Aeson.Types.ToJSON.ToJSON Hercules.API.Agent.Build.BuildEvent.OutputInfo.OutputInfo
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: instance GHC.Classes.Eq Hercules.API.Agent.Build.BuildEvent.OutputInfo.OutputInfo
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: instance GHC.Generics.Generic Hercules.API.Agent.Build.BuildEvent.OutputInfo.OutputInfo
- Hercules.API.Agent.Build.BuildEvent.OutputInfo: instance GHC.Show.Show Hercules.API.Agent.Build.BuildEvent.OutputInfo.OutputInfo
+ Hercules.API.Agent.Evaluate.EvaluateEvent: SubstitutionQueryResult :: SubstitutionQueryResult -> EvaluateEvent
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: SubstitutionQueryResult :: !Text -> !Text -> !Text -> !Maybe OutputInfo -> SubstitutionQueryResult
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: [derivation] :: SubstitutionQueryResult -> !Text
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: [outputInfo] :: SubstitutionQueryResult -> !Maybe OutputInfo
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: [outputName] :: SubstitutionQueryResult -> !Text
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: [storeURI] :: SubstitutionQueryResult -> !Text
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: data SubstitutionQueryResult
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: instance Control.DeepSeq.NFData Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult.SubstitutionQueryResult
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: instance Data.Aeson.Types.FromJSON.FromJSON Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult.SubstitutionQueryResult
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: instance Data.Aeson.Types.ToJSON.ToJSON Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult.SubstitutionQueryResult
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: instance GHC.Classes.Eq Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult.SubstitutionQueryResult
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: instance GHC.Generics.Generic Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult.SubstitutionQueryResult
+ Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult: instance GHC.Show.Show Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult.SubstitutionQueryResult
+ Hercules.API.Agent.OutputInfo: OutputInfo :: Text -> Text -> Text -> Text -> Integer -> Maybe [Text] -> OutputInfo
+ Hercules.API.Agent.OutputInfo: [deriver] :: OutputInfo -> Text
+ Hercules.API.Agent.OutputInfo: [hash] :: OutputInfo -> Text
+ Hercules.API.Agent.OutputInfo: [name] :: OutputInfo -> Text
+ Hercules.API.Agent.OutputInfo: [path] :: OutputInfo -> Text
+ Hercules.API.Agent.OutputInfo: [references] :: OutputInfo -> Maybe [Text]
+ Hercules.API.Agent.OutputInfo: [size] :: OutputInfo -> Integer
+ Hercules.API.Agent.OutputInfo: data OutputInfo
+ Hercules.API.Agent.OutputInfo: instance Control.DeepSeq.NFData Hercules.API.Agent.OutputInfo.OutputInfo
+ Hercules.API.Agent.OutputInfo: instance Data.Aeson.Types.FromJSON.FromJSON Hercules.API.Agent.OutputInfo.OutputInfo
+ Hercules.API.Agent.OutputInfo: instance Data.Aeson.Types.ToJSON.ToJSON Hercules.API.Agent.OutputInfo.OutputInfo
+ Hercules.API.Agent.OutputInfo: instance GHC.Classes.Eq Hercules.API.Agent.OutputInfo.OutputInfo
+ Hercules.API.Agent.OutputInfo: instance GHC.Generics.Generic Hercules.API.Agent.OutputInfo.OutputInfo
+ Hercules.API.Agent.OutputInfo: instance GHC.Show.Show Hercules.API.Agent.OutputInfo.OutputInfo
+ Hercules.Formats.Mountable: Mountable :: !Text -> !Bool -> !Condition -> Mountable
+ Hercules.Formats.Mountable: [condition] :: Mountable -> !Condition
+ Hercules.Formats.Mountable: [readOnly] :: Mountable -> !Bool
+ Hercules.Formats.Mountable: [source] :: Mountable -> !Text
+ Hercules.Formats.Mountable: data Mountable
+ Hercules.Formats.Mountable: instance Data.Aeson.Types.FromJSON.FromJSON Hercules.Formats.Mountable.Mountable
+ Hercules.Formats.Mountable: instance Data.Aeson.Types.ToJSON.ToJSON Hercules.Formats.Mountable.Mountable
+ Hercules.Formats.Mountable: instance GHC.Classes.Eq Hercules.Formats.Mountable.Mountable
+ Hercules.Formats.Mountable: instance GHC.Generics.Generic Hercules.Formats.Mountable.Mountable
+ Hercules.Formats.Mountable: instance GHC.Show.Show Hercules.Formats.Mountable.Mountable
+ Hercules.Formats.Secret: Const :: Bool -> Condition

Files

CHANGELOG.md view
@@ -5,6 +5,14 @@  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## 0.5.1.0 - 2024-02-12++### Added++ - `Mountable` configuration format+ - Constant booleans in `Condition` expressions+ - `SubstitutionQueryResult` evaluation event+ ## 0.5.0.1 - 2023-06-28   - Maintenance release
hercules-ci-api-agent.cabal view
@@ -1,6 +1,6 @@ cabal-version:      1.12 name:               hercules-ci-api-agent-version:            0.5.0.1+version:            0.5.1.0 synopsis:   API definition for Hercules CI Agent to talk to hercules-ci.com or Hercules CI Enterprise @@ -23,7 +23,6 @@     Hercules.API.Agent     Hercules.API.Agent.Build     Hercules.API.Agent.Build.BuildEvent-    Hercules.API.Agent.Build.BuildEvent.OutputInfo     Hercules.API.Agent.Build.BuildEvent.Pushed     Hercules.API.Agent.Build.BuildTask     Hercules.API.Agent.Effect.EffectTask@@ -38,6 +37,7 @@     Hercules.API.Agent.Evaluate.EvaluateEvent.BuildRequired     Hercules.API.Agent.Evaluate.EvaluateEvent.DerivationInfo     Hercules.API.Agent.Evaluate.EvaluateEvent.InputDeclaration+    Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult     Hercules.API.Agent.Evaluate.EvaluateEvent.JobConfig     Hercules.API.Agent.Evaluate.EvaluateEvent.Message     Hercules.API.Agent.Evaluate.EvaluateEvent.OnPushHandlerEvent@@ -54,6 +54,7 @@     Hercules.API.Agent.LifeCycle.CreateAgentSession_V2     Hercules.API.Agent.LifeCycle.ServiceInfo     Hercules.API.Agent.LifeCycle.StartInfo+    Hercules.API.Agent.OutputInfo     Hercules.API.Agent.Socket.AgentPayload     Hercules.API.Agent.Socket.Frame     Hercules.API.Agent.Socket.ServicePayload@@ -67,6 +68,7 @@     Hercules.API.TaskStatus     Hercules.Formats.CachixCache     Hercules.Formats.Common+    Hercules.Formats.Mountable     Hercules.Formats.NixCache     Hercules.Formats.Secret @@ -130,6 +132,7 @@     Hercules.API.Agent.LifeCycle.AgentInfoSpec     Hercules.Formats.CachixCacheSpec     Hercules.Formats.SecretSpec+    Hercules.Formats.MountableSpec     Spec    hs-source-dirs:     test
src/Hercules/API/Agent/Build/BuildEvent.hs view
@@ -2,11 +2,11 @@  module Hercules.API.Agent.Build.BuildEvent where -import Hercules.API.Agent.Build.BuildEvent.OutputInfo-  ( OutputInfo,-  ) import Hercules.API.Agent.Build.BuildEvent.Pushed   ( Pushed,+  )+import Hercules.API.Agent.OutputInfo+  ( OutputInfo,   ) import Hercules.API.Prelude 
− src/Hercules/API/Agent/Build/BuildEvent/OutputInfo.hs
@@ -1,19 +0,0 @@-{-# LANGUAGE DeriveAnyClass #-}--module Hercules.API.Agent.Build.BuildEvent.OutputInfo where--import Hercules.API.Prelude--data OutputInfo = OutputInfo-  { -- | store path ending in .drv-    deriver :: Text,-    -- | e.g. out, dev-    name :: Text,-    -- | store path-    path :: Text,-    -- | typically sha256:...-    hash :: Text,-    -- | nar size in bytes-    size :: Integer-  }-  deriving (Generic, Show, Eq, NFData, ToJSON, FromJSON)
src/Hercules/API/Agent/Evaluate/EvaluateEvent.hs view
@@ -14,6 +14,7 @@ import Hercules.API.Agent.Evaluate.EvaluateEvent.OnPushHandlerEvent (OnPushHandlerEvent) import Hercules.API.Agent.Evaluate.EvaluateEvent.OnScheduleHandlerEvent (OnScheduleHandlerEvent) import Hercules.API.Agent.Evaluate.EvaluateEvent.PushedAll (PushedAll)+import Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult (SubstitutionQueryResult) import Hercules.API.Prelude  data EvaluateEvent@@ -25,6 +26,7 @@   | DerivationInfo DerivationInfo   | PushedAll PushedAll   | BuildRequired BuildRequired+  | SubstitutionQueryResult SubstitutionQueryResult   | BuildRequest BuildRequest   | JobConfig JobConfig   | OnPushHandlerEvent OnPushHandlerEvent
+ src/Hercules/API/Agent/Evaluate/EvaluateEvent/SubstitutionQueryResult.hs view
@@ -0,0 +1,23 @@+{-# LANGUAGE DeriveAnyClass #-}++module Hercules.API.Agent.Evaluate.EvaluateEvent.SubstitutionQueryResult+  ( SubstitutionQueryResult (..),+  )+where++import Hercules.API.Agent.OutputInfo (OutputInfo)+import Hercules.API.Prelude++data SubstitutionQueryResult = SubstitutionQueryResult+  { storeURI :: !Text,+    -- | NB: does not necessarily match outputInfo.derivation+    derivation :: !Text,+    -- | NB: does not necessarily match outputInfo.name+    outputName :: !Text,+    -- | NB: does not necessarily match derivation and outputName+    --+    -- 'Nothing': not substitutable+    -- 'Just': substitutable, and expect the following metadata+    outputInfo :: !(Maybe OutputInfo)+  }+  deriving (Generic, Show, Eq, NFData, FromJSON, ToJSON)
+ src/Hercules/API/Agent/OutputInfo.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE DeriveAnyClass #-}++module Hercules.API.Agent.OutputInfo where++import Hercules.API.Prelude++-- | Produced by both build tasks and evaluation tasks+data OutputInfo = OutputInfo+  { -- | store path ending in .drv+    deriver :: Text,+    -- | e.g. out, dev+    name :: Text,+    -- | store path+    path :: Text,+    -- | typically sha256:...+    hash :: Text,+    -- | nar size in bytes+    size :: Integer,+    -- | output references in store path basename form+    --+    -- Maybe for backcompat; older agents have not reported the output references.+    references :: Maybe [Text]+  }+  deriving (Generic, Show, Eq, NFData, ToJSON, FromJSON)
src/Hercules/API/Agent/Socket/Frame.hs view
@@ -25,7 +25,7 @@ mapOob _ (Ack a) = Ack a mapOob _ (Exception e) = Exception e -removeOob :: Alternative f => Frame o a -> f (Frame Void a)+removeOob :: (Alternative f) => Frame o a -> f (Frame Void a) removeOob (Msg a b) = pure $ Msg a b removeOob (Ack a) = pure $ Ack a removeOob Oob {} = empty
src/Hercules/Formats/CachixCache.hs view
@@ -29,10 +29,10 @@       ( "kind"           .= String "CachixCache"           <> "signingKeys"-          .= signingKeys a+            .= signingKeys a           <> foldMap ("authToken" .=) (authToken a)           <> "publicKeys"-          .= publicKeys a+            .= publicKeys a       )  instance FromJSON CachixCache where
+ src/Hercules/Formats/Mountable.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE DeriveAnyClass #-}++module Hercules.Formats.Mountable where++import qualified Data.Aeson as A+import Data.Text (Text)+import GHC.Generics (Generic)+import Hercules.Formats.Secret (Condition)+import Prelude (Bool, Eq, Show)++data Mountable = Mountable+  { -- | A path on the host.+    source :: !Text,+    readOnly :: !Bool,+    condition :: !Condition+  }+  deriving (Generic, Show, Eq, A.ToJSON, A.FromJSON)
src/Hercules/Formats/NixCache.hs view
@@ -30,11 +30,11 @@       ( "kind"           .= String "NixCache"           <> "storeURI"-          .= storeURI a+            .= storeURI a           <> "signingKeys"-          .= signingKeys a+            .= signingKeys a           <> "publicKeys"-          .= publicKeys a+            .= publicKeys a       )  instance FromJSON NixCache where
src/Hercules/Formats/Secret.hs view
@@ -21,6 +21,7 @@   | IsTag   | IsRepo Text   | IsOwner Text+  | Const Bool   deriving (Generic, Eq, Read, Show)  instance ToJSON Condition where@@ -31,6 +32,7 @@   toJSON (IsBranch a) = object ["isBranch" .= a]   toJSON (IsRepo a) = object ["isRepo" .= a]   toJSON (IsOwner a) = object ["isOwner" .= a]+  toJSON (Const b) = Bool b  instance FromJSON Condition where   parseJSON (String "isTag") = pure IsTag@@ -42,7 +44,8 @@         Nothing -> fail $ "The field name in a Condition object must be one of " <> show (map fst (HM.toList taggedConditionParsers))         Just p -> p v       _ -> fail "A Condition object must contain a single field."-  parseJSON _ = fail "Expected Object or String."+  parseJSON (Bool b) = pure (Const b)+  parseJSON _ = fail "Expected Object, String or true."  taggedConditionParsers :: HM.HashMap Text (Value -> A.Parser Condition) taggedConditionParsers =@@ -62,50 +65,6 @@       ("isOwner", fmap IsOwner . parseJSON)     ] -{---This was awful:--instance FromJSON Condition where-  parseJSON (String "isTag") = pure IsTag-  parseJSON (String "isDefaultBranch") = pure IsDefaultBranch-  parseJSON j = do-    l <- parseJSON j-    case l of-      [] -> fail "The empty list does not represent a Condition."-      (jTag : args) -> do-        tag <- parseJSON jTag-        case tag :: Text of-          "or" -> do-            Or <$> traverse parseJSON args-          "and" -> do-            And <$> traverse parseJSON args-          "isDefaultBranch" -> do-            IsDefaultBranch <$ noParams tag args-          "isTag" -> do-            IsTag <$ noParams tag args-          "isBranch" -> do-            IsBranch <$> traverse parseJSON args-          "isRepo" -> do-            IsRepo <$> traverse parseJSON args-          "isOwner" -> do-            IsOwner <$> traverse parseJSON args-          t -> do-            fail $ "Unknown tag " <> show t <> " in Condition."-    where-      noParams _ [] = pure ()-      noParams tag _ = fail $ "Condition with tag " <> show tag <> " does not take any parameters."--instance ToJSON Condition where-  toJSON (Or a) = toJSON (String "or" : map toJSON a)-  toJSON (And a) = toJSON (String "and" : map toJSON a)-  toJSON IsDefaultBranch = String "isDefaultBranch"-  toJSON IsTag = String "isTag"-  toJSON (IsBranch a) = toJSON (String "isBranch" : map toJSON a)-  toJSON (IsRepo a) = toJSON (String "isRepo" : map toJSON a)-  toJSON (IsOwner a) = toJSON (String "isOwner" : map toJSON a)--}- -- | Arbitrary secret like keys, tokens, passwords etc. data Secret = Secret   { data_ :: Map Text Value,@@ -123,10 +82,12 @@  instance FromJSON Secret where   parseJSON =-    withKind "Secret" $-      withVersions+    withKind "Secret"+      $ withVersions         [ noVersion $ \o ->             Secret-              <$> o .: "data"-              <*> o .:? "condition"+              <$> o+              .: "data"+              <*> o+              .:? "condition"         ]
test/Hercules/API/Agent/LifeCycle/AgentInfoSpec.hs view
@@ -91,7 +91,7 @@           ]     } -($=) :: A.ToJSON b => a -> b -> (a, A.Value)+($=) :: (A.ToJSON b) => a -> b -> (a, A.Value) a $= b = (a, A.toJSON b)  spec :: Spec
+ test/Hercules/Formats/MountableSpec.hs view
@@ -0,0 +1,28 @@+module Hercules.Formats.MountableSpec (spec) where++import qualified AesonSupport as Aeson+import Data.Aeson (eitherDecode)+import Hercules.Formats.Mountable (Mountable (..))+import Hercules.Formats.Secret (Condition (IsDefaultBranch, Or))+import Hercules.Formats.SecretSpec (genCondition, genText)+import Test.Hspec (Spec, describe, it, shouldBe)+import Test.QuickCheck (Gen, arbitrary)+import Prelude++spec :: Spec+spec = describe "Mountable" $ do+  Aeson.checkLaws genMountable+  it "Decodes example 1" $+    eitherDecode+      "{ \"source\": \"the source\", \"readOnly\": false, \"condition\": {\"or\": [\"isDefaultBranch\"]} }"+      `shouldBe` Right+        ( Mountable+            { source = "the source",+              readOnly = False,+              condition = Or [IsDefaultBranch]+            }+        )++genMountable :: Gen Mountable+genMountable =+  Mountable <$> genText <*> arbitrary <*> genCondition
test/Hercules/Formats/SecretSpec.hs view
@@ -64,7 +64,7 @@     6     ( Secret         <$> liftArbitraryMap text (resize 100 genValue)-        <*> frequency [(1, pure Nothing), (19, Just <$> genCondition)]+        <*> frequency [(1, pure Nothing), (17, Just <$> genCondition)]     )  genCondition :: Gen Condition@@ -76,13 +76,15 @@       (1, pure IsTag),       (1, IsBranch <$> text),       (1, IsRepo <$> text),-      (1, IsOwner <$> text)+      (1, IsOwner <$> text),+      (1, Hercules.Formats.Secret.Const <$> arbitrary)     ] -text :: Gen Text+genText, text :: Gen Text text = TE.decodeUtf8 . TE.encodeUtf8 . T.pack <$> resize 4 arbitrary+genText = text -liftArbitraryMap :: Ord k => Gen k -> Gen a -> Gen (M.Map k a)+liftArbitraryMap :: (Ord k) => Gen k -> Gen a -> Gen (M.Map k a) liftArbitraryMap k v = M.fromList <$> liftArbitrary ((,) <$> k <*> v)  genValue :: Gen A.Value
test/Spec.hs view
@@ -7,6 +7,7 @@ import qualified Hercules.API.Agent.Evaluate.EvaluateEvent.DerivationInfoSpec import qualified Hercules.API.Agent.LifeCycle.AgentInfoSpec import qualified Hercules.Formats.CachixCacheSpec+import qualified Hercules.Formats.MountableSpec import qualified Hercules.Formats.SecretSpec import Test.Hspec @@ -22,5 +23,7 @@     Hercules.API.Agent.Evaluate.EvaluateEvent.AttributeEffectEventSpec.spec   describe "Hercules.Formats.CachixCache" do     Hercules.Formats.CachixCacheSpec.spec+  describe "Hercules.Formats.Mountable" do+    Hercules.Formats.MountableSpec.spec   describe "Hercules.Formats.Secret" do     Hercules.Formats.SecretSpec.spec