Mix configuration and PackageDescription
This commit is contained in:
parent
2a78256933
commit
00cc58f87e
@ -33,6 +33,9 @@ data PackageSettings = PackageSettings
|
|||||||
{ name :: Text
|
{ name :: Text
|
||||||
, template :: Text
|
, template :: Text
|
||||||
, is64 :: Bool
|
, is64 :: Bool
|
||||||
|
, github :: Maybe (Text, Text)
|
||||||
|
, packagist :: Maybe (Text, Text)
|
||||||
|
, text :: Maybe Text
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
settingsCodec :: Toml.TomlCodec Settings
|
settingsCodec :: Toml.TomlCodec Settings
|
||||||
@ -54,3 +57,6 @@ packageSettingsCodec = PackageSettings
|
|||||||
<$> Toml.text "name" .= name
|
<$> Toml.text "name" .= name
|
||||||
<*> Toml.text "template" .= template
|
<*> Toml.text "template" .= template
|
||||||
<*> Toml.bool "is64" .= is64
|
<*> Toml.bool "is64" .= is64
|
||||||
|
<*> Toml.dioptional (flip Toml.table "github" $ Toml.pair (Toml.text "owner") (Toml.text "name")) .= github
|
||||||
|
<*> Toml.dioptional (flip Toml.table "packagist" $ Toml.pair (Toml.text "owner") (Toml.text "name")) .= packagist
|
||||||
|
<*> Toml.dioptional (flip Toml.table "text" $ Toml.text "url") .= text
|
||||||
|
136
src/Main.hs
136
src/Main.hs
@ -20,11 +20,11 @@ import qualified Toml
|
|||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
import qualified Data.Text.IO as Text
|
import qualified Data.Text.IO as Text
|
||||||
import Control.Monad.Trans.Reader (ReaderT(..))
|
import Control.Monad.Trans.Reader (ReaderT(..), asks)
|
||||||
import SlackBuilder.Package (PackageDescription(..))
|
import SlackBuilder.Package (PackageDescription(..))
|
||||||
import qualified SlackBuilder.Package as Package
|
import qualified SlackBuilder.Package as Package
|
||||||
import Text.URI.QQ (uri)
|
import Text.URI.QQ (uri)
|
||||||
import Data.Foldable (for_, find)
|
import Data.Foldable (find, traverse_)
|
||||||
import GHC.Records (HasField(..))
|
import GHC.Records (HasField(..))
|
||||||
import System.Process (CmdSpec(..))
|
import System.Process (CmdSpec(..))
|
||||||
import System.Console.ANSI
|
import System.Console.ANSI
|
||||||
@ -34,95 +34,84 @@ import System.Console.ANSI
|
|||||||
, Color(..)
|
, Color(..)
|
||||||
, ConsoleLayer(..)
|
, ConsoleLayer(..)
|
||||||
)
|
)
|
||||||
|
import Data.Maybe (fromJust)
|
||||||
|
|
||||||
autoUpdatable :: [PackageDescription]
|
autoUpdatable :: [PackageSettings] -> [PackageDescription]
|
||||||
autoUpdatable =
|
autoUpdatable packageSettings =
|
||||||
[ PackageDescription
|
[ PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = PackageOwner{ owner = "universal-ctags", name = "ctags" }
|
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
template = Package.DownloadTemplate
|
setting = fromJust $ find ((== "universal-ctags") . getField @"name") packageSettings
|
||||||
"https://github.com/universal-ctags/ctags/archive/{version}/ctags-{version}.tar.gz"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
||||||
, getVersion = reuploadWithTemplate template []
|
, getVersion = reuploadWithTemplate template []
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "universal-ctags"
|
, name = "universal-ctags"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let packagistArguments = PackageOwner{ owner = "composer", name = "composer" }
|
let packagistArguments = uncurry PackageOwner $ fromJust $ getField @"packagist" setting
|
||||||
template = Package.DownloadTemplate
|
setting = fromJust $ find ((== "composer") . getField @"name") packageSettings
|
||||||
"https://getcomposer.org/download/{version}/composer.phar"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestPackagist packagistArguments
|
{ detectLatest = latestPackagist packagistArguments
|
||||||
, getVersion = downloadWithTemplate template
|
, getVersion = downloadWithTemplate template
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "composer"
|
, name = "composer"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = PackageOwner
|
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
{ owner = "jitsi"
|
setting = fromJust $ find ((== "jitsi-meet-desktop") . getField @"name") packageSettings
|
||||||
, name = "jitsi-meet-electron"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
}
|
|
||||||
template = Package.DownloadTemplate
|
|
||||||
"https://github.com/jitsi/jitsi-meet-electron/releases/download/v{version}/jitsi-meet-x86_64.AppImage"
|
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments "(v)*"
|
{ detectLatest = latestGitHub ghArguments "(v)*"
|
||||||
, getVersion = downloadWithTemplate template
|
, getVersion = downloadWithTemplate template
|
||||||
, is64 = True
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "jitsi-meet-desktop"
|
, name = "jitsi-meet-desktop"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = PackageOwner
|
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
{ owner = "php"
|
setting = fromJust $ find ((== "php82") . getField @"name") packageSettings
|
||||||
, name = "php-src"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
}
|
|
||||||
template = Package.DownloadTemplate
|
|
||||||
"https://www.php.net/distributions/php-{version}.tar.xz"
|
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments "(php-)8.2.\\d"
|
{ detectLatest = latestGitHub ghArguments "(php-)8.2.\\d"
|
||||||
, getVersion = downloadWithTemplate template
|
, getVersion = downloadWithTemplate template
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "php82"
|
, name = "php82"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = PackageOwner
|
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
{ owner = "kovidgoyal"
|
setting = fromJust $ find ((== "kitty") . getField @"name") packageSettings
|
||||||
, name = "kitty"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
}
|
|
||||||
template = Package.DownloadTemplate
|
|
||||||
"https://github.com/kovidgoyal/kitty/releases/download/v{version}/kitty-{version}.tar.xz"
|
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
||||||
, getVersion = reuploadWithTemplate template [RawCommand "go" ["mod", "vendor"]]
|
, getVersion = reuploadWithTemplate template [RawCommand "go" ["mod", "vendor"]]
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "kitty"
|
, name = "kitty"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = PackageOwner
|
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
{ owner = "rdiff-backup"
|
setting = fromJust $ find ((== "rdiff-backup") . getField @"name") packageSettings
|
||||||
, name = "rdiff-backup"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
}
|
|
||||||
template = Package.DownloadTemplate
|
|
||||||
"https://github.com/rdiff-backup/rdiff-backup/releases/download/v{version}/rdiff-backup-{version}.tar.gz"
|
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
||||||
, getVersion = reuploadWithTemplate template []
|
, getVersion = reuploadWithTemplate template []
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "rdiff-backup"
|
, name = "rdiff-backup"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
@ -131,34 +120,31 @@ autoUpdatable =
|
|||||||
{ latest =
|
{ latest =
|
||||||
let needle = "Linux—"
|
let needle = "Linux—"
|
||||||
textArguments = TextArguments
|
textArguments = TextArguments
|
||||||
{ textURL = "https://help.webex.com/en-us/article/mqkve8/Webex-App-%7C-Release-notes"
|
{ textURL = fromJust $ getField @"text" setting
|
||||||
, versionPicker = Text.takeWhile (liftA2 (||) (== '.') isNumber)
|
, versionPicker = Text.takeWhile (liftA2 (||) (== '.') isNumber)
|
||||||
. Text.drop (Text.length needle)
|
. Text.drop (Text.length needle)
|
||||||
. snd
|
. snd
|
||||||
. Text.breakOn needle
|
. Text.breakOn needle
|
||||||
}
|
}
|
||||||
template = Package.DownloadTemplate
|
setting = fromJust $ find ((== "webex") . getField @"name") packageSettings
|
||||||
"https://binaries.webex.com/WebexDesktop-Ubuntu-Official-Package/Webex.deb"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments
|
{ detectLatest = latestText textArguments
|
||||||
, getVersion = downloadWithTemplate template
|
, getVersion = downloadWithTemplate template
|
||||||
, is64 = True
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "webex"
|
, name = "webex"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = PackageOwner
|
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
{ owner = "librsync"
|
setting = fromJust $ find ((== "librsync") . getField @"name") packageSettings
|
||||||
, name = "librsync"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
}
|
|
||||||
template = Package.DownloadTemplate
|
|
||||||
"https://github.com/librsync/librsync/archive/v{version}/librsync-{version}.tar.gz"
|
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
||||||
, getVersion = reuploadWithTemplate template []
|
, getVersion = reuploadWithTemplate template []
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "librsync"
|
, name = "librsync"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
@ -166,15 +152,15 @@ autoUpdatable =
|
|||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let textArguments = TextArguments
|
let textArguments = TextArguments
|
||||||
{ textURL = "https://downloads.dlang.org/releases/LATEST"
|
{ textURL = fromJust $ getField @"text" setting
|
||||||
, versionPicker = Text.strip
|
, versionPicker = Text.strip
|
||||||
}
|
}
|
||||||
template = Package.DownloadTemplate
|
setting = fromJust $ find ((== "dmd") . getField @"name") packageSettings
|
||||||
"https://downloads.dlang.org/releases/2.x/{version}/dmd.{version}.linux.tar.xz"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments
|
{ detectLatest = latestText textArguments
|
||||||
, getVersion = downloadWithTemplate template
|
, getVersion = downloadWithTemplate template
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "dmd"
|
, name = "dmd"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
@ -182,14 +168,15 @@ autoUpdatable =
|
|||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let textArguments = TextArguments
|
let textArguments = TextArguments
|
||||||
{ textURL = "https://downloads.dlang.org/releases/LATEST"
|
{ textURL = fromJust $ getField @"text" setting
|
||||||
, versionPicker = Text.strip
|
, versionPicker = Text.strip
|
||||||
}
|
}
|
||||||
template = Package.DownloadTemplate "https://codeload.github.com/dlang/tools/tar.gz/v{version}"
|
setting = fromJust $ find ((== "d-tools") . getField @"name") packageSettings
|
||||||
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestText textArguments
|
{ detectLatest = latestText textArguments
|
||||||
, getVersion = reuploadWithTemplate template []
|
, getVersion = reuploadWithTemplate template []
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "d-tools"
|
, name = "d-tools"
|
||||||
, downloaders =
|
, downloaders =
|
||||||
@ -222,32 +209,26 @@ autoUpdatable =
|
|||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = PackageOwner
|
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
{ owner = "simd-everywhere"
|
setting = fromJust $ find ((== "simde") . getField @"name") packageSettings
|
||||||
, name = "simde"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
}
|
|
||||||
template = Package.DownloadTemplate
|
|
||||||
"https://github.com/simd-everywhere/simde/releases/download/v{version}/simde-amalgamated-{version}.tar.xz"
|
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
{ detectLatest = latestGitHub ghArguments "(v)\\."
|
||||||
, getVersion = downloadWithTemplate template
|
, getVersion = downloadWithTemplate template
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "simde"
|
, name = "simde"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
}
|
}
|
||||||
, PackageDescription
|
, PackageDescription
|
||||||
{ latest =
|
{ latest =
|
||||||
let ghArguments = PackageOwner
|
let ghArguments = uncurry PackageOwner $ fromJust $ getField @"github" setting
|
||||||
{ owner = "nginx"
|
setting = fromJust $ find ((== "nginx") . getField @"name") packageSettings
|
||||||
, name = "nginx"
|
template = Package.DownloadTemplate $ getField @"template" setting
|
||||||
}
|
|
||||||
template = Package.DownloadTemplate
|
|
||||||
"http://nginx.org/download/nginx-{version}.tar.gz"
|
|
||||||
in Package.Updater
|
in Package.Updater
|
||||||
{ detectLatest = latestGitHub ghArguments "(release-)\\d.[02468].\\d"
|
{ detectLatest = latestGitHub ghArguments "(release-)\\d.[02468].\\d"
|
||||||
, getVersion = downloadWithTemplate template
|
, getVersion = downloadWithTemplate template
|
||||||
, is64 = False
|
, is64 = getField @"is64" setting
|
||||||
}
|
}
|
||||||
, name = "nginx"
|
, name = "nginx"
|
||||||
, downloaders = mempty
|
, downloaders = mempty
|
||||||
@ -255,10 +236,12 @@ autoUpdatable =
|
|||||||
]
|
]
|
||||||
|
|
||||||
up2Date :: Maybe Text -> SlackBuilderT ()
|
up2Date :: Maybe Text -> SlackBuilderT ()
|
||||||
up2Date = \case
|
up2Date selectedPackage = do
|
||||||
Nothing -> for_ autoUpdatable $ handle handleException . go
|
packages' <- SlackBuilderT $ asks (getField @"packages")
|
||||||
|
case selectedPackage of
|
||||||
|
Nothing -> traverse_ (handle handleException . go) $ autoUpdatable packages'
|
||||||
Just packageName
|
Just packageName
|
||||||
| Just foundPackage <- find ((packageName ==) . getField @"name") autoUpdatable ->
|
| Just foundPackage <- find ((packageName ==) . getField @"name") (autoUpdatable packages') ->
|
||||||
go foundPackage
|
go foundPackage
|
||||||
| otherwise -> throwM $ UpdaterNotFound packageName
|
| otherwise -> throwM $ UpdaterNotFound packageName
|
||||||
where
|
where
|
||||||
@ -267,7 +250,8 @@ up2Date = \case
|
|||||||
>> liftIO (putStrLn "")
|
>> liftIO (putStrLn "")
|
||||||
|
|
||||||
check :: SlackBuilderT ()
|
check :: SlackBuilderT ()
|
||||||
check = for_ autoUpdatable $ handle handleException . go
|
check = SlackBuilderT (asks (getField @"packages"))
|
||||||
|
>>= traverse_ (handle handleException . go) . autoUpdatable
|
||||||
where
|
where
|
||||||
go package = getAndLogLatest package
|
go package = getAndLogLatest package
|
||||||
>>= mapM_ checkUpdateAvailability
|
>>= mapM_ checkUpdateAvailability
|
||||||
|
Loading…
Reference in New Issue
Block a user