diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-09-03 10:26:43 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-09-03 10:26:43 +0200 |
| commit | 77c9a2ab54b697f37e21b76c1fd82fc42dc4792e (patch) | |
| tree | 882f48c34d14a9ae58642ea41ba102136d7bf8c4 /app/Main.hs | |
| parent | c2b98ba395aa486c18fa002175d93aa789b231d6 (diff) | |
| download | slackbuilder-77c9a2ab54b697f37e21b76c1fd82fc42dc4792e.tar.gz | |
Add a test module
Diffstat (limited to 'app/Main.hs')
| -rw-r--r-- | app/Main.hs | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/app/Main.hs b/app/Main.hs index 76c985f..51681b5 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,7 +2,8 @@ module Main ( main ) where -import qualified Data.Text.IO as Text.IO +import Data.List.NonEmpty (NonEmpty(..)) +import Control.Monad.IO.Class (MonadIO(..)) import Data.Maybe (fromMaybe) import Options.Applicative (execParser) import SlackBuilder.CommandLine @@ -10,10 +11,80 @@ import SlackBuilder.Config import SlackBuilder.Trans import SlackBuilder.Updater import qualified Toml +import Data.Text (Text) import qualified Data.Text as Text -import Control.Monad.Trans.Reader (ReaderT(..)) +import qualified Data.Text.IO as Text.IO +import Control.Monad.Trans.Reader (ReaderT(..), asks) import SlackBuilder.Download -import Text.URI (mkURI) +import qualified SlackBuilder.Package as Package +import Text.URI (mkURI, URI) +import Text.URI.QQ (uri) +import Data.Foldable (for_) +import qualified Text.URI as URI +import GHC.Records (HasField(..)) + +data Package = Package + { latest :: Package.Updater + , category :: Text + , name :: Text + , homepage :: Maybe URI + , requires :: [Text] + } + +autoUpdatable :: [Package] +autoUpdatable = + [ Package + { latest = + let ghArguments = GhArguments{ owner = "universal-ctags", name = "ctags", transform = Nothing} + latest' = latestGitHub ghArguments pure + templateTail = + [ Package.StaticPlaceholder "/ctags-" + , Package.VersionPlaceholder + , Package.StaticPlaceholder ".tar.gz" + ] + template = Package.DownloadTemplate + $ Package.StaticPlaceholder "https://github.com/universal-ctags/ctags/archive/" :| templateTail + in Package.Updater latest' template + , category = "development" + , name = "universal-ctags" + , homepage = Just [uri|https://ctags.io/|] + , requires = pure "%README%" + } + ] + +up2Date :: SlackBuilderT () +up2Date = for_ autoUpdatable go + where + go package@Package{ latest = Package.Updater getLatest _ } = + getLatest >>= mapM_ (updatePackage package) + +updatePackage :: Package -> Text -> SlackBuilderT () +updatePackage Package{..} version = do + maintainer' <- SlackBuilderT $ asks maintainer + let packagePath = category <> "/" <> name + package' = Package.PackageInfo + { version = version + , requires = requires + , path = Text.unpack packagePath + , homepage = maybe "" URI.render homepage + , maintainer = Package.Maintainer + { name = getField @"name" maintainer' + , email = getField @"email" maintainer' + } + } + Package.Updater _ downloadTemplate = latest + + uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version + let tarball = "slackbuilds/development/universal-ctags/ctags-#{version}.tar.gz" + checksum <- fromMaybe undefined <$> download uri' tarball + download' <- liftIO $ mkURI "https://download.dlackware.com/hosted-sources/universal-ctags/ctags-#{version}.tar.gz" + + liftIO $ Text.IO.writeFile "slackbuilds/#{package.path}/#{package.name}.info" + $ Package.infoTemplate package' [Package.Download download' checksum False] + updateSlackBuildVersion packagePath version + uploadCommand (Text.pack tarball) "#{CONFIG[:remote_path]}/universal-ctags" + + commit packagePath version main :: IO () main = do @@ -40,13 +111,14 @@ main = do ArchiveCommand repo nameVersion tarball tagPrefix -> cloneAndArchive repo nameVersion tarball tagPrefix >> pure Nothing DownloadCommand url target - | Just uri <- mkURI url -> fmap (Text.pack . show) - <$> download uri target + | Just uri' <- mkURI url -> fmap (Text.pack . show) + <$> download uri' target | otherwise -> pure Nothing CloneCommand repo tarball tagPrefix -> fmap (Text.pack . show) <$> clone repo tarball tagPrefix - DownloadAndDeployCommand uri tarball -> fmap (Text.pack . show) - <$> downloadAndDeploy uri tarball + DownloadAndDeployCommand uri' tarball -> fmap (Text.pack . show) + <$> downloadAndDeploy uri' tarball + Up2DateCommand -> up2Date >> pure Nothing chooseTransformFunction (Just "php") = phpTransform chooseTransformFunction (Just "rdiff-backup") = Text.stripPrefix "v" chooseTransformFunction _ = stripPrefix "v" |
