Make is64 property part of the updater
All checks were successful
Build / audit (push) Successful in 14m26s
Build / test (push) Successful in 14m35s

This commit is contained in:
Eugen Wissner 2024-01-19 09:57:58 +01:00
parent 7edb811dc2
commit 2802194063
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
2 changed files with 102 additions and 55 deletions

View File

@ -34,7 +34,6 @@ data Package = Package
data Download = Download data Download = Download
{ download :: URI { download :: URI
, md5sum :: Digest MD5 , md5sum :: Digest MD5
, is64 :: Bool
} deriving (Eq, Show) } deriving (Eq, Show)
-- | Package maintainer information. -- | Package maintainer information.
@ -74,5 +73,6 @@ 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)
, is64 :: Bool
, getVersion :: Text -> Text -> SlackBuilderT Download , getVersion :: Text -> Text -> SlackBuilderT Download
} }

View File

@ -60,7 +60,6 @@ autoUpdatable =
[ Package [ Package
{ latest = { latest =
let ghArguments = PackageOwner{ owner = "universal-ctags", name = "ctags" } let ghArguments = PackageOwner{ owner = "universal-ctags", name = "ctags" }
latest' = latestGitHub ghArguments stableTagTransform
templateTail = templateTail =
[ Package.VersionPlaceholder [ Package.VersionPlaceholder
, Package.StaticPlaceholder "/ctags-" , Package.StaticPlaceholder "/ctags-"
@ -70,7 +69,11 @@ autoUpdatable =
template = Package.DownloadTemplate template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://github.com/universal-ctags/ctags/archive/" $ Package.StaticPlaceholder "https://github.com/universal-ctags/ctags/archive/"
:| templateTail :| templateTail
in Package.Updater latest' $ reuploadWithTemplate template [] in Package.Updater
{ detectLatest = latestGitHub ghArguments stableTagTransform
, getVersion = reuploadWithTemplate template []
, is64 = False
}
, category = "development" , category = "development"
, name = "universal-ctags" , name = "universal-ctags"
, downloaders = mempty , downloaders = mempty
@ -78,11 +81,14 @@ autoUpdatable =
, Package , Package
{ latest = { latest =
let packagistArguments = PackageOwner{ owner = "composer", name = "composer" } let packagistArguments = PackageOwner{ owner = "composer", name = "composer" }
latest' = latestPackagist packagistArguments
template = Package.DownloadTemplate template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://getcomposer.org/download/" $ Package.StaticPlaceholder "https://getcomposer.org/download/"
:| [Package.VersionPlaceholder, Package.StaticPlaceholder "/composer.phar"] :| [Package.VersionPlaceholder, Package.StaticPlaceholder "/composer.phar"]
in Package.Updater latest' $ downloadWithTemplate template False in Package.Updater
{ detectLatest = latestPackagist packagistArguments
, getVersion = downloadWithTemplate template
, is64 = False
}
, category = "development" , category = "development"
, name = "composer" , name = "composer"
, downloaders = mempty , downloaders = mempty
@ -93,12 +99,15 @@ autoUpdatable =
{ owner = "jitsi" { owner = "jitsi"
, name = "jitsi-meet-electron" , name = "jitsi-meet-electron"
} }
latest' = latestGitHub ghArguments $ Text.stripPrefix "v"
template = Package.DownloadTemplate template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://github.com/jitsi/jitsi-meet-electron/releases/download/v" $ Package.StaticPlaceholder "https://github.com/jitsi/jitsi-meet-electron/releases/download/v"
:| Package.VersionPlaceholder :| Package.VersionPlaceholder
: [Package.StaticPlaceholder "/jitsi-meet-x86_64.AppImage"] : [Package.StaticPlaceholder "/jitsi-meet-x86_64.AppImage"]
in Package.Updater latest' $ downloadWithTemplate template False in Package.Updater
{ detectLatest = latestGitHub ghArguments $ Text.stripPrefix "v"
, getVersion = downloadWithTemplate template
, is64 = True
}
, category = "network" , category = "network"
, name = "jitsi-meet-desktop" , name = "jitsi-meet-desktop"
, downloaders = mempty , downloaders = mempty
@ -113,12 +122,15 @@ autoUpdatable =
| not $ Text.isInfixOf "RC" x | not $ Text.isInfixOf "RC" x
, Text.isPrefixOf "php-8.2." x = Text.stripPrefix "php-" x , Text.isPrefixOf "php-8.2." x = Text.stripPrefix "php-" x
| otherwise = Nothing | otherwise = Nothing
latest' = latestGitHub ghArguments checkVersion
template = Package.DownloadTemplate template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://www.php.net/distributions/php-" $ Package.StaticPlaceholder "https://www.php.net/distributions/php-"
:| Package.VersionPlaceholder :| Package.VersionPlaceholder
: [Package.StaticPlaceholder ".tar.xz"] : [Package.StaticPlaceholder ".tar.xz"]
in Package.Updater latest' $ downloadWithTemplate template False in Package.Updater
{ detectLatest = latestGitHub ghArguments checkVersion
, getVersion = downloadWithTemplate template
, is64 = False
}
, category = "development" , category = "development"
, name = "php82" , name = "php82"
, downloaders = mempty , downloaders = mempty
@ -129,7 +141,6 @@ autoUpdatable =
{ owner = "kovidgoyal" { owner = "kovidgoyal"
, name = "kitty" , name = "kitty"
} }
latest' = latestGitHub ghArguments stableTagTransform
templateTail = templateTail =
[ Package.StaticPlaceholder "/kitty-" [ Package.StaticPlaceholder "/kitty-"
, Package.VersionPlaceholder , Package.VersionPlaceholder
@ -139,7 +150,11 @@ autoUpdatable =
$ Package.StaticPlaceholder "https://github.com/kovidgoyal/kitty/releases/download/v" $ Package.StaticPlaceholder "https://github.com/kovidgoyal/kitty/releases/download/v"
:| Package.VersionPlaceholder :| Package.VersionPlaceholder
: templateTail : templateTail
in Package.Updater latest' $ reuploadWithTemplate template [RawCommand "go" ["mod", "vendor"]] in Package.Updater
{ detectLatest = latestGitHub ghArguments stableTagTransform
, getVersion = reuploadWithTemplate template [RawCommand "go" ["mod", "vendor"]]
, is64 = False
}
, category = "system" , category = "system"
, name = "kitty" , name = "kitty"
, downloaders = mempty , downloaders = mempty
@ -150,14 +165,17 @@ autoUpdatable =
{ owner = "rdiff-backup" { owner = "rdiff-backup"
, name = "rdiff-backup" , name = "rdiff-backup"
} }
latest' = latestGitHub ghArguments $ Text.stripPrefix "v"
template = Package.DownloadTemplate template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://github.com/rdiff-backup/rdiff-backup/releases/download/v" $ Package.StaticPlaceholder "https://github.com/rdiff-backup/rdiff-backup/releases/download/v"
:| Package.VersionPlaceholder :| Package.VersionPlaceholder
: Package.StaticPlaceholder "/rdiff-backup-" : Package.StaticPlaceholder "/rdiff-backup-"
: Package.VersionPlaceholder : Package.VersionPlaceholder
: [Package.StaticPlaceholder ".tar.gz"] : [Package.StaticPlaceholder ".tar.gz"]
in Package.Updater latest' $ reuploadWithTemplate template [] in Package.Updater
{ detectLatest = latestGitHub ghArguments $ Text.stripPrefix "v"
, getVersion = reuploadWithTemplate template []
, is64 = False
}
, category = "system" , category = "system"
, name = "rdiff-backup" , name = "rdiff-backup"
, downloaders = mempty , downloaders = mempty
@ -172,11 +190,14 @@ autoUpdatable =
. snd . snd
. Text.breakOn needle . Text.breakOn needle
} }
latest' = latestText textArguments
template = Package.DownloadTemplate $ pure template = Package.DownloadTemplate $ pure
$ Package.StaticPlaceholder $ Package.StaticPlaceholder
"https://binaries.webex.com/WebexDesktop-Ubuntu-Official-Package/Webex.deb" "https://binaries.webex.com/WebexDesktop-Ubuntu-Official-Package/Webex.deb"
in Package.Updater latest' $ downloadWithTemplate template True in Package.Updater
{ detectLatest = latestText textArguments
, getVersion = downloadWithTemplate template
, is64 = True
}
, category = "network" , category = "network"
, name = "webex" , name = "webex"
, downloaders = mempty , downloaders = mempty
@ -187,14 +208,17 @@ autoUpdatable =
{ owner = "librsync" { owner = "librsync"
, name = "librsync" , name = "librsync"
} }
latest' = latestGitHub ghArguments $ Text.stripPrefix "v"
template = Package.DownloadTemplate template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://github.com/librsync/librsync/archive/v" $ Package.StaticPlaceholder "https://github.com/librsync/librsync/archive/v"
:| Package.VersionPlaceholder :| Package.VersionPlaceholder
: Package.StaticPlaceholder "/librsync-" : Package.StaticPlaceholder "/librsync-"
: Package.VersionPlaceholder : Package.VersionPlaceholder
: [Package.StaticPlaceholder ".tar.gz"] : [Package.StaticPlaceholder ".tar.gz"]
in Package.Updater latest' $ reuploadWithTemplate template [] in Package.Updater
{ detectLatest = latestGitHub ghArguments $ Text.stripPrefix "v"
, getVersion = reuploadWithTemplate template []
, is64 = True
}
, category = "libraries" , category = "libraries"
, name = "librsync" , name = "librsync"
, downloaders = mempty , downloaders = mempty
@ -205,14 +229,17 @@ autoUpdatable =
{ textURL = "https://downloads.dlang.org/releases/LATEST" { textURL = "https://downloads.dlang.org/releases/LATEST"
, versionPicker = Text.strip , versionPicker = Text.strip
} }
latest' = latestText textArguments
template = Package.DownloadTemplate template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://downloads.dlang.org/releases/2.x/" $ Package.StaticPlaceholder "https://downloads.dlang.org/releases/2.x/"
:| Package.VersionPlaceholder :| Package.VersionPlaceholder
: Package.StaticPlaceholder "/dmd." : Package.StaticPlaceholder "/dmd."
: Package.VersionPlaceholder : Package.VersionPlaceholder
: [Package.StaticPlaceholder ".linux.tar.xz"] : [Package.StaticPlaceholder ".linux.tar.xz"]
in Package.Updater latest' $ downloadWithTemplate template False in Package.Updater
{ detectLatest = latestText textArguments
, getVersion = downloadWithTemplate template
, is64 = False
}
, category = "development" , category = "development"
, name = "dmd" , name = "dmd"
, downloaders = mempty , downloaders = mempty
@ -223,29 +250,44 @@ autoUpdatable =
{ textURL = "https://downloads.dlang.org/releases/LATEST" { textURL = "https://downloads.dlang.org/releases/LATEST"
, versionPicker = Text.strip , versionPicker = Text.strip
} }
latest' = latestText textArguments
template = Package.DownloadTemplate template = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://codeload.github.com/dlang/tools/tar.gz/v" $ Package.StaticPlaceholder "https://codeload.github.com/dlang/tools/tar.gz/v"
:| [Package.VersionPlaceholder] :| [Package.VersionPlaceholder]
in Package.Updater latest' $ reuploadWithTemplate template [] in Package.Updater
{ detectLatest = latestText textArguments
, getVersion = reuploadWithTemplate template []
, is64 = False
}
, category = "development" , category = "development"
, name = "d-tools" , name = "d-tools"
, downloaders = , downloaders =
let dubArguments = PackageOwner{ owner = "dlang", name = "dub" } let dubArguments = PackageOwner{ owner = "dlang", name = "dub" }
dscannerArguments = PackageOwner{ owner = "dlang-community", name = "D-Scanner" } dscannerArguments = PackageOwner{ owner = "dlang-community", name = "D-Scanner" }
dcdArguments = PackageOwner{ owner = "dlang-community", name = "DCD" } dcdArguments = PackageOwner{ owner = "dlang-community", name = "DCD" }
latestDub = latestGitHub dubArguments stableTagTransform latestDub = Package.Updater
latestDscanner = latestGitHub dscannerArguments stableTagTransform { detectLatest = latestGitHub dubArguments stableTagTransform
latestDcd = latestGitHub dcdArguments stableTagTransform , getVersion = downloadWithTemplate dubTemplate
, is64 = False
}
latestDscanner = Package.Updater
{ detectLatest = latestGitHub dscannerArguments stableTagTransform
, getVersion = cloneFromGit dscannerURI "v"
, is64 = False
}
dcdURI = [uri|https://github.com/dlang-community/DCD.git|]
latestDcd = Package.Updater
{ detectLatest = latestGitHub dcdArguments stableTagTransform
, getVersion = cloneFromGit dcdURI "v"
, is64 = False
}
dubTemplate = Package.DownloadTemplate dubTemplate = Package.DownloadTemplate
$ Package.StaticPlaceholder "https://codeload.github.com/dlang/dub/tar.gz/v" $ Package.StaticPlaceholder "https://codeload.github.com/dlang/dub/tar.gz/v"
:| [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|]
in Map.fromList in Map.fromList
[ ("DUB", Package.Updater latestDub $ downloadWithTemplate dubTemplate False) [ ("DUB", latestDub)
, ("DSCANNER", Package.Updater latestDscanner $ cloneFromGit dscannerURI "v") , ("DSCANNER", latestDscanner)
, ("DCD", Package.Updater latestDcd $ cloneFromGit dcdURI "v") , ("DCD", latestDcd)
] ]
} }
] ]
@ -307,11 +349,21 @@ updatePackageIfRequired package version
= checkUpdateAvailability package version = checkUpdateAvailability package version
>>= mapM_ (updatePackage package version) >>= mapM_ (updatePackage package version)
updateDownload :: Package -> Package.Updater -> SlackBuilderT (Package.Download, Text) data DownloadUpdated = DownloadUpdated
updateDownload Package{..} Package.Updater{..} = do { result :: Package.Download
, version :: Text
, is64 :: Bool
} deriving (Eq, Show)
updateDownload :: Text -> Package.Updater -> SlackBuilderT DownloadUpdated
updateDownload packagePath Package.Updater{..} = do
latestDownloadVersion <- fromJust <$> detectLatest latestDownloadVersion <- fromJust <$> detectLatest
result <- getVersion (Text.pack $ Text.unpack category </> Text.unpack name) latestDownloadVersion result <- getVersion packagePath latestDownloadVersion
pure (result, latestDownloadVersion) pure $ DownloadUpdated
{ result = result
, version = latestDownloadVersion
, is64 = is64
}
cloneFromGit :: URI -> Text -> Text -> Text -> SlackBuilderT Package.Download cloneFromGit :: URI -> Text -> Text -> Text -> SlackBuilderT Package.Download
cloneFromGit repo tagPrefix packagePath version = do cloneFromGit repo tagPrefix packagePath version = do
@ -322,12 +374,11 @@ cloneFromGit repo tagPrefix packagePath version = do
(uri', checksum) <- fromJust <$> cloneAndUpload (URI.render repo) relativeTarball tagPrefix (uri', checksum) <- fromJust <$> cloneAndUpload (URI.render repo) relativeTarball tagPrefix
pure $ Package.Download pure $ Package.Download
{ md5sum = checksum { md5sum = checksum
, is64 = False
, download = uri' , download = uri'
} }
downloadWithTemplate :: Package.DownloadTemplate -> Bool -> Text -> Text -> SlackBuilderT Package.Download downloadWithTemplate :: Package.DownloadTemplate -> Text -> Text -> SlackBuilderT Package.Download
downloadWithTemplate downloadTemplate is64' 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
let downloadFileName = URI.unRText let downloadFileName = URI.unRText
@ -335,18 +386,18 @@ downloadWithTemplate downloadTemplate is64' 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 $ Package.Download uri' checksum is64' pure $ Package.Download uri' checksum
reuploadWithTemplate :: Package.DownloadTemplate -> [CmdSpec] -> Text -> Text -> SlackBuilderT Package.Download reuploadWithTemplate :: Package.DownloadTemplate -> [CmdSpec] -> Text -> Text -> SlackBuilderT Package.Download
reuploadWithTemplate downloadTemplate commands packagePath version = do reuploadWithTemplate downloadTemplate commands packagePath version = do
Package.Download{ download = uri', md5sum = checksum } <- Package.Download{ download = uri', md5sum = checksum } <-
downloadWithTemplate downloadTemplate False packagePath version 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 (Text.unpack relativeTarball) downloadFileName download' <- handleReupload (Text.unpack relativeTarball) downloadFileName
pure $ Package.Download download' checksum False pure $ Package.Download download' checksum
where where
name' = Text.pack $ takeBaseName $ Text.unpack packagePath name' = Text.pack $ takeBaseName $ Text.unpack packagePath
handleReupload relativeTarball downloadFileName = do handleReupload relativeTarball downloadFileName = do
@ -384,33 +435,29 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
, child_group = Nothing , child_group = Nothing
} }
renderAndDownload :: Package -> Text -> SlackBuilderT Package.Download
renderAndDownload Package{..} version = do
let packagePath = category <> "/" <> name
Package.Updater _ getVersion = latest
getVersion packagePath version
updatePackage :: Package -> Text -> PackageInfo -> SlackBuilderT () updatePackage :: Package -> Text -> PackageInfo -> SlackBuilderT ()
updatePackage package@Package{..} version info = do updatePackage Package{..} version info = do
let packagePath = category <> "/" <> name let packagePath = category <> "/" <> name
repository' <- SlackBuilderT $ asks repository repository' <- SlackBuilderT $ asks repository
mainDownload <- renderAndDownload package version mainDownload <- (, getField @"is64" latest)
moreDownloads <- traverse (updateDownload package) downloaders <$> getField @"getVersion" latest packagePath version
let (downloads64, allDownloads) = partition (getField @"is64") moreDownloads <- traverse (updateDownload packagePath) downloaders
$ mainDownload : toList (fst <$> moreDownloads) let (downloads64, allDownloads) = partition snd
$ mainDownload
: (liftA2 (,) (getField @"result") (getField @"is64") <$> toList 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 = getField @"download" <$> allDownloads , downloads = getField @"download" . fst <$> allDownloads
, checksums = getField @"md5sum" <$> allDownloads , checksums = getField @"md5sum" . fst <$> allDownloads
, downloadX64 = getField @"download" <$> downloads64 , downloadX64 = getField @"download" . fst <$> downloads64
, checksumX64 = getField @"md5sum" <$> downloads64 , checksumX64 = getField @"md5sum" . fst <$> downloads64
} }
liftIO $ Text.IO.writeFile infoFilePath $ generate package' liftIO $ Text.IO.writeFile infoFilePath $ generate package'
updateSlackBuildVersion packagePath version $ snd <$> moreDownloads updateSlackBuildVersion packagePath version
$ getField @"version" <$> moreDownloads
commit packagePath version commit packagePath version