Support VCS clone configuration
This commit is contained in:
parent
c7e300dc91
commit
2f46303a6d
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
-- | Configuration file.
|
-- | Configuration file.
|
||||||
module SlackBuilder.Config
|
module SlackBuilder.Config
|
||||||
( DownloaderSettings(..)
|
( CloneSettings(..)
|
||||||
|
, DownloaderSettings(..)
|
||||||
, Settings(..)
|
, Settings(..)
|
||||||
, MaintainerSettings(..)
|
, MaintainerSettings(..)
|
||||||
, PackageSettings(..)
|
, PackageSettings(..)
|
||||||
@ -33,17 +34,24 @@ newtype MaintainerSettings = MaintainerSettings
|
|||||||
|
|
||||||
data DownloaderSettings = DownloaderSettings
|
data DownloaderSettings = DownloaderSettings
|
||||||
{ name :: Text
|
{ name :: Text
|
||||||
, template :: Text
|
|
||||||
, is64 :: Bool
|
, is64 :: Bool
|
||||||
, version :: Text
|
, version :: Text
|
||||||
|
, template :: Maybe Text
|
||||||
|
, clone :: Maybe CloneSettings
|
||||||
, github :: Maybe (Text, Text)
|
, github :: Maybe (Text, Text)
|
||||||
, packagist :: Maybe (Text, Text)
|
, packagist :: Maybe (Text, Text)
|
||||||
, text :: Maybe (Text, [String])
|
, text :: Maybe (Text, [String])
|
||||||
, repackage :: Maybe [String]
|
, repackage :: Maybe [String]
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
newtype PackageSettings = PackageSettings
|
data PackageSettings = PackageSettings
|
||||||
{ downloader :: DownloaderSettings
|
{ downloader :: DownloaderSettings
|
||||||
|
, downloaders :: [DownloaderSettings]
|
||||||
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
|
data CloneSettings = CloneSettings
|
||||||
|
{ remote :: Text
|
||||||
|
, tagTemplate :: Text
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
settingsCodec :: Toml.TomlCodec Settings
|
settingsCodec :: Toml.TomlCodec Settings
|
||||||
@ -63,9 +71,10 @@ maintainerSettingsCodec = MaintainerSettings
|
|||||||
downloaderSettingsCodec :: Toml.TomlCodec DownloaderSettings
|
downloaderSettingsCodec :: Toml.TomlCodec DownloaderSettings
|
||||||
downloaderSettingsCodec = DownloaderSettings
|
downloaderSettingsCodec = DownloaderSettings
|
||||||
<$> Toml.text "name" .= name
|
<$> Toml.text "name" .= name
|
||||||
<*> Toml.text "template" .= template
|
|
||||||
<*> Toml.bool "is64" .= is64
|
<*> Toml.bool "is64" .= is64
|
||||||
<*> Toml.text "version" .= version
|
<*> Toml.text "version" .= version
|
||||||
|
<*> Toml.dioptional (Toml.text "template") .= template
|
||||||
|
<*> Toml.dioptional (Toml.table cloneSettingsCodec "clone") .= clone
|
||||||
<*> Toml.dioptional (Toml.table githubCodec "github") .= github
|
<*> Toml.dioptional (Toml.table githubCodec "github") .= github
|
||||||
<*> Toml.dioptional (Toml.table packagistCodec "packagist") .= packagist
|
<*> Toml.dioptional (Toml.table packagistCodec "packagist") .= packagist
|
||||||
<*> Toml.dioptional (Toml.table textCodec "text") .= text
|
<*> Toml.dioptional (Toml.table textCodec "text") .= text
|
||||||
@ -76,4 +85,11 @@ downloaderSettingsCodec = DownloaderSettings
|
|||||||
textCodec = Toml.pair (Toml.text "url") (Toml.arrayOf Toml._String "picker")
|
textCodec = Toml.pair (Toml.text "url") (Toml.arrayOf Toml._String "picker")
|
||||||
|
|
||||||
packageSettingsCodec :: Toml.TomlCodec PackageSettings
|
packageSettingsCodec :: Toml.TomlCodec PackageSettings
|
||||||
packageSettingsCodec = Toml.dimap (getField @"downloader") PackageSettings downloaderSettingsCodec
|
packageSettingsCodec = PackageSettings
|
||||||
|
<$> downloaderSettingsCodec .= getField @"downloader"
|
||||||
|
<*> Toml.list downloaderSettingsCodec "downloader" .= downloaders
|
||||||
|
|
||||||
|
cloneSettingsCodec :: Toml.TomlCodec CloneSettings
|
||||||
|
cloneSettingsCodec = CloneSettings
|
||||||
|
<$> Toml.text "remote" .= remote
|
||||||
|
<*> Toml.text "tag_template" .= tagTemplate
|
||||||
|
63
src/Main.hs
63
src/Main.hs
@ -32,6 +32,7 @@ import System.Console.ANSI
|
|||||||
, ConsoleLayer(..)
|
, ConsoleLayer(..)
|
||||||
)
|
)
|
||||||
import Data.Maybe (fromJust, mapMaybe)
|
import Data.Maybe (fromJust, mapMaybe)
|
||||||
|
import qualified Text.URI as URI
|
||||||
|
|
||||||
findUpdatable :: Text -> [PackageSettings] -> DownloaderSettings
|
findUpdatable :: Text -> [PackageSettings] -> DownloaderSettings
|
||||||
findUpdatable packageName = getField @"downloader" . fromJust
|
findUpdatable packageName = getField @"downloader" . fromJust
|
||||||
@ -40,33 +41,39 @@ findUpdatable packageName = getField @"downloader" . fromJust
|
|||||||
githubAutoUpdatables :: [PackageSettings] -> [PackageDescription]
|
githubAutoUpdatables :: [PackageSettings] -> [PackageDescription]
|
||||||
githubAutoUpdatables = mapMaybe go
|
githubAutoUpdatables = mapMaybe go
|
||||||
where
|
where
|
||||||
go PackageSettings{ downloader = setting }
|
go PackageSettings{ downloader = setting, downloaders } = do
|
||||||
| Just githubSettings <- getField @"github" setting = Just
|
latest' <- packageUpdaterFromSettings setting
|
||||||
$ PackageDescription
|
pure $ PackageDescription
|
||||||
{ latest =
|
{ latest = latest'
|
||||||
|
, name = getField @"name" setting
|
||||||
|
, downloaders = Map.fromList $ mapMaybe forDownloader downloaders
|
||||||
|
}
|
||||||
|
forDownloader downloaderSettings@DownloaderSettings{ name } =
|
||||||
|
(name,) <$> packageUpdaterFromSettings downloaderSettings
|
||||||
|
|
||||||
|
packageUpdaterFromSettings :: DownloaderSettings -> Maybe Package.Updater
|
||||||
|
packageUpdaterFromSettings DownloaderSettings{..} = do
|
||||||
|
getVersion' <- getVersionSettings
|
||||||
|
detectLatest' <- detectLatestSettings
|
||||||
|
Just Package.Updater
|
||||||
|
{ detectLatest = detectLatest'
|
||||||
|
, getVersion = getVersion'
|
||||||
|
, is64 = is64
|
||||||
|
}
|
||||||
|
where
|
||||||
|
detectLatestSettings
|
||||||
|
| Just githubSettings <- github =
|
||||||
let ghArguments = uncurry PackageOwner githubSettings
|
let ghArguments = uncurry PackageOwner githubSettings
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
in Just $ latestGitHub ghArguments version
|
||||||
in Package.Updater
|
| Just packagistSettings <- packagist =
|
||||||
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
|
|
||||||
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
|
|
||||||
, is64 = getField @"is64" setting
|
|
||||||
}
|
|
||||||
, name = getField @"name" setting
|
|
||||||
, downloaders = mempty
|
|
||||||
}
|
|
||||||
| Just packagistSettings <- getField @"packagist" setting = Just
|
|
||||||
$ PackageDescription
|
|
||||||
{ latest =
|
|
||||||
let packagistArguments = uncurry PackageOwner packagistSettings
|
let packagistArguments = uncurry PackageOwner packagistSettings
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
in Just $ latestPackagist packagistArguments
|
||||||
in Package.Updater
|
| otherwise = Nothing
|
||||||
{ detectLatest = latestPackagist packagistArguments
|
getVersionSettings
|
||||||
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
|
| Just template' <- template =
|
||||||
, is64 = getField @"is64" setting
|
Just $ repackageWithTemplate repackage $ Package.DownloadTemplate template'
|
||||||
}
|
| Just CloneSettings{..} <- clone =
|
||||||
, name = getField @"name" setting
|
flip cloneFromGit tagTemplate <$> URI.mkURI remote
|
||||||
, downloaders = mempty
|
|
||||||
}
|
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
autoUpdatable :: [PackageSettings] -> [PackageDescription]
|
autoUpdatable :: [PackageSettings] -> [PackageDescription]
|
||||||
@ -75,7 +82,7 @@ autoUpdatable packageSettings = githubAutoUpdatables packageSettings ++
|
|||||||
{ latest =
|
{ latest =
|
||||||
let setting = findUpdatable "webex" packageSettings
|
let setting = findUpdatable "webex" packageSettings
|
||||||
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ fromJust $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||||
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
|
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
|
||||||
@ -88,7 +95,7 @@ autoUpdatable packageSettings = githubAutoUpdatables packageSettings ++
|
|||||||
{ latest =
|
{ latest =
|
||||||
let setting = findUpdatable "dmd" packageSettings
|
let setting = findUpdatable "dmd" packageSettings
|
||||||
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ fromJust $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||||
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
|
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
|
||||||
@ -101,7 +108,7 @@ autoUpdatable packageSettings = githubAutoUpdatables packageSettings ++
|
|||||||
{ latest =
|
{ latest =
|
||||||
let setting = findUpdatable "d-tools" packageSettings
|
let setting = findUpdatable "d-tools" packageSettings
|
||||||
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
|
||||||
template = Package.DownloadTemplate $ getField @"template" setting
|
template = Package.DownloadTemplate $ fromJust $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments (getField @"version" setting)
|
{ detectLatest = latestText textArguments (getField @"version" setting)
|
||||||
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
|
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
|
||||||
|
Loading…
Reference in New Issue
Block a user