Support VCS clone configuration
All checks were successful
Build / audit (push) Successful in 7s
Build / test (push) Successful in 14m32s

This commit is contained in:
Eugen Wissner 2024-11-14 22:58:14 +01:00
parent c7e300dc91
commit 2f46303a6d
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
2 changed files with 56 additions and 33 deletions

View File

@ -4,7 +4,8 @@
-- | Configuration file.
module SlackBuilder.Config
( DownloaderSettings(..)
( CloneSettings(..)
, DownloaderSettings(..)
, Settings(..)
, MaintainerSettings(..)
, PackageSettings(..)
@ -33,17 +34,24 @@ newtype MaintainerSettings = MaintainerSettings
data DownloaderSettings = DownloaderSettings
{ name :: Text
, template :: Text
, is64 :: Bool
, version :: Text
, template :: Maybe Text
, clone :: Maybe CloneSettings
, github :: Maybe (Text, Text)
, packagist :: Maybe (Text, Text)
, text :: Maybe (Text, [String])
, repackage :: Maybe [String]
} deriving (Eq, Show)
newtype PackageSettings = PackageSettings
data PackageSettings = PackageSettings
{ downloader :: DownloaderSettings
, downloaders :: [DownloaderSettings]
} deriving (Eq, Show)
data CloneSettings = CloneSettings
{ remote :: Text
, tagTemplate :: Text
} deriving (Eq, Show)
settingsCodec :: Toml.TomlCodec Settings
@ -63,9 +71,10 @@ maintainerSettingsCodec = MaintainerSettings
downloaderSettingsCodec :: Toml.TomlCodec DownloaderSettings
downloaderSettingsCodec = DownloaderSettings
<$> Toml.text "name" .= name
<*> Toml.text "template" .= template
<*> Toml.bool "is64" .= is64
<*> 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 packagistCodec "packagist") .= packagist
<*> Toml.dioptional (Toml.table textCodec "text") .= text
@ -76,4 +85,11 @@ downloaderSettingsCodec = DownloaderSettings
textCodec = Toml.pair (Toml.text "url") (Toml.arrayOf Toml._String "picker")
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

View File

@ -32,6 +32,7 @@ import System.Console.ANSI
, ConsoleLayer(..)
)
import Data.Maybe (fromJust, mapMaybe)
import qualified Text.URI as URI
findUpdatable :: Text -> [PackageSettings] -> DownloaderSettings
findUpdatable packageName = getField @"downloader" . fromJust
@ -40,33 +41,39 @@ findUpdatable packageName = getField @"downloader" . fromJust
githubAutoUpdatables :: [PackageSettings] -> [PackageDescription]
githubAutoUpdatables = mapMaybe go
where
go PackageSettings{ downloader = setting }
| Just githubSettings <- getField @"github" setting = Just
$ PackageDescription
{ latest =
let ghArguments = uncurry PackageOwner githubSettings
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments (getField @"version" setting)
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
go PackageSettings{ downloader = setting, downloaders } = do
latest' <- packageUpdaterFromSettings setting
pure $ PackageDescription
{ latest = latest'
, name = getField @"name" setting
, downloaders = mempty
}
| Just packagistSettings <- getField @"packagist" setting = Just
$ PackageDescription
{ latest =
let packagistArguments = uncurry PackageOwner packagistSettings
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestPackagist packagistArguments
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = getField @"name" setting
, downloaders = mempty
, 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
in Just $ latestGitHub ghArguments version
| Just packagistSettings <- packagist =
let packagistArguments = uncurry PackageOwner packagistSettings
in Just $ latestPackagist packagistArguments
| otherwise = Nothing
getVersionSettings
| Just template' <- template =
Just $ repackageWithTemplate repackage $ Package.DownloadTemplate template'
| Just CloneSettings{..} <- clone =
flip cloneFromGit tagTemplate <$> URI.mkURI remote
| otherwise = Nothing
autoUpdatable :: [PackageSettings] -> [PackageDescription]
@ -75,7 +82,7 @@ autoUpdatable packageSettings = githubAutoUpdatables packageSettings ++
{ latest =
let setting = findUpdatable "webex" packageSettings
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
template = Package.DownloadTemplate $ getField @"template" setting
template = Package.DownloadTemplate $ fromJust $ getField @"template" setting
in Package.Updater
{ detectLatest = latestText textArguments (getField @"version" setting)
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
@ -88,7 +95,7 @@ autoUpdatable packageSettings = githubAutoUpdatables packageSettings ++
{ latest =
let setting = findUpdatable "dmd" packageSettings
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
template = Package.DownloadTemplate $ getField @"template" setting
template = Package.DownloadTemplate $ fromJust $ getField @"template" setting
in Package.Updater
{ detectLatest = latestText textArguments (getField @"version" setting)
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
@ -101,7 +108,7 @@ autoUpdatable packageSettings = githubAutoUpdatables packageSettings ++
{ latest =
let setting = findUpdatable "d-tools" packageSettings
textArguments = uncurry TextArguments $ fromJust $ getField @"text" setting
template = Package.DownloadTemplate $ getField @"template" setting
template = Package.DownloadTemplate $ fromJust $ getField @"template" setting
in Package.Updater
{ detectLatest = latestText textArguments (getField @"version" setting)
, getVersion = repackageWithTemplate (getField @"repackage" setting) template