Compare commits
3 Commits
77c9a2ab54
...
ec704e267b
Author | SHA1 | Date | |
---|---|---|---|
ec704e267b | |||
840290491f | |||
a7114618c1 |
15
app/Main.hs
15
app/Main.hs
@ -22,6 +22,7 @@ import Text.URI.QQ (uri)
|
||||
import Data.Foldable (for_)
|
||||
import qualified Text.URI as URI
|
||||
import GHC.Records (HasField(..))
|
||||
import System.FilePath ((</>), (<.>))
|
||||
|
||||
data Package = Package
|
||||
{ latest :: Package.Updater
|
||||
@ -77,12 +78,20 @@ updatePackage Package{..} version = do
|
||||
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
||||
let tarball = "slackbuilds/development/universal-ctags/ctags-#{version}.tar.gz"
|
||||
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]
|
||||
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
|
||||
|
||||
|
@ -63,12 +63,13 @@ instance Show DownloadTemplate
|
||||
where
|
||||
show (DownloadTemplate components) = concatMap show components
|
||||
|
||||
-- | Replaces placeholders in the URL template with the given version.
|
||||
renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI
|
||||
renderDownloadWithVersion (DownloadTemplate components) version =
|
||||
URI.mkURI $ foldr f "" components
|
||||
where
|
||||
f (StaticPlaceholder staticPlaceholder) accumulator = accumulator <> staticPlaceholder
|
||||
f VersionPlaceholder accumulator = accumulator <> version
|
||||
f (StaticPlaceholder staticPlaceholder) = (staticPlaceholder <>)
|
||||
f VersionPlaceholder = (version <>)
|
||||
|
||||
-- | Function used to get the latest version of a source.
|
||||
data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate
|
@ -15,16 +15,14 @@ maintainer: belka@caraus.de
|
||||
category: Build
|
||||
extra-source-files: CHANGELOG.md
|
||||
|
||||
executable slackbuilder
|
||||
main-is: Main.hs
|
||||
|
||||
other-modules:
|
||||
SlackBuilder.CommandLine
|
||||
SlackBuilder.Config
|
||||
SlackBuilder.Download
|
||||
SlackBuilder.Package
|
||||
SlackBuilder.Trans
|
||||
SlackBuilder.Updater
|
||||
common dependencies
|
||||
build-depends:
|
||||
base ^>= 4.16.4.0,
|
||||
cryptonite >= 0.30,
|
||||
filepath ^>= 1.4.2,
|
||||
modern-uri ^>= 0.3.6,
|
||||
text ^>= 2.0
|
||||
default-language: Haskell2010
|
||||
default-extensions:
|
||||
DataKinds
|
||||
DuplicateRecordFields
|
||||
@ -35,35 +33,53 @@ executable slackbuilder
|
||||
QuasiQuotes
|
||||
TemplateHaskell
|
||||
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:
|
||||
aeson ^>= 2.2.0,
|
||||
base ^>= 4.16.4.0,
|
||||
bytestring ^>= 0.11.0,
|
||||
conduit ^>= 1.3.5,
|
||||
cryptonite >= 0.30,
|
||||
exceptions >= 0.10,
|
||||
filepath ^>= 1.4.2,
|
||||
http-client ^>= 0.7,
|
||||
modern-uri ^>= 0.3.6,
|
||||
optparse-applicative ^>= 0.18.1,
|
||||
process ^>= 1.6.17,
|
||||
req ^>= 3.13,
|
||||
text ^>= 2.0,
|
||||
tomland ^>= 1.3.3,
|
||||
transformers ^>= 0.5.6,
|
||||
unordered-containers ^>= 0.2.19,
|
||||
vector ^>= 0.13.0
|
||||
hs-source-dirs: app
|
||||
default-language: Haskell2010
|
||||
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||
|
||||
test-suite slackbuilder-test
|
||||
import: dependencies
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Spec.hs
|
||||
hs-source-dirs:
|
||||
tests
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||
default-language: Haskell2010
|
||||
|
||||
other-modules:
|
||||
SlackBuilder.PackageSpec
|
||||
hs-source-dirs: tests
|
||||
build-depends:
|
||||
hspec >= 2.10.9 && < 2.12
|
||||
hspec >= 2.10.9 && < 2.12,
|
||||
slackbuilder-internal
|
||||
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||
|
27
tests/SlackBuilder/PackageSpec.hs
Normal file
27
tests/SlackBuilder/PackageSpec.hs
Normal 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
|
Loading…
Reference in New Issue
Block a user