Support additional downloads in the package

This commit is contained in:
Eugen Wissner 2023-10-24 21:06:37 +02:00
parent 8a69240d88
commit 58a1b8864c
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
2 changed files with 62 additions and 15 deletions

View File

@ -22,7 +22,8 @@ import Control.Monad.Trans.Reader (ReaderT(..), asks)
import SlackBuilder.Download import SlackBuilder.Download
import SlackBuilder.Package (Package(..)) import SlackBuilder.Package (Package(..))
import qualified SlackBuilder.Package as Package import qualified SlackBuilder.Package as Package
import Text.URI (mkURI) import Text.URI (URI(..), mkURI)
import Crypto.Hash (Digest, MD5)
import Data.Foldable (for_, find) import Data.Foldable (for_, find)
import qualified Text.URI as URI import qualified Text.URI as URI
import System.FilePath ((</>), (<.>), dropExtension, takeBaseName, makeRelative, splitFileName) import System.FilePath ((</>), (<.>), dropExtension, takeBaseName, makeRelative, splitFileName)
@ -67,6 +68,7 @@ autoUpdatable =
, category = "development" , category = "development"
, name = "universal-ctags" , name = "universal-ctags"
, reupload = Just [] , reupload = Just []
, downloaders = mempty
} }
, Package , Package
{ latest = { latest =
@ -79,6 +81,7 @@ autoUpdatable =
, category = "development" , category = "development"
, name = "composer" , name = "composer"
, reupload = Nothing , reupload = Nothing
, downloaders = mempty
} }
, Package , Package
{ latest = { latest =
@ -96,6 +99,7 @@ autoUpdatable =
, category = "network" , category = "network"
, name = "jitsi-meet-desktop" , name = "jitsi-meet-desktop"
, reupload = Nothing , reupload = Nothing
, downloaders = mempty
} }
, Package , Package
{ latest = { latest =
@ -117,6 +121,7 @@ autoUpdatable =
, category = "development" , category = "development"
, name = "php82" , name = "php82"
, reupload = Nothing , reupload = Nothing
, downloaders = mempty
} }
, Package , Package
{ latest = { latest =
@ -139,6 +144,7 @@ autoUpdatable =
, category = "system" , category = "system"
, name = "kitty" , name = "kitty"
, reupload = Just [RawCommand "go" ["mod", "vendor"]] , reupload = Just [RawCommand "go" ["mod", "vendor"]]
, downloaders = mempty
} }
, Package , Package
{ latest = { latest =
@ -158,6 +164,7 @@ autoUpdatable =
, category = "system" , category = "system"
, name = "rdiff-backup" , name = "rdiff-backup"
, reupload = Just mempty , reupload = Just mempty
, downloaders = mempty
} }
, Package , Package
{ latest = { latest =
@ -177,6 +184,7 @@ autoUpdatable =
, category = "network" , category = "network"
, name = "webex" , name = "webex"
, reupload = Nothing , reupload = Nothing
, downloaders = mempty
} }
, Package , Package
{ latest = { latest =
@ -196,6 +204,7 @@ autoUpdatable =
, category = "libraries" , category = "libraries"
, name = "librsync" , name = "librsync"
, reupload = Just mempty , reupload = Just mempty
, downloaders = []
} }
, Package , Package
{ latest = { latest =
@ -214,6 +223,29 @@ autoUpdatable =
, category = "development" , category = "development"
, name = "dmd" , name = "dmd"
, reupload = Nothing , reupload = Nothing
, downloaders = mempty
}
, Package
{ latest =
let textArguments = TextArguments
{ textURL = "https://downloads.dlang.org/releases/LATEST"
, versionPicker = Text.strip
}
latest' = latestText textArguments
template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://codeload.github.com/dlang/tools/tar.gz/v"
:| [Package.VersionPlaceholder]
in Package.Updater latest' template
, category = "development"
, name = "d-tools"
, reupload = Just []
, downloaders =
let dubArguments = GhArguments{ owner = "dlang", name = "dub", transform = Nothing}
latestDub = latestGitHub dubArguments pure
dubTemplate = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://codeload.github.com/dlang/dub/tar.gz/v"
:| [Package.VersionPlaceholder]
in [Package.Updater latestDub dubTemplate]
} }
] ]
@ -244,10 +276,13 @@ updatePackageIfRequired package@Package{..} version = do
| otherwise -> updatePackage package parsedInfoFile version | otherwise -> updatePackage package parsedInfoFile version
Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
updatePackage :: Package -> PackageInfo -> Text -> SlackBuilderT () updateDownload :: Package -> Package.Updater -> SlackBuilderT (URI, Digest MD5)
updatePackage Package{..} info version = do updateDownload package (Package.Updater updater downloadTemplate) = updater
>>= renderAndDownload package downloadTemplate . fromJust
renderAndDownload :: Package -> Package.DownloadTemplate -> Text -> SlackBuilderT (URI, Digest MD5)
renderAndDownload Package{..} downloadTemplate version = do
let packagePath = category <> "/" <> name let packagePath = category <> "/" <> name
Package.Updater _ downloadTemplate = latest
repository' <- SlackBuilderT $ asks repository repository' <- SlackBuilderT $ asks repository
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
@ -259,18 +294,8 @@ updatePackage Package{..} info version = do
$ "Downloading " <> Text.unpack (URI.render uri') <> " to " <> tarball <> "." $ "Downloading " <> Text.unpack (URI.render uri') <> " to " <> tarball <> "."
checksum <- fromJust <$> download uri' tarball checksum <- fromJust <$> download uri' tarball
download' <- handleReupload uri' relativeTarball downloadFileName download' <- handleReupload uri' relativeTarball downloadFileName
let infoFilePath = repository' </> Text.unpack packagePath
</> (Text.unpack name <.> "info")
package' = info
{ version = version
, downloads = [download']
, checksums = [checksum]
}
liftIO $ Text.IO.writeFile infoFilePath $ generate package' pure (download', checksum)
updateSlackBuildVersion packagePath version
commit packagePath version
where where
handleReupload uri' relativeTarball downloadFileName = do handleReupload uri' relativeTarball downloadFileName = do
repository' <- SlackBuilderT $ asks repository repository' <- SlackBuilderT $ asks repository
@ -308,6 +333,27 @@ updatePackage Package{..} info version = do
, child_group = Nothing , child_group = Nothing
} }
updatePackage :: Package -> PackageInfo -> Text -> SlackBuilderT ()
updatePackage package@Package{..} info version = do
let packagePath = category <> "/" <> name
Package.Updater _ downloadTemplate = latest
repository' <- SlackBuilderT $ asks repository
mainDownload <- renderAndDownload package downloadTemplate version
moreDownloads <- traverse (updateDownload package) downloaders
let (allDownloads, allChecksums) = unzip $ mainDownload : moreDownloads
let infoFilePath = repository' </> Text.unpack packagePath
</> (Text.unpack name <.> "info")
package' = info
{ version = version
, downloads = allDownloads
, checksums = allChecksums
}
liftIO $ Text.IO.writeFile infoFilePath $ generate package'
updateSlackBuildVersion packagePath version
commit packagePath version
findCategory :: FilePath -> IO [FilePath] findCategory :: FilePath -> IO [FilePath]
findCategory currentDirectory = do findCategory currentDirectory = do
contents <- liftIO $ listDirectory currentDirectory contents <- liftIO $ listDirectory currentDirectory

View File

@ -22,6 +22,7 @@ import System.Process (CmdSpec(..))
-- | Contains information how a package can be updated. -- | Contains information how a package can be updated.
data Package = Package data Package = Package
{ latest :: Updater { latest :: Updater
, downloaders :: [Updater]
, category :: Text , category :: Text
, name :: Text , name :: Text
, reupload :: Maybe [CmdSpec] , reupload :: Maybe [CmdSpec]