Support a custom upload command
This commit is contained in:
@ -9,6 +9,7 @@ module SlackBuilder.Config
|
||||
, settingsCodec
|
||||
) where
|
||||
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import Data.Text (Text)
|
||||
import Toml ((.=))
|
||||
import qualified Toml
|
||||
@ -18,7 +19,7 @@ data Settings = Settings
|
||||
, repository :: !FilePath
|
||||
, branch :: Text
|
||||
, downloadURL :: Text
|
||||
, remotePath :: Text
|
||||
, uploadCommand :: NonEmpty Text
|
||||
, maintainer :: MaintainerSettings
|
||||
} deriving (Eq, Show)
|
||||
|
||||
@ -32,7 +33,7 @@ settingsCodec = Settings
|
||||
<*> Toml.string "repository" .= repository
|
||||
<*> Toml.text "branch" .= branch
|
||||
<*> Toml.text "download_url" .= downloadURL
|
||||
<*> Toml.text "remote_path" .= remotePath
|
||||
<*> Toml.arrayNonEmptyOf Toml._Text "upload_command" .= uploadCommand
|
||||
<*> Toml.table maintainerSettingsCodec "maintainer" .= maintainer
|
||||
|
||||
maintainerSettingsCodec :: Toml.TomlCodec MaintainerSettings
|
||||
|
@ -14,12 +14,13 @@ module SlackBuilder.Download
|
||||
, sinkFileAndHash
|
||||
, sinkHash
|
||||
, updateSlackBuildVersion
|
||||
, uploadCommand
|
||||
, uploadSource
|
||||
) where
|
||||
|
||||
import Data.ByteString (ByteString)
|
||||
import qualified Data.ByteString as ByteString
|
||||
import qualified Data.ByteString.Char8 as Char8
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import qualified Data.List.NonEmpty as NonEmpty
|
||||
import Data.Foldable (find)
|
||||
import Data.Map.Strict (Map)
|
||||
@ -195,10 +196,10 @@ cloneAndUpload :: Text -> FilePath -> Text -> SlackBuilderT (URI, Digest MD5)
|
||||
cloneAndUpload repo tarballPath tagPrefix = do
|
||||
localPath <- relativeToRepository $ tarballPath <.> "tar.xz"
|
||||
let packageName = takeFileName $ takeDirectory tarballPath
|
||||
remoteArchivePath = Text.cons '/' $ Text.pack
|
||||
remoteArchivePath = Text.pack
|
||||
$ packageName </> takeFileName tarballPath <.> "tar.xz"
|
||||
remoteResultURI <- hostedSources remoteArchivePath
|
||||
remoteFileExists' <- remoteFileExists remoteArchivePath
|
||||
remoteResultURI <- hostedSources $ Text.cons '/' remoteArchivePath
|
||||
remoteFileExists' <- remoteFileExists $ Text.cons '/' remoteArchivePath
|
||||
|
||||
if remoteFileExists'
|
||||
then (remoteResultURI,) . snd
|
||||
@ -206,21 +207,22 @@ cloneAndUpload repo tarballPath tagPrefix = do
|
||||
else
|
||||
let go = sourceFile localPath .| sinkHash
|
||||
in cloneAndArchive repo tarballPath tagPrefix
|
||||
>> uploadCommand localPath remoteArchivePath
|
||||
>> uploadSource localPath remoteArchivePath
|
||||
>> liftIO (runConduitRes go) <&> (remoteResultURI,)
|
||||
|
||||
-- | Given a path to a local file and a remote path uploads the file using
|
||||
-- the settings given in the configuration file.
|
||||
--
|
||||
-- The remote path is given relative to the path in the configuration.
|
||||
uploadCommand :: FilePath -> Text -> SlackBuilderT ()
|
||||
uploadCommand localPath remotePath' = do
|
||||
remoteRoot <- SlackBuilderT $ asks remotePath
|
||||
uploadSource :: FilePath -> Text -> SlackBuilderT ()
|
||||
uploadSource localPath remotePath' = do
|
||||
uploadCommand' :| uploadArguments <- SlackBuilderT $ asks uploadCommand
|
||||
let uploadArguments' = Text.unpack
|
||||
. Text.replace "%s" (Text.pack localPath)
|
||||
. Text.replace "%c" remotePath'
|
||||
<$> uploadArguments
|
||||
|
||||
liftIO $ callProcess "scp"
|
||||
[ localPath
|
||||
, Text.unpack $ remoteRoot <> remotePath'
|
||||
]
|
||||
liftIO $ callProcess (Text.unpack uploadCommand') uploadArguments'
|
||||
|
||||
-- | Downlaods a file into the directory. Returns name of the downloaded file
|
||||
-- and checksum.
|
||||
|
Reference in New Issue
Block a user