Provide a name for additional downloads
This commit is contained in:
parent
396a536b3a
commit
64233c4c63
44
app/Main.hs
44
app/Main.hs
@ -8,6 +8,7 @@ import Data.List.NonEmpty (NonEmpty(..))
|
|||||||
import qualified Data.List.NonEmpty as NonEmpty
|
import qualified Data.List.NonEmpty as NonEmpty
|
||||||
import Control.Monad.IO.Class (MonadIO(..))
|
import Control.Monad.IO.Class (MonadIO(..))
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
|
import qualified Data.Map as Map
|
||||||
import Options.Applicative (execParser)
|
import Options.Applicative (execParser)
|
||||||
import SlackBuilder.CommandLine
|
import SlackBuilder.CommandLine
|
||||||
import SlackBuilder.Config
|
import SlackBuilder.Config
|
||||||
@ -24,8 +25,7 @@ import SlackBuilder.Package (Package(..))
|
|||||||
import qualified SlackBuilder.Package as Package
|
import qualified SlackBuilder.Package as Package
|
||||||
import Text.URI (URI(..), mkURI)
|
import Text.URI (URI(..), mkURI)
|
||||||
import Text.URI.QQ (uri)
|
import Text.URI.QQ (uri)
|
||||||
import Crypto.Hash (Digest, MD5)
|
import Data.Foldable (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)
|
||||||
import SlackBuilder.Info
|
import SlackBuilder.Info
|
||||||
@ -197,7 +197,7 @@ autoUpdatable =
|
|||||||
in Package.Updater latest' $ reuploadWithTemplate template []
|
in Package.Updater latest' $ reuploadWithTemplate template []
|
||||||
, category = "libraries"
|
, category = "libraries"
|
||||||
, name = "librsync"
|
, name = "librsync"
|
||||||
, downloaders = []
|
, downloaders = mempty
|
||||||
}
|
}
|
||||||
, Package
|
, Package
|
||||||
{ latest =
|
{ latest =
|
||||||
@ -242,10 +242,10 @@ autoUpdatable =
|
|||||||
:| [Package.VersionPlaceholder]
|
:| [Package.VersionPlaceholder]
|
||||||
dscannerURI = [uri|https://github.com/dlang-community/D-Scanner.git|]
|
dscannerURI = [uri|https://github.com/dlang-community/D-Scanner.git|]
|
||||||
dcdURI = [uri|https://github.com/dlang-community/DCD.git|]
|
dcdURI = [uri|https://github.com/dlang-community/DCD.git|]
|
||||||
in
|
in Map.fromList
|
||||||
[ Package.Updater latestDub $ downloadWithTemplate dubTemplate
|
[ ("DUB", Package.Updater latestDub $ downloadWithTemplate dubTemplate)
|
||||||
, Package.Updater latestDscanner $ cloneFromGit dscannerURI "v"
|
, ("DSCANNER", Package.Updater latestDscanner $ cloneFromGit dscannerURI "v")
|
||||||
, Package.Updater latestDcd $ cloneFromGit dcdURI "v"
|
, ("DCD", Package.Updater latestDcd $ cloneFromGit dcdURI "v")
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -285,11 +285,13 @@ updatePackageIfRequired package@Package{..} version = do
|
|||||||
updatePackage package parsedInfoFile version
|
updatePackage package parsedInfoFile version
|
||||||
Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
|
Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
|
||||||
|
|
||||||
updateDownload :: Package -> Package.Updater -> SlackBuilderT (URI, Digest MD5)
|
updateDownload :: Package -> Package.Updater -> SlackBuilderT (Package.Download, Text)
|
||||||
updateDownload Package{..} Package.Updater{..} = detectLatest
|
updateDownload Package{..} Package.Updater{..} = do
|
||||||
>>= getVersion (Text.pack $ Text.unpack category </> Text.unpack name) . fromJust
|
latestDownloadVersion <- fromJust <$> detectLatest
|
||||||
|
result <- getVersion (Text.pack $ Text.unpack category </> Text.unpack name) latestDownloadVersion
|
||||||
|
pure (result, latestDownloadVersion)
|
||||||
|
|
||||||
cloneFromGit :: URI -> Text -> Text -> Text -> SlackBuilderT (URI, Digest MD5)
|
cloneFromGit :: URI -> Text -> Text -> Text -> SlackBuilderT Package.Download
|
||||||
cloneFromGit repo tagPrefix packagePath version = do
|
cloneFromGit repo tagPrefix packagePath version = do
|
||||||
repository' <- SlackBuilderT $ asks repository
|
repository' <- SlackBuilderT $ asks repository
|
||||||
let downloadFileName = URI.unRText
|
let downloadFileName = URI.unRText
|
||||||
@ -300,10 +302,10 @@ cloneFromGit repo tagPrefix packagePath version = do
|
|||||||
name' = Text.pack (takeBaseName $ Text.unpack packagePath)
|
name' = Text.pack (takeBaseName $ Text.unpack packagePath)
|
||||||
checksum <- clone (URI.render repo) (Text.pack tarball) tagPrefix
|
checksum <- clone (URI.render repo) (Text.pack tarball) tagPrefix
|
||||||
uploadCommand (Text.pack relativeTarball) ("/" <> name')
|
uploadCommand (Text.pack relativeTarball) ("/" <> name')
|
||||||
(, fromJust checksum)
|
(flip . flip Package.Download) (fromJust checksum) False
|
||||||
<$> liftIO (mkURI $ "https://download.dlackware.com/hosted-sources/" <> name' <> "/" <> downloadFileName)
|
<$> liftIO (mkURI $ "https://download.dlackware.com/hosted-sources/" <> name' <> "/" <> downloadFileName)
|
||||||
|
|
||||||
downloadWithTemplate :: Package.DownloadTemplate -> Text -> Text -> SlackBuilderT (URI, Digest MD5)
|
downloadWithTemplate :: Package.DownloadTemplate -> Text -> Text -> SlackBuilderT Package.Download
|
||||||
downloadWithTemplate downloadTemplate packagePath version = do
|
downloadWithTemplate downloadTemplate packagePath version = do
|
||||||
repository' <- SlackBuilderT $ asks repository
|
repository' <- SlackBuilderT $ asks repository
|
||||||
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
||||||
@ -312,17 +314,17 @@ downloadWithTemplate downloadTemplate packagePath version = do
|
|||||||
relativeTarball = packagePath <> "/" <> downloadFileName
|
relativeTarball = packagePath <> "/" <> downloadFileName
|
||||||
tarball = repository' </> Text.unpack relativeTarball
|
tarball = repository' </> Text.unpack relativeTarball
|
||||||
checksum <- fromJust <$> download uri' tarball
|
checksum <- fromJust <$> download uri' tarball
|
||||||
pure (uri', checksum)
|
pure $ Package.Download uri' checksum False
|
||||||
|
|
||||||
reuploadWithTemplate :: Package.DownloadTemplate -> [CmdSpec] -> Text -> Text -> SlackBuilderT (URI, Digest MD5)
|
reuploadWithTemplate :: Package.DownloadTemplate -> [CmdSpec] -> Text -> Text -> SlackBuilderT Package.Download
|
||||||
reuploadWithTemplate downloadTemplate commands packagePath version = do
|
reuploadWithTemplate downloadTemplate commands packagePath version = do
|
||||||
(uri', checksum) <- downloadWithTemplate downloadTemplate packagePath version
|
Package.Download{ download = uri', md5sum = checksum } <- downloadWithTemplate downloadTemplate packagePath version
|
||||||
let downloadFileName = URI.unRText
|
let downloadFileName = URI.unRText
|
||||||
$ NonEmpty.last $ snd $ fromJust $ URI.uriPath uri'
|
$ NonEmpty.last $ snd $ fromJust $ URI.uriPath uri'
|
||||||
relativeTarball = packagePath <> "/" <> downloadFileName
|
relativeTarball = packagePath <> "/" <> downloadFileName
|
||||||
download' <- handleReupload relativeTarball downloadFileName
|
download' <- handleReupload relativeTarball downloadFileName
|
||||||
|
|
||||||
pure (download', checksum)
|
pure $ Package.Download download' checksum False
|
||||||
where
|
where
|
||||||
name' = Text.pack $ takeBaseName $ Text.unpack packagePath
|
name' = Text.pack $ takeBaseName $ Text.unpack packagePath
|
||||||
handleReupload relativeTarball downloadFileName = do
|
handleReupload relativeTarball downloadFileName = do
|
||||||
@ -360,7 +362,7 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
|
|||||||
, child_group = Nothing
|
, child_group = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
renderAndDownload :: Package -> Text -> SlackBuilderT (URI, Digest MD5)
|
renderAndDownload :: Package -> Text -> SlackBuilderT Package.Download
|
||||||
renderAndDownload Package{..} version = do
|
renderAndDownload Package{..} version = do
|
||||||
let packagePath = category <> "/" <> name
|
let packagePath = category <> "/" <> name
|
||||||
Package.Updater _ getVersion = latest
|
Package.Updater _ getVersion = latest
|
||||||
@ -374,13 +376,13 @@ updatePackage package@Package{..} info version = do
|
|||||||
repository' <- SlackBuilderT $ asks repository
|
repository' <- SlackBuilderT $ asks repository
|
||||||
mainDownload <- renderAndDownload package version
|
mainDownload <- renderAndDownload package version
|
||||||
moreDownloads <- traverse (updateDownload package) downloaders
|
moreDownloads <- traverse (updateDownload package) downloaders
|
||||||
let (allDownloads, allChecksums) = unzip $ mainDownload : moreDownloads
|
let allDownloads = mainDownload : toList (fst <$> moreDownloads)
|
||||||
let infoFilePath = repository' </> Text.unpack packagePath
|
let infoFilePath = repository' </> Text.unpack packagePath
|
||||||
</> (Text.unpack name <.> "info")
|
</> (Text.unpack name <.> "info")
|
||||||
package' = info
|
package' = info
|
||||||
{ version = version
|
{ version = version
|
||||||
, downloads = allDownloads
|
, downloads = getField @"download" <$> allDownloads
|
||||||
, checksums = allChecksums
|
, checksums = getField @"md5sum" <$> allDownloads
|
||||||
}
|
}
|
||||||
liftIO $ Text.IO.writeFile infoFilePath $ generate package'
|
liftIO $ Text.IO.writeFile infoFilePath $ generate package'
|
||||||
updateSlackBuildVersion packagePath version
|
updateSlackBuildVersion packagePath version
|
||||||
|
@ -17,11 +17,12 @@ import qualified Text.URI as URI
|
|||||||
import Crypto.Hash (Digest, MD5)
|
import Crypto.Hash (Digest, MD5)
|
||||||
import SlackBuilder.Trans
|
import SlackBuilder.Trans
|
||||||
import Control.Monad.Catch (MonadThrow)
|
import Control.Monad.Catch (MonadThrow)
|
||||||
|
import Data.Map (Map)
|
||||||
|
|
||||||
-- | 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]
|
, downloaders :: Map Text Updater
|
||||||
, category :: Text
|
, category :: Text
|
||||||
, name :: Text
|
, name :: Text
|
||||||
}
|
}
|
||||||
@ -79,5 +80,5 @@ renderDownloadWithVersion (DownloadTemplate components) version =
|
|||||||
-- | Function used to get the latest version of a source.
|
-- | Function used to get the latest version of a source.
|
||||||
data Updater = Updater
|
data Updater = Updater
|
||||||
{ detectLatest :: SlackBuilderT (Maybe Text)
|
{ detectLatest :: SlackBuilderT (Maybe Text)
|
||||||
, getVersion :: Text -> Text -> SlackBuilderT (URI, Digest MD5)
|
, getVersion :: Text -> Text -> SlackBuilderT Download
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ common dependencies
|
|||||||
build-depends:
|
build-depends:
|
||||||
base ^>= 4.16.4.0,
|
base ^>= 4.16.4.0,
|
||||||
bytestring ^>= 0.11.0,
|
bytestring ^>= 0.11.0,
|
||||||
|
containers ^>= 0.6,
|
||||||
cryptonite >= 0.30,
|
cryptonite >= 0.30,
|
||||||
directory ^>= 1.3.8,
|
directory ^>= 1.3.8,
|
||||||
filepath ^>= 1.4.2,
|
filepath ^>= 1.4.2,
|
||||||
|
Loading…
Reference in New Issue
Block a user