Include repackaging command into configuration
All checks were successful
Build / audit (push) Successful in 8s
Build / test (push) Successful in 15m0s

This commit is contained in:
Eugen Wissner 2024-09-29 21:24:40 +02:00
parent d9bfd2941c
commit 8168804d71
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 52 additions and 36 deletions

View File

@ -36,6 +36,7 @@ data PackageSettings = PackageSettings
, github :: Maybe (Text, Text)
, packagist :: Maybe (Text, Text)
, text :: Maybe (Text, [String])
, repackage :: Maybe [String]
} deriving (Eq, Show)
settingsCodec :: Toml.TomlCodec Settings
@ -59,7 +60,8 @@ packageSettingsCodec = PackageSettings
<*> Toml.bool "is64" .= is64
<*> Toml.dioptional (Toml.table githubCodec "github") .= github
<*> Toml.dioptional (Toml.table packagistCodec "packagist") .= packagist
<*> Toml.dioptional (Toml.table textCodec "text") .= text
<*> Toml.dioptional (Toml.table textCodec "text") .= text
<*> Toml.dioptional (Toml.arrayOf Toml._String "repackage") .= repackage
where
githubCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
packagistCodec = Toml.pair (Toml.text "owner") (Toml.text "name")

View File

@ -24,7 +24,6 @@ import qualified SlackBuilder.Package as Package
import Text.URI.QQ (uri)
import Data.Foldable (find, traverse_)
import GHC.Records (HasField(..))
import System.Process (CmdSpec(..))
import System.Console.ANSI
( setSGR
, SGR(..)
@ -43,7 +42,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments "(v)\\."
, getVersion = reuploadWithTemplate template []
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "universal-ctags"
@ -56,7 +55,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestPackagist packagistArguments
, getVersion = downloadWithTemplate template
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "composer"
@ -69,7 +68,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments "(v)*"
, getVersion = downloadWithTemplate template
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "jitsi-meet-desktop"
@ -82,7 +81,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments "(php-)8.2.\\d"
, getVersion = downloadWithTemplate template
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "php82"
@ -95,7 +94,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments "(v)\\."
, getVersion = reuploadWithTemplate template [RawCommand "go" ["mod", "vendor"]]
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "kitty"
@ -108,7 +107,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments "(v)\\."
, getVersion = reuploadWithTemplate template []
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "rdiff-backup"
@ -121,7 +120,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestText textArguments "(Linux—)*"
, getVersion = downloadWithTemplate template
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "webex"
@ -134,7 +133,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments "(v)\\."
, getVersion = reuploadWithTemplate template []
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "librsync"
@ -147,7 +146,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestText textArguments "\\."
, getVersion = downloadWithTemplate template
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "dmd"
@ -160,7 +159,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestText textArguments "\\."
, getVersion = reuploadWithTemplate template []
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "d-tools"
@ -170,7 +169,7 @@ autoUpdatable packageSettings =
dcdArguments = PackageOwner{ owner = "dlang-community", name = "DCD" }
latestDub = Package.Updater
{ detectLatest = latestGitHub dubArguments "(v)\\."
, getVersion = reuploadWithTemplate dubTemplate []
, getVersion = reuploadWithTemplate dubTemplate
, is64 = False
}
latestDscanner = Package.Updater
@ -199,7 +198,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments "(v)\\."
, getVersion = downloadWithTemplate template
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "simde"
@ -212,7 +211,7 @@ autoUpdatable packageSettings =
template = Package.DownloadTemplate $ getField @"template" setting
in Package.Updater
{ detectLatest = latestGitHub ghArguments "(release-)\\d.[02468].\\d"
, getVersion = downloadWithTemplate template
, getVersion = repackageWithTemplate (getField @"repackage" setting) template
, is64 = getField @"is64" setting
}
, name = "nginx"

View File

@ -8,6 +8,7 @@ module SlackBuilder.Update
, downloadWithTemplate
, getAndLogLatest
, handleException
, repackageWithTemplate
, reuploadWithTemplate
, updatePackageIfRequired
) where
@ -142,6 +143,12 @@ cloneFromGit repo tagPrefix packagePath version = do
, download = uri'
}
repackageWithTemplate :: Maybe [String] -> Package.DownloadTemplate -> Text -> Text -> SlackBuilderT Package.Download
repackageWithTemplate Nothing template' = downloadWithTemplate template'
repackageWithTemplate (Just (cmd : arguments)) template' =
reuploadWithTemplate' template' (RawCommand cmd arguments)
repackageWithTemplate (Just []) template' = reuploadWithTemplate template'
downloadWithTemplate :: Package.DownloadTemplate -> Text -> Text -> SlackBuilderT Package.Download
downloadWithTemplate downloadTemplate packagePath version = do
repository' <- SlackBuilderT $ asks repository
@ -149,8 +156,19 @@ downloadWithTemplate downloadTemplate packagePath version = do
checksum <- download uri' $ repository' </> Text.unpack packagePath
pure $ Package.Download uri' $ snd checksum
reuploadWithTemplate :: Package.DownloadTemplate -> [CmdSpec] -> Text -> Text -> SlackBuilderT Package.Download
reuploadWithTemplate downloadTemplate commands packagePath version = do
reuploadWithTemplate :: Package.DownloadTemplate -> Text -> Text -> SlackBuilderT Package.Download
reuploadWithTemplate downloadTemplate packagePath version = do
repository' <- SlackBuilderT $ asks repository
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
let packagePathRelativeToCurrent = repository' </> Text.unpack packagePath
(downloadedFileName, checksum) <- download uri' packagePathRelativeToCurrent
download' <- handleReupload packagePath
$ packagePathRelativeToCurrent </> downloadedFileName
pure $ Package.Download download' checksum
reuploadWithTemplate' :: Package.DownloadTemplate -> CmdSpec -> Text -> Text -> SlackBuilderT Package.Download
reuploadWithTemplate' downloadTemplate commands packagePath version = do
repository' <- SlackBuilderT $ asks repository
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
let downloadFileName = Text.unpack
@ -158,22 +176,16 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
$ NonEmpty.last $ snd $ fromJust $ URI.uriPath uri'
packagePathRelativeToCurrent = repository' </> Text.unpack packagePath
(relativeTarball', checksum) <- case commands of
[] -> do
(downloadedFileName, checksum) <- download uri' packagePathRelativeToCurrent
pure (packagePathRelativeToCurrent </> downloadedFileName, checksum)
_ -> do
changedArchiveRootName <- extractRemote uri' packagePathRelativeToCurrent
let relativeTarball = packagePathRelativeToCurrent
</> fromMaybe downloadFileName changedArchiveRootName
prepareSource relativeTarball
changedArchiveRootName <- extractRemote uri' packagePathRelativeToCurrent
let relativeTarball = packagePathRelativeToCurrent
</> fromMaybe downloadFileName changedArchiveRootName
(relativeTarball', checksum) <- prepareSource relativeTarball
download' <- handleReupload relativeTarball'
download' <- handleReupload packagePath relativeTarball'
pure $ Package.Download download' checksum
where
category' = Text.pack $ takeBaseName $ Text.unpack packagePath
prepareSource tarballPath =
liftIO (traverse (defaultCreateProcess tarballPath) commands)
liftIO (defaultCreateProcess tarballPath commands)
>> liftIO (tarCompress tarballPath)
<* liftIO (removeDirectoryRecursive tarballPath)
tarCompress tarballPath =
@ -182,13 +194,6 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
in fmap (appendTarExtension tarballPath,)
$ withCurrentDirectory (takeDirectory tarballPath)
$ createLzmaTarball archiveBaseFilename (appendTarExtension archiveBaseFilename)
handleReupload relativeTarball = do
liftIO $ putStrLn $ "Upload the source tarball " <> relativeTarball
uploadSource relativeTarball category'
hostedSources $ NonEmpty.cons category'
$ pure $ Text.pack $ takeFileName relativeTarball
defaultCreateProcess cwd' cmdSpec
= flip withCreateProcess (const . const . const waitForProcess)
$ CreateProcess
@ -209,6 +214,16 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
, child_group = Nothing
}
handleReupload :: Text -> String -> SlackBuilderT URI
handleReupload packagePath relativeTarball = do
liftIO $ putStrLn $ "Upload the source tarball " <> relativeTarball
uploadSource relativeTarball category'
hostedSources $ NonEmpty.cons category'
$ pure $ Text.pack $ takeFileName relativeTarball
where
category' = Text.pack $ takeBaseName $ Text.unpack packagePath
updatePackage :: PackageUpdateData -> PackageInfo -> SlackBuilderT ()
updatePackage PackageUpdateData{..} info = do
let packagePath = category <> "/" <> getField @"name" description