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.Package (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 qualified Text.URI as URI
import System.FilePath ((</>), (<.>), dropExtension, takeBaseName, makeRelative, splitFileName)
@ -67,6 +68,7 @@ autoUpdatable =
, category = "development"
, name = "universal-ctags"
, reupload = Just []
, downloaders = mempty
}
, Package
{ latest =
@ -79,6 +81,7 @@ autoUpdatable =
, category = "development"
, name = "composer"
, reupload = Nothing
, downloaders = mempty
}
, Package
{ latest =
@ -96,6 +99,7 @@ autoUpdatable =
, category = "network"
, name = "jitsi-meet-desktop"
, reupload = Nothing
, downloaders = mempty
}
, Package
{ latest =
@ -117,6 +121,7 @@ autoUpdatable =
, category = "development"
, name = "php82"
, reupload = Nothing
, downloaders = mempty
}
, Package
{ latest =
@ -139,6 +144,7 @@ autoUpdatable =
, category = "system"
, name = "kitty"
, reupload = Just [RawCommand "go" ["mod", "vendor"]]
, downloaders = mempty
}
, Package
{ latest =
@ -158,6 +164,7 @@ autoUpdatable =
, category = "system"
, name = "rdiff-backup"
, reupload = Just mempty
, downloaders = mempty
}
, Package
{ latest =
@ -177,6 +184,7 @@ autoUpdatable =
, category = "network"
, name = "webex"
, reupload = Nothing
, downloaders = mempty
}
, Package
{ latest =
@ -196,6 +204,7 @@ autoUpdatable =
, category = "libraries"
, name = "librsync"
, reupload = Just mempty
, downloaders = []
}
, Package
{ latest =
@ -214,6 +223,29 @@ autoUpdatable =
, category = "development"
, name = "dmd"
, 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
Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
updatePackage :: Package -> PackageInfo -> Text -> SlackBuilderT ()
updatePackage Package{..} info version = do
updateDownload :: Package -> Package.Updater -> SlackBuilderT (URI, Digest MD5)
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
Package.Updater _ downloadTemplate = latest
repository' <- SlackBuilderT $ asks repository
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
@ -259,18 +294,8 @@ updatePackage Package{..} info version = do
$ "Downloading " <> Text.unpack (URI.render uri') <> " to " <> tarball <> "."
checksum <- fromJust <$> download uri' tarball
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'
updateSlackBuildVersion packagePath version
commit packagePath version
pure (download', checksum)
where
handleReupload uri' relativeTarball downloadFileName = do
repository' <- SlackBuilderT $ asks repository
@ -308,6 +333,27 @@ updatePackage Package{..} info version = do
, 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 currentDirectory = do
contents <- liftIO $ listDirectory currentDirectory

View File

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