Skip to content

Commit e25c92c

Browse files
committed
Not use the versions file for NPM tools
1 parent 915bfb6 commit e25c92c

File tree

6 files changed

+68
-44
lines changed

6 files changed

+68
-44
lines changed

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/update.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Setup/BuildPlan.purs

+15-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Data.Either (Either(..))
1111
import Data.Foldable (fold)
1212
import Data.Maybe (Maybe(..))
1313
import Data.Traversable (traverse)
14-
import Data.Version (Version)
1514
import Data.Version as Version
1615
import Effect (Effect)
1716
import Effect.Aff (error, throwError)
@@ -22,19 +21,17 @@ import Setup.Data.Key (Key)
2221
import Setup.Data.Key as Key
2322
import Setup.Data.Tool (Tool)
2423
import Setup.Data.Tool as Tool
24+
import Setup.Data.VersionField (VersionField(..))
2525
import Text.Parsing.Parser (parseErrorMessage)
2626
import Text.Parsing.Parser as ParseError
2727

2828
-- | The list of tools that should be downloaded and cached by the action
29-
type BuildPlan = Array { tool :: Tool, version :: Version }
29+
type BuildPlan = Array { tool :: Tool, versionField :: VersionField }
3030

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

35-
-- | The parsed value of an input field that specifies a version
36-
data VersionField = Latest | Exact Version
37-
3835
-- | Attempt to read the value of an input specifying a tool version
3936
getVersionField :: Key -> ExceptT Error Effect (Maybe VersionField)
4037
getVersionField key = do
@@ -52,19 +49,24 @@ getVersionField key = do
5249
pure (pure (Exact version))
5350

5451
-- | Resolve the exact version to provide for a tool in the environment, based
55-
-- | on the action.yml file.
56-
resolve :: Json -> Tool -> ExceptT Error Effect (Maybe { tool :: Tool, version :: Version })
52+
-- | on the action.yml file. In the case of NPM packages, bypass the action.yml
53+
-- | file and use 'Latest'.
54+
resolve :: Json -> Tool -> ExceptT Error Effect (Maybe { tool :: Tool, versionField :: VersionField })
5755
resolve versionsContents tool = do
5856
let key = Key.fromTool tool
5957
field <- getVersionField key
60-
case field of
61-
Nothing -> pure Nothing
58+
case field, Tool.isNPMTool tool of
59+
Nothing, _ -> pure Nothing
6260

63-
Just (Exact v) -> liftEffect do
61+
Just (Exact v), _ -> liftEffect do
6462
Core.info "Found exact version"
65-
pure (pure { tool, version: v })
63+
pure (pure { tool, versionField: Exact v })
64+
65+
Just Latest, true -> liftEffect do
66+
Core.info $ fold [ "Fetching latest tag for ", Tool.name tool ]
67+
pure (pure { tool, versionField: Latest })
6668

67-
Just Latest -> liftEffect do
69+
Just Latest, false -> liftEffect do
6870
Core.info $ fold [ "Fetching latest tag for ", Tool.name tool ]
6971

7072
let
@@ -77,4 +79,4 @@ resolve versionsContents tool = do
7779
throwError $ error "Unable to complete fetching version."
7880

7981
Right v -> do
80-
pure (pure { tool, version: v })
82+
pure (pure { tool, versionField: Exact v })

src/Setup/Data/Tool.purs

+32-22
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ module Setup.Data.Tool where
33
import Prelude
44

55
import Affjax (URL)
6+
import Data.Bounded.Generic (genericBottom, genericTop)
67
import Data.Either (fromRight')
78
import Data.Enum (class Enum, upFromIncluding)
9+
import Data.Enum.Generic (genericPred, genericSucc)
810
import Data.Foldable (elem, fold)
911
import Data.Generic.Rep (class Generic)
10-
import Data.Bounded.Generic (genericBottom, genericTop)
11-
import Data.Enum.Generic (genericPred, genericSucc)
12-
import Data.Version (Version, parseVersion)
13-
import Data.Version as Version
12+
import Data.Version (parseVersion)
1413
import Node.Path (FilePath)
1514
import Node.Path as Path
1615
import Partial.Unsafe (unsafeCrashWith)
1716
import Setup.Data.Platform (Platform(..), platform)
17+
import Setup.Data.VersionField (VersionField(..))
18+
import Setup.Data.VersionField as VersionField
1819

1920
data Tool
2021
= PureScript
@@ -75,6 +76,9 @@ repository = case _ of
7576
Zephyr ->
7677
{ owner: "coot", name: "zephyr" }
7778

79+
isNPMTool :: Tool -> Boolean
80+
isNPMTool = (_ == Psa) || (_ == PursTidy)
81+
7882
-- | How a tool will be installed: either a tarball from a URL, or an NPM package
7983
-- | at a particular version.
8084
data InstallMethod = Tarball TarballOpts | NPM NPMPackage
@@ -91,8 +95,8 @@ type NPMPackage = String
9195

9296
-- | The installation method for a tool, which includes the source path necessary
9397
-- | to download or install the tool.
94-
installMethod :: Tool -> Version -> InstallMethod
95-
installMethod tool version = do
98+
installMethod :: Tool -> VersionField -> InstallMethod
99+
installMethod tool versionField = do
96100
let
97101
toolName = name tool
98102
toolRepo = repository tool
@@ -118,26 +122,32 @@ installMethod tool version = do
118122
Spago -> Tarball
119123
{ source: formatGitHub'
120124
-- Spago has changed naming conventions from version to version
121-
if version >= unsafeVersion "0.18.1" then case platform of
122-
Windows -> "Windows"
123-
Mac -> "macOS"
124-
Linux -> "Linux"
125-
else if version == unsafeVersion "0.18.0" then case platform of
126-
Windows -> "windows-latest"
127-
Mac -> "macOS-latest"
128-
Linux -> "linux-latest"
129-
else case platform of
130-
Windows -> "windows"
131-
Mac -> "osx"
132-
Linux -> "linux"
125+
case versionField of
126+
Exact version
127+
| version >= unsafeVersion "0.18.1" ->
128+
case platform of
129+
Windows -> "Windows"
130+
Mac -> "macOS"
131+
Linux -> "Linux"
132+
| version == unsafeVersion "0.18.1" ->
133+
case platform of
134+
Windows -> "windows-latest"
135+
Mac -> "macOS-latest"
136+
Linux -> "linux-latest"
137+
_ ->
138+
case platform of
139+
Windows -> "windows"
140+
Mac -> "osx"
141+
Linux -> "linux"
142+
133143
, getExecutablePath: \p -> Path.concat [ p, executableName ]
134144
}
135145

136146
Psa ->
137-
NPM ("purescript-psa@" <> Version.showVersion version)
147+
NPM ("purescript-psa@" <> VersionField.showVersionField versionField)
138148

139149
PursTidy ->
140-
NPM ("purs-tidy@" <> Version.showVersion version)
150+
NPM ("purs-tidy@" <> VersionField.showVersionField versionField)
141151

142152
Zephyr -> Tarball
143153
{ source: formatGitHub' $ case platform of
@@ -153,8 +163,8 @@ installMethod tool version = do
153163
-- Example: "v0.13.2", "0.15.2"
154164
formatTag :: String
155165
formatTag = do
156-
let versionStr = Version.showVersion version
157-
if tool `elem` [ PureScript, Zephyr, Psa ] then
166+
let versionStr = VersionField.showVersionField versionField
167+
if tool `elem` [ PureScript, Zephyr ] then
158168
fold [ "v", versionStr ]
159169
else
160170
versionStr

src/Setup/Data/VersionField.purs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Setup.Data.VersionField (VersionField(..), showVersionField) where
2+
3+
import Data.Version (Version)
4+
import Data.Version as Version
5+
6+
-- | The parsed value of an input field that specifies a version
7+
data VersionField = Latest | Exact Version
8+
9+
showVersionField :: VersionField -> String
10+
showVersionField = case _ of
11+
Latest -> "latest"
12+
Exact v -> Version.showVersion v

src/Setup/GetTool.purs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import Prelude
55
import Control.Monad.Except.Trans (ExceptT, mapExceptT)
66
import Data.Foldable (fold)
77
import Data.Maybe (Maybe(..))
8-
import Data.Version (Version)
9-
import Data.Version as Version
108
import Effect.Aff (Aff)
119
import Effect.Class (liftEffect)
1210
import Effect.Exception (Error)
@@ -16,18 +14,20 @@ import GitHub.Actions.ToolCache as ToolCache
1614
import Setup.Data.Platform (Platform(..), platform)
1715
import Setup.Data.Tool (InstallMethod(..), Tool)
1816
import Setup.Data.Tool as Tool
17+
import Setup.Data.VersionField (VersionField)
18+
import Setup.Data.VersionField as VersionField
1919

20-
getTool :: { tool :: Tool, version :: Version } -> ExceptT Error Aff Unit
21-
getTool { tool, version } = do
20+
getTool :: { tool :: Tool, versionField :: VersionField } -> ExceptT Error Aff Unit
21+
getTool { tool, versionField } = do
2222
let
2323
name = Tool.name tool
24-
installMethod = Tool.installMethod tool version
24+
installMethod = Tool.installMethod tool versionField
2525

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

2828
case installMethod of
2929
Tarball opts -> do
30-
mbPath <- mapExceptT liftEffect $ ToolCache.find { arch: Nothing, toolName: name, versionSpec: Version.showVersion version }
30+
mbPath <- mapExceptT liftEffect $ ToolCache.find { arch: Nothing, toolName: name, versionSpec: VersionField.showVersionField versionField }
3131
case mbPath of
3232
Just path -> liftEffect do
3333
Core.info $ fold [ "Found cached version of ", name ]
@@ -36,7 +36,7 @@ getTool { tool, version } = do
3636
Nothing -> do
3737
downloadPath <- ToolCache.downloadTool' opts.source
3838
extractedPath <- ToolCache.extractTar' downloadPath
39-
cached <- ToolCache.cacheFile { sourceFile: opts.getExecutablePath extractedPath, tool: name, version: Version.showVersion version, targetFile: name, arch: Nothing }
39+
cached <- ToolCache.cacheFile { sourceFile: opts.getExecutablePath extractedPath, tool: name, version: VersionField.showVersionField versionField, targetFile: name, arch: Nothing }
4040

4141
liftEffect do
4242
Core.info $ fold [ "Cached path ", cached, ", adding to PATH" ]

0 commit comments

Comments
 (0)