Skip to content

Commit beee57d

Browse files
author
Colin Wahl
authored
Use purescript-github-actions-toolkit library (#8)
1 parent 9d12f75 commit beee57d

File tree

12 files changed

+51
-244
lines changed

12 files changed

+51
-244
lines changed

packages.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let upstream =
2-
https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200724/packages.dhall sha256:bb941d30820a49345a0e88937094d2b9983d939c9fd3a46969b85ce44953d7d9
2+
https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200909/packages.dhall sha256:b899488adf6f02a92bbaae88039935bbc61bcba4cf4462f6d915fc3d0e094604
33

44
in upstream
55
with versions =

spago.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
, "argonaut-core"
99
, "console"
1010
, "effect"
11+
, "github-actions-toolkit"
1112
, "node-fs"
1213
, "node-path"
1314
, "node-process"

src/Actions/Core.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Actions/Core.purs

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/Actions/Exec.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/Actions/Exec.purs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Actions/ToolCache.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Actions/ToolCache.purs

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/Main.purs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@ module Main where
22

33
import Prelude
44

5+
import Control.Monad.Except.Trans (mapExceptT, runExceptT)
56
import Data.Argonaut.Core (Json)
7+
import Data.Either (Either(..))
68
import Data.Foldable (traverse_)
79
import Effect (Effect)
8-
import Effect.Aff (launchAff_)
10+
import Effect.Aff (launchAff_, runAff_)
11+
import Effect.Class (liftEffect)
12+
import Effect.Exception (message)
13+
import GitHub.Actions.Core as Core
914
import Setup.BuildPlan (constructBuildPlan)
1015
import Setup.GetTool (getTool)
1116
import Setup.UpdateVersions (updateVersions)
1217

1318
main :: Json -> Effect Unit
14-
main json = do
15-
tools <- constructBuildPlan json
16-
launchAff_ $ traverse_ getTool tools
19+
main json = runAff_ go $ runExceptT do
20+
tools <- mapExceptT liftEffect $ constructBuildPlan json
21+
traverse_ getTool tools
22+
where
23+
go res = case join res of
24+
Left err -> Core.setFailed (message err)
25+
Right a -> pure unit
1726

1827
update :: Effect Unit
1928
update = launchAff_ updateVersions

src/Setup/BuildPlan.purs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ module Setup.BuildPlan (constructBuildPlan, BuildPlan) where
22

33
import Prelude
44

5-
import Actions.Core as Core
5+
import Control.Monad.Except.Trans (ExceptT)
66
import Data.Argonaut.Core (Json)
77
import Data.Argonaut.Decode (decodeJson, printJsonDecodeError, (.:))
8-
import Data.Array as Array
9-
import Data.Bifunctor (bimap, lmap)
8+
import Data.Bifunctor (lmap)
109
import Data.Either (Either(..))
1110
import Data.Foldable (fold)
12-
import Data.Maybe (Maybe(..))
11+
import Data.Newtype (unwrap)
1312
import Data.Traversable (traverse)
1413
import Data.Version (Version)
1514
import Data.Version as Version
1615
import Effect (Effect)
1716
import Effect.Aff (error, throwError)
17+
import Effect.Class (liftEffect)
18+
import Effect.Exception (Error)
19+
import GitHub.Actions.Core as Core
1820
import Setup.Data.Key (Key)
1921
import Setup.Data.Key as Key
20-
import Setup.Data.Tool (Tool, required)
22+
import Setup.Data.Tool (Tool)
2123
import Setup.Data.Tool as Tool
2224
import Text.Parsing.Parser (parseErrorMessage)
2325
import Text.Parsing.Parser as ParseError
@@ -26,42 +28,34 @@ import Text.Parsing.Parser as ParseError
2628
type BuildPlan = Array { tool :: Tool, version :: Version }
2729

2830
-- | Construct the list of tools that sholud be downloaded and cached by the action
29-
constructBuildPlan :: Json -> Effect BuildPlan
30-
constructBuildPlan json = map Array.catMaybes $ traverse (resolve json) Tool.allTools
31+
constructBuildPlan :: Json -> ExceptT Error Effect BuildPlan
32+
constructBuildPlan json = traverse (resolve json) Tool.allTools
3133

3234
-- | The parsed value of an input field that specifies a version
3335
data VersionField = Latest | Exact Version
3436

3537
-- | Attempt to read the value of an input specifying a tool version
36-
getVersionField :: Key -> Effect (Maybe (Either String VersionField))
37-
getVersionField = map (map parse) <<< Core.getInput
38-
where
39-
parse = case _ of
38+
getVersionField :: Key -> ExceptT Error Effect VersionField
39+
getVersionField key = do
40+
value <- Core.getInput' (unwrap key)
41+
case value of
4042
"latest" -> pure Latest
41-
value -> bimap ParseError.parseErrorMessage Exact (Version.parseVersion value)
43+
val -> case Version.parseVersion val of
44+
Left msg -> throwError (error (ParseError.parseErrorMessage msg))
45+
Right version -> pure (Exact version)
4246

4347
-- | Resolve the exact version to provide for a tool in the environment, based
4448
-- | on the action.yml file.
45-
resolve :: Json -> Tool -> Effect (Maybe { tool :: Tool, version :: Version })
49+
resolve :: Json -> Tool -> ExceptT Error Effect { tool :: Tool, version :: Version }
4650
resolve versionsContents tool = do
4751
let key = Key.fromTool tool
48-
getVersionField key >>= case _ of
49-
Nothing | required tool -> throwError $ error "No input received for required key."
50-
Nothing -> pure Nothing
51-
Just field -> map Just $ getVersion field
52-
53-
where
54-
getVersion :: Either String VersionField -> Effect { tool :: Tool, version :: Version }
55-
getVersion = case _ of
56-
Left err -> do
57-
Core.setFailed $ fold [ "Unable to parse version: ", err ]
58-
throwError $ error "Unable to complete fetching version."
59-
60-
Right (Exact v) -> do
52+
field <- getVersionField key
53+
case field of
54+
Exact v -> liftEffect do
6155
Core.info "Found exact version"
6256
pure { tool, version: v }
6357

64-
Right Latest -> do
58+
Latest -> liftEffect do
6559
Core.info $ fold [ "Fetching latest tag for ", Tool.name tool ]
6660

6761
let

0 commit comments

Comments
 (0)