diff options
Diffstat (limited to 'app/Main.hs')
| -rw-r--r-- | app/Main.hs | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/app/Main.hs b/app/Main.hs index e8cd335..7766959 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -12,6 +12,7 @@ import SlackBuilder.Config import SlackBuilder.Trans import SlackBuilder.Updater import qualified Toml +import qualified Data.ByteString as ByteString import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.IO as Text.IO @@ -24,6 +25,8 @@ import Data.Foldable (for_) import qualified Text.URI as URI import GHC.Records (HasField(..)) import System.FilePath ((</>), (<.>)) +import SlackBuilder.Info +import Text.Megaparsec (parse, errorBundlePretty) data Package = Package { latest :: Package.Updater @@ -89,19 +92,51 @@ autoUpdatable = , requires = mempty , reupload = False } + , Package + { latest = + let ghArguments = GhArguments + { owner = "php" + , name = "php-src" + , transform = Nothing + } + checkVersion x + | Text.isPrefixOf "php-8.2." x = Text.stripPrefix "php-" x + | otherwise = Nothing + latest' = latestGitHub ghArguments checkVersion + template = Package.DownloadTemplate + $ Package.StaticPlaceholder "https://www.php.net/distributions/php-" + :| Package.VersionPlaceholder + : [Package.StaticPlaceholder ".tar.xz"] + in Package.Updater latest' template + , category = "development" + , name = "php82" + , homepage = Just [uri|https://www.php.net/|] + , requires = ["postgresql"] + , reupload = False + } ] up2Date :: SlackBuilderT () up2Date = for_ autoUpdatable go where - go package = getAndLogLatest package >>= mapM_ (updatePackage package) + go package = getAndLogLatest package >>= mapM_ (updatePackageIfRequired package) getAndLogLatest Package{ latest = Package.Updater getLatest _, name } = liftIO (putStrLn $ Text.unpack name <> ": Retreiving the latest version.") >> getLatest +updatePackageIfRequired :: Package -> Text -> SlackBuilderT () +updatePackageIfRequired package@Package{..} version = do + let packagePath = Text.unpack category </> Text.unpack name </> (Text.unpack name <.> "info") + repository' <- SlackBuilderT $ asks repository + infoContents <- liftIO $ ByteString.readFile $ repository' </> packagePath + + case parse parseInfoFile packagePath infoContents of + Right _parsedInfoFile -> updatePackage package version + Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle + updatePackage :: Package -> Text -> SlackBuilderT () updatePackage Package{..} version = do - maintainer' <- SlackBuilderT $ asks maintainer + maintainer' <- SlackBuilderT $ asks $ getField @"maintainer" let packagePath = category <> "/" <> name package' = Package.PackageInfo { version = version |
