-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGetTool.purs
49 lines (41 loc) · 1.9 KB
/
GetTool.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Setup.GetTool (getTool) where
import Prelude
import Control.Monad.Except.Trans (ExceptT, mapExceptT)
import Data.Foldable (fold)
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Effect.Exception (Error)
import GitHub.Actions.Core as Core
import GitHub.Actions.Exec as Exec
import GitHub.Actions.ToolCache as ToolCache
import Setup.Data.Platform (Platform(..), platform)
import Setup.Data.Tool (InstallMethod(..), Tool)
import Setup.Data.Tool as Tool
import Setup.Data.VersionField (VersionField)
import Setup.Data.VersionField as VersionField
getTool :: { tool :: Tool, versionField :: VersionField } -> ExceptT Error Aff Unit
getTool { tool, versionField } = do
let
name = Tool.name tool
installMethod = Tool.installMethod tool versionField
liftEffect $ Core.info $ fold [ "Fetching ", name ]
case installMethod of
Tarball opts -> do
mbPath <- mapExceptT liftEffect $ ToolCache.find { arch: Nothing, toolName: name, versionSpec: VersionField.showVersionField versionField }
case mbPath of
Just path -> liftEffect do
Core.info $ fold [ "Found cached version of ", name ]
Core.addPath path
Nothing -> do
downloadPath <- ToolCache.downloadTool' opts.source
extractedPath <- ToolCache.extractTar' downloadPath
cached <- ToolCache.cacheFile { sourceFile: opts.getExecutablePath extractedPath, tool: name, version: VersionField.showVersionField versionField, targetFile: name, arch: Nothing }
liftEffect do
Core.info $ fold [ "Cached path ", cached, ", adding to PATH" ]
Core.addPath cached
NPM package -> void $ case platform of
Windows ->
Exec.exec { command: "npm", args: Just [ "install", "-g", package ], options: Nothing }
_ ->
Exec.exec { command: "sudo npm", args: Just [ "install", "-g", package ], options: Nothing }