Migrate composer updater
This commit is contained in:
parent
69b24c6cfa
commit
f4b7883cf2
45
app/Main.hs
45
app/Main.hs
@ -3,8 +3,9 @@ module Main
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.List.NonEmpty (NonEmpty(..))
|
import Data.List.NonEmpty (NonEmpty(..))
|
||||||
|
import qualified Data.List.NonEmpty as NonEmpty
|
||||||
import Control.Monad.IO.Class (MonadIO(..))
|
import Control.Monad.IO.Class (MonadIO(..))
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromJust, fromMaybe)
|
||||||
import Options.Applicative (execParser)
|
import Options.Applicative (execParser)
|
||||||
import SlackBuilder.CommandLine
|
import SlackBuilder.CommandLine
|
||||||
import SlackBuilder.Config
|
import SlackBuilder.Config
|
||||||
@ -30,6 +31,7 @@ data Package = Package
|
|||||||
, name :: Text
|
, name :: Text
|
||||||
, homepage :: Maybe URI
|
, homepage :: Maybe URI
|
||||||
, requires :: [Text]
|
, requires :: [Text]
|
||||||
|
, reupload :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
autoUpdatable :: [Package]
|
autoUpdatable :: [Package]
|
||||||
@ -45,12 +47,28 @@ autoUpdatable =
|
|||||||
, Package.StaticPlaceholder ".tar.gz"
|
, Package.StaticPlaceholder ".tar.gz"
|
||||||
]
|
]
|
||||||
template = Package.DownloadTemplate
|
template = Package.DownloadTemplate
|
||||||
$ Package.StaticPlaceholder "https://github.com/universal-ctags/ctags/archive/" :| templateTail
|
$ Package.StaticPlaceholder "https://github.com/universal-ctags/ctags/archive/"
|
||||||
|
:| templateTail
|
||||||
in Package.Updater latest' template
|
in Package.Updater latest' template
|
||||||
, category = "development"
|
, category = "development"
|
||||||
, name = "universal-ctags"
|
, name = "universal-ctags"
|
||||||
, homepage = Just [uri|https://ctags.io/|]
|
, homepage = Just [uri|https://ctags.io/|]
|
||||||
, requires = pure "%README%"
|
, requires = pure "%README%"
|
||||||
|
, reupload = True
|
||||||
|
}
|
||||||
|
, Package
|
||||||
|
{ latest =
|
||||||
|
let packagistArguments = PackagistArguments{ vendor = "composer", name = "composer" }
|
||||||
|
latest' = latestPackagist packagistArguments
|
||||||
|
template = Package.DownloadTemplate
|
||||||
|
$ Package.StaticPlaceholder "https://getcomposer.org/download/"
|
||||||
|
:| [Package.VersionPlaceholder, Package.StaticPlaceholder "/composer.phar"]
|
||||||
|
in Package.Updater latest' template
|
||||||
|
, category = "development"
|
||||||
|
, name = "composer"
|
||||||
|
, homepage = Just [uri|https://getcomposer.org/|]
|
||||||
|
, requires = mempty
|
||||||
|
, reupload = False
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -80,15 +98,14 @@ updatePackage Package{..} version = do
|
|||||||
|
|
||||||
repository' <- SlackBuilderT $ asks repository
|
repository' <- SlackBuilderT $ asks repository
|
||||||
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
||||||
let relativeTarball = Text.replace "#{version}" version
|
let downloadFileName = URI.unRText
|
||||||
"development/universal-ctags/ctags-#{version}.tar.gz"
|
$ NonEmpty.last $ snd $ fromJust $ URI.uriPath uri'
|
||||||
|
relativeTarball = packagePath <> "/" <> downloadFileName
|
||||||
tarball = repository' </> Text.unpack relativeTarball
|
tarball = repository' </> Text.unpack relativeTarball
|
||||||
liftIO $ putStrLn
|
liftIO $ putStrLn
|
||||||
$ "Downloading " <> Text.unpack (URI.render uri') <> " to " <> tarball <> "."
|
$ "Downloading " <> Text.unpack (URI.render uri') <> " to " <> tarball <> "."
|
||||||
checksum <- fromMaybe undefined <$> download uri' tarball
|
checksum <- fromJust <$> download uri' tarball
|
||||||
download' <- liftIO $ mkURI
|
download' <- handleReupload uri' relativeTarball downloadFileName
|
||||||
$ Text.replace "#{version}" version
|
|
||||||
"https://download.dlackware.com/hosted-sources/universal-ctags/ctags-#{version}.tar.gz"
|
|
||||||
let infoFilePath = repository' </> Text.unpack packagePath
|
let infoFilePath = repository' </> Text.unpack packagePath
|
||||||
</> (Text.unpack name <.> "info")
|
</> (Text.unpack name <.> "info")
|
||||||
|
|
||||||
@ -96,11 +113,15 @@ updatePackage Package{..} version = do
|
|||||||
$ Package.infoTemplate package' [Package.Download download' checksum False]
|
$ Package.infoTemplate package' [Package.Download download' checksum False]
|
||||||
updateSlackBuildVersion packagePath version
|
updateSlackBuildVersion packagePath version
|
||||||
|
|
||||||
liftIO $ putStrLn
|
|
||||||
$ "Upload the source tarball " <> Text.unpack relativeTarball
|
|
||||||
uploadCommand relativeTarball "/universal-ctags"
|
|
||||||
|
|
||||||
commit packagePath version
|
commit packagePath version
|
||||||
|
where
|
||||||
|
handleReupload uri' relativeTarball downloadFileName
|
||||||
|
| reupload =
|
||||||
|
liftIO (putStrLn $ "Upload the source tarball " <> Text.unpack relativeTarball)
|
||||||
|
>> uploadCommand relativeTarball ("/" <> name)
|
||||||
|
>> liftIO (mkURI $ "https://download.dlackware.com/hosted-sources/" <> name <> "/" <> downloadFileName)
|
||||||
|
| otherwise = pure uri'
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
@ -5,6 +5,7 @@ module SlackBuilder.Trans
|
|||||||
import Control.Monad.Trans.Reader (ReaderT(..))
|
import Control.Monad.Trans.Reader (ReaderT(..))
|
||||||
import SlackBuilder.Config
|
import SlackBuilder.Config
|
||||||
import Control.Monad.IO.Class (MonadIO(..))
|
import Control.Monad.IO.Class (MonadIO(..))
|
||||||
|
import Control.Monad.Catch (MonadCatch(..), MonadThrow(..))
|
||||||
|
|
||||||
newtype SlackBuilderT a = SlackBuilderT
|
newtype SlackBuilderT a = SlackBuilderT
|
||||||
{ runSlackBuilderT :: ReaderT Settings IO a
|
{ runSlackBuilderT :: ReaderT Settings IO a
|
||||||
@ -27,3 +28,12 @@ instance Monad SlackBuilderT
|
|||||||
instance MonadIO SlackBuilderT
|
instance MonadIO SlackBuilderT
|
||||||
where
|
where
|
||||||
liftIO = SlackBuilderT . liftIO
|
liftIO = SlackBuilderT . liftIO
|
||||||
|
|
||||||
|
instance MonadThrow SlackBuilderT
|
||||||
|
where
|
||||||
|
throwM = SlackBuilderT . throwM
|
||||||
|
|
||||||
|
instance MonadCatch SlackBuilderT
|
||||||
|
where
|
||||||
|
catch (SlackBuilderT action) handler =
|
||||||
|
SlackBuilderT $ catch action $ runSlackBuilderT . handler
|
||||||
|
Loading…
Reference in New Issue
Block a user