Skip to content

Add extra debug statements and fix build plan #15

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

Merged
merged 1 commit into from
Oct 4, 2020
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
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/update.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/versions.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"purs":"0.13.8","spago":"0.16.0","psa":"0.8.0","purty":"6.2.0","zephyr":"0.3.2"}
{"purs":"0.13.8","spago":"0.16.0","psa":"0.8.0","purty":"6.2.0","zephyr":"0.3.2"}
5 changes: 3 additions & 2 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
, "argonaut-codecs"
, "argonaut-core"
, "console"
, "debug"
, "effect"
, "github-actions-toolkit"
, "monad-loops"
, "node-fs"
, "node-path"
, "node-process"
, "nullable"
, "psci-support"
, "record"
, "versions"
, "monad-loops"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
, sources = [ "src/**/*.purs" ]
}
2 changes: 2 additions & 0 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import Setup.UpdateVersions (updateVersions)
main :: Json -> Effect Unit
main json = runAff_ go $ runExceptT do
tools <- mapExceptT liftEffect $ constructBuildPlan json
liftEffect $ Core.info "Constructed build plan."
traverse_ getTool tools
liftEffect $ Core.info "Fetched tools."
where
go res = case join res of
Left err -> Core.setFailed (message err)
Expand Down
32 changes: 21 additions & 11 deletions src/Setup/BuildPlan.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import Prelude
import Control.Monad.Except.Trans (ExceptT)
import Data.Argonaut.Core (Json)
import Data.Argonaut.Decode (decodeJson, printJsonDecodeError, (.:))
import Data.Array as Array
import Data.Bifunctor (lmap)
import Data.Either (Either(..))
import Data.Foldable (fold)
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
import Data.Traversable (traverse)
import Data.Version (Version)
Expand All @@ -29,33 +31,41 @@ type BuildPlan = Array { tool :: Tool, version :: Version }

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

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

-- | Attempt to read the value of an input specifying a tool version
getVersionField :: Key -> ExceptT Error Effect VersionField
getVersionField :: Key -> ExceptT Error Effect (Maybe VersionField)
getVersionField key = do
value <- Core.getInput' (unwrap key)
case value of
"latest" -> pure Latest
"" ->
pure Nothing
"latest" ->
pure (pure Latest)
val -> case Version.parseVersion val of
Left msg -> throwError (error (ParseError.parseErrorMessage msg))
Right version -> pure (Exact version)
Left msg -> do
liftEffect $ Core.error $ fold [ "Failed to parse version ", val ]
throwError (error (ParseError.parseErrorMessage msg))
Right version ->
pure (pure (Exact version))

-- | Resolve the exact version to provide for a tool in the environment, based
-- | on the action.yml file.
resolve :: Json -> Tool -> ExceptT Error Effect { tool :: Tool, version :: Version }
resolve :: Json -> Tool -> ExceptT Error Effect (Maybe { tool :: Tool, version :: Version })
resolve versionsContents tool = do
let key = Key.fromTool tool
field <- getVersionField key
case field of
Exact v -> liftEffect do
Nothing -> pure Nothing

Just (Exact v) -> liftEffect do
Core.info "Found exact version"
pure { tool, version: v }
pure (pure { tool, version: v })

Latest -> liftEffect do
Just Latest -> liftEffect do
Core.info $ fold [ "Fetching latest tag for ", Tool.name tool ]

let
Expand All @@ -67,5 +77,5 @@ resolve versionsContents tool = do
Core.setFailed $ fold [ "Unable to parse version: ", e ]
throwError $ error "Unable to complete fetching version."

Right v ->
pure { tool, version: v }
Right v -> do
pure (pure { tool, version: v })
2 changes: 2 additions & 0 deletions src/Setup/GetTool.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ getTool { tool, version } = do
name = Tool.name tool
installMethod = Tool.installMethod tool version

liftEffect $ Core.info $ fold [ "Fetching ", name ]

case installMethod of
Tarball opts -> do
mbPath <- mapExceptT liftEffect $ ToolCache.find { arch: Nothing, toolName: name, versionSpec: Version.showVersion version }
Expand Down