Compare commits

...

3 Commits

6 changed files with 82 additions and 29 deletions

View File

@ -22,6 +22,7 @@ import Text.URI.QQ (uri)
import Data.Foldable (for_) import Data.Foldable (for_)
import qualified Text.URI as URI import qualified Text.URI as URI
import GHC.Records (HasField(..)) import GHC.Records (HasField(..))
import System.FilePath ((</>), (<.>))
data Package = Package data Package = Package
{ latest :: Package.Updater { latest :: Package.Updater
@ -77,12 +78,20 @@ updatePackage Package{..} version = do
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
let tarball = "slackbuilds/development/universal-ctags/ctags-#{version}.tar.gz" let tarball = "slackbuilds/development/universal-ctags/ctags-#{version}.tar.gz"
checksum <- fromMaybe undefined <$> download uri' tarball checksum <- fromMaybe undefined <$> download uri' tarball
download' <- liftIO $ mkURI "https://download.dlackware.com/hosted-sources/universal-ctags/ctags-#{version}.tar.gz" download' <- liftIO
$ mkURI
$ Text.replace "#{version}" version
"https://download.dlackware.com/hosted-sources/universal-ctags/ctags-#{version}.tar.gz"
repository' <- SlackBuilderT $ asks repository
let infoFilePath = repository' </> Text.unpack packagePath
</> (Text.unpack name <.> "info")
liftIO $ Text.IO.writeFile "slackbuilds/#{package.path}/#{package.name}.info" liftIO $ Text.IO.writeFile infoFilePath
$ Package.infoTemplate package' [Package.Download download' checksum False] $ Package.infoTemplate package' [Package.Download download' checksum False]
updateSlackBuildVersion packagePath version updateSlackBuildVersion packagePath version
uploadCommand (Text.pack tarball) "#{CONFIG[:remote_path]}/universal-ctags"
remotePath' <- SlackBuilderT $ asks remotePath
uploadCommand (Text.pack tarball) $ remotePath' <> "/universal-ctags"
commit packagePath version commit packagePath version

View File

@ -63,12 +63,13 @@ instance Show DownloadTemplate
where where
show (DownloadTemplate components) = concatMap show components show (DownloadTemplate components) = concatMap show components
-- | Replaces placeholders in the URL template with the given version.
renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI
renderDownloadWithVersion (DownloadTemplate components) version = renderDownloadWithVersion (DownloadTemplate components) version =
URI.mkURI $ foldr f "" components URI.mkURI $ foldr f "" components
where where
f (StaticPlaceholder staticPlaceholder) accumulator = accumulator <> staticPlaceholder f (StaticPlaceholder staticPlaceholder) = (staticPlaceholder <>)
f VersionPlaceholder accumulator = accumulator <> version f VersionPlaceholder = (version <>)
-- | Function used to get the latest version of a source. -- | Function used to get the latest version of a source.
data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate

View File

@ -15,16 +15,14 @@ maintainer: belka@caraus.de
category: Build category: Build
extra-source-files: CHANGELOG.md extra-source-files: CHANGELOG.md
executable slackbuilder common dependencies
main-is: Main.hs build-depends:
base ^>= 4.16.4.0,
other-modules: cryptonite >= 0.30,
SlackBuilder.CommandLine filepath ^>= 1.4.2,
SlackBuilder.Config modern-uri ^>= 0.3.6,
SlackBuilder.Download text ^>= 2.0
SlackBuilder.Package default-language: Haskell2010
SlackBuilder.Trans
SlackBuilder.Updater
default-extensions: default-extensions:
DataKinds DataKinds
DuplicateRecordFields DuplicateRecordFields
@ -35,35 +33,53 @@ executable slackbuilder
QuasiQuotes QuasiQuotes
TemplateHaskell TemplateHaskell
TypeApplications TypeApplications
library slackbuilder-internal
import: dependencies
exposed-modules:
SlackBuilder.Config
SlackBuilder.Package
SlackBuilder.Trans
hs-source-dirs: lib
build-depends:
exceptions >= 0.10,
tomland ^>= 1.3.3,
transformers ^>= 0.5.6
ghc-options: -Wall
executable slackbuilder
import: dependencies
main-is: Main.hs
other-modules:
SlackBuilder.CommandLine
SlackBuilder.Download
SlackBuilder.Updater
build-depends: build-depends:
aeson ^>= 2.2.0, aeson ^>= 2.2.0,
base ^>= 4.16.4.0,
bytestring ^>= 0.11.0, bytestring ^>= 0.11.0,
conduit ^>= 1.3.5, conduit ^>= 1.3.5,
cryptonite >= 0.30,
exceptions >= 0.10,
filepath ^>= 1.4.2,
http-client ^>= 0.7, http-client ^>= 0.7,
modern-uri ^>= 0.3.6,
optparse-applicative ^>= 0.18.1, optparse-applicative ^>= 0.18.1,
process ^>= 1.6.17, process ^>= 1.6.17,
req ^>= 3.13, req ^>= 3.13,
text ^>= 2.0,
tomland ^>= 1.3.3,
transformers ^>= 0.5.6,
unordered-containers ^>= 0.2.19, unordered-containers ^>= 0.2.19,
vector ^>= 0.13.0 vector ^>= 0.13.0
hs-source-dirs: app hs-source-dirs: app
default-language: Haskell2010
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
test-suite slackbuilder-test test-suite slackbuilder-test
import: dependencies
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
main-is: Spec.hs main-is: Spec.hs
hs-source-dirs:
tests other-modules:
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall SlackBuilder.PackageSpec
default-language: Haskell2010 hs-source-dirs: tests
build-depends: build-depends:
hspec >= 2.10.9 && < 2.12 hspec >= 2.10.9 && < 2.12,
slackbuilder-internal
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall

View File

@ -0,0 +1,27 @@
module SlackBuilder.PackageSpec
( spec
) where
import Data.List.NonEmpty (NonEmpty(..))
import SlackBuilder.Package
import Test.Hspec (Spec, describe, it, shouldBe)
import Text.URI.QQ (uri)
spec :: Spec
spec = do
describe "renderDownloadWithVersion" $ do
it "renders text as URL" $
let given = DownloadTemplate
$ pure
$ StaticPlaceholder "https://example.com"
actual = renderDownloadWithVersion given "1.2"
expected = Just [uri|https://example.com|]
in actual `shouldBe` expected
it "renders the components in order" $
let given = DownloadTemplate
$ StaticPlaceholder "https://example.com/"
:| [VersionPlaceholder, StaticPlaceholder "/segment"]
actual = renderDownloadWithVersion given "1.2"
expected = Just [uri|https://example.com/1.2/segment|]
in actual `shouldBe` expected