Support a custom upload command
This commit is contained in:
parent
6ba319c3b6
commit
f8ef93fde7
@ -19,13 +19,13 @@ branch = "user/nick/updates"
|
|||||||
# be configured consistently with the remote_path.
|
# be configured consistently with the remote_path.
|
||||||
download_url = "https://example.com/some/path"
|
download_url = "https://example.com/some/path"
|
||||||
|
|
||||||
# If a package updater generates a source tarball, the tarball is uploaded to
|
# If a package updater generates a source tarball, the tarball is uploaded with
|
||||||
# a remote destination with scp. remote_path specifies the remote server and
|
# a command given in this parameter. The parameter is a array where the first
|
||||||
# a local path on the server where the source tarballs are hosted. When
|
# element is the command with the following elements being the command
|
||||||
# uploading the remote_path is followed by the package name and source file
|
# arguments. The command supports 2 placeholders:
|
||||||
# name. To specify a public URL where the sources can be downloaded, see
|
# %s - Path to the source archive.
|
||||||
# download_url.
|
# %c - Package category.
|
||||||
remote_path = "example.com:/srv/httpd/some/path"
|
upload_command = ["scp", "%s", "example.com:/srv/httpd/some/path/%c"]
|
||||||
|
|
||||||
## Maintainer specific options
|
## Maintainer specific options
|
||||||
[maintainer]
|
[maintainer]
|
||||||
|
@ -9,6 +9,7 @@ module SlackBuilder.Config
|
|||||||
, settingsCodec
|
, settingsCodec
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Data.List.NonEmpty (NonEmpty(..))
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Toml ((.=))
|
import Toml ((.=))
|
||||||
import qualified Toml
|
import qualified Toml
|
||||||
@ -18,7 +19,7 @@ data Settings = Settings
|
|||||||
, repository :: !FilePath
|
, repository :: !FilePath
|
||||||
, branch :: Text
|
, branch :: Text
|
||||||
, downloadURL :: Text
|
, downloadURL :: Text
|
||||||
, remotePath :: Text
|
, uploadCommand :: NonEmpty Text
|
||||||
, maintainer :: MaintainerSettings
|
, maintainer :: MaintainerSettings
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ settingsCodec = Settings
|
|||||||
<*> Toml.string "repository" .= repository
|
<*> Toml.string "repository" .= repository
|
||||||
<*> Toml.text "branch" .= branch
|
<*> Toml.text "branch" .= branch
|
||||||
<*> Toml.text "download_url" .= downloadURL
|
<*> Toml.text "download_url" .= downloadURL
|
||||||
<*> Toml.text "remote_path" .= remotePath
|
<*> Toml.arrayNonEmptyOf Toml._Text "upload_command" .= uploadCommand
|
||||||
<*> Toml.table maintainerSettingsCodec "maintainer" .= maintainer
|
<*> Toml.table maintainerSettingsCodec "maintainer" .= maintainer
|
||||||
|
|
||||||
maintainerSettingsCodec :: Toml.TomlCodec MaintainerSettings
|
maintainerSettingsCodec :: Toml.TomlCodec MaintainerSettings
|
||||||
|
@ -14,12 +14,13 @@ module SlackBuilder.Download
|
|||||||
, sinkFileAndHash
|
, sinkFileAndHash
|
||||||
, sinkHash
|
, sinkHash
|
||||||
, updateSlackBuildVersion
|
, updateSlackBuildVersion
|
||||||
, uploadCommand
|
, uploadSource
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import qualified Data.ByteString as ByteString
|
import qualified Data.ByteString as ByteString
|
||||||
import qualified Data.ByteString.Char8 as Char8
|
import qualified Data.ByteString.Char8 as Char8
|
||||||
|
import Data.List.NonEmpty (NonEmpty(..))
|
||||||
import qualified Data.List.NonEmpty as NonEmpty
|
import qualified Data.List.NonEmpty as NonEmpty
|
||||||
import Data.Foldable (find)
|
import Data.Foldable (find)
|
||||||
import Data.Map.Strict (Map)
|
import Data.Map.Strict (Map)
|
||||||
@ -195,10 +196,10 @@ cloneAndUpload :: Text -> FilePath -> Text -> SlackBuilderT (URI, Digest MD5)
|
|||||||
cloneAndUpload repo tarballPath tagPrefix = do
|
cloneAndUpload repo tarballPath tagPrefix = do
|
||||||
localPath <- relativeToRepository $ tarballPath <.> "tar.xz"
|
localPath <- relativeToRepository $ tarballPath <.> "tar.xz"
|
||||||
let packageName = takeFileName $ takeDirectory tarballPath
|
let packageName = takeFileName $ takeDirectory tarballPath
|
||||||
remoteArchivePath = Text.cons '/' $ Text.pack
|
remoteArchivePath = Text.pack
|
||||||
$ packageName </> takeFileName tarballPath <.> "tar.xz"
|
$ packageName </> takeFileName tarballPath <.> "tar.xz"
|
||||||
remoteResultURI <- hostedSources remoteArchivePath
|
remoteResultURI <- hostedSources $ Text.cons '/' remoteArchivePath
|
||||||
remoteFileExists' <- remoteFileExists remoteArchivePath
|
remoteFileExists' <- remoteFileExists $ Text.cons '/' remoteArchivePath
|
||||||
|
|
||||||
if remoteFileExists'
|
if remoteFileExists'
|
||||||
then (remoteResultURI,) . snd
|
then (remoteResultURI,) . snd
|
||||||
@ -206,21 +207,22 @@ cloneAndUpload repo tarballPath tagPrefix = do
|
|||||||
else
|
else
|
||||||
let go = sourceFile localPath .| sinkHash
|
let go = sourceFile localPath .| sinkHash
|
||||||
in cloneAndArchive repo tarballPath tagPrefix
|
in cloneAndArchive repo tarballPath tagPrefix
|
||||||
>> uploadCommand localPath remoteArchivePath
|
>> uploadSource localPath remoteArchivePath
|
||||||
>> liftIO (runConduitRes go) <&> (remoteResultURI,)
|
>> liftIO (runConduitRes go) <&> (remoteResultURI,)
|
||||||
|
|
||||||
-- | Given a path to a local file and a remote path uploads the file using
|
-- | Given a path to a local file and a remote path uploads the file using
|
||||||
-- the settings given in the configuration file.
|
-- the settings given in the configuration file.
|
||||||
--
|
--
|
||||||
-- The remote path is given relative to the path in the configuration.
|
-- The remote path is given relative to the path in the configuration.
|
||||||
uploadCommand :: FilePath -> Text -> SlackBuilderT ()
|
uploadSource :: FilePath -> Text -> SlackBuilderT ()
|
||||||
uploadCommand localPath remotePath' = do
|
uploadSource localPath remotePath' = do
|
||||||
remoteRoot <- SlackBuilderT $ asks remotePath
|
uploadCommand' :| uploadArguments <- SlackBuilderT $ asks uploadCommand
|
||||||
|
let uploadArguments' = Text.unpack
|
||||||
|
. Text.replace "%s" (Text.pack localPath)
|
||||||
|
. Text.replace "%c" remotePath'
|
||||||
|
<$> uploadArguments
|
||||||
|
|
||||||
liftIO $ callProcess "scp"
|
liftIO $ callProcess (Text.unpack uploadCommand') uploadArguments'
|
||||||
[ localPath
|
|
||||||
, Text.unpack $ remoteRoot <> remotePath'
|
|
||||||
]
|
|
||||||
|
|
||||||
-- | Downlaods a file into the directory. Returns name of the downloaded file
|
-- | Downlaods a file into the directory. Returns name of the downloaded file
|
||||||
-- and checksum.
|
-- and checksum.
|
||||||
|
@ -172,7 +172,7 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
|
|||||||
download' <- handleReupload relativeTarball' downloadFileName
|
download' <- handleReupload relativeTarball' downloadFileName
|
||||||
pure $ Package.Download download' checksum
|
pure $ Package.Download download' checksum
|
||||||
where
|
where
|
||||||
name' = Text.pack $ takeBaseName $ Text.unpack packagePath
|
category' = Text.pack $ takeBaseName $ Text.unpack packagePath
|
||||||
prepareSource tarballPath =
|
prepareSource tarballPath =
|
||||||
liftIO (traverse (defaultCreateProcess tarballPath) commands)
|
liftIO (traverse (defaultCreateProcess tarballPath) commands)
|
||||||
>> liftIO (tarCompress tarballPath)
|
>> liftIO (tarCompress tarballPath)
|
||||||
@ -190,8 +190,8 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
|
|||||||
downloadURL' <- SlackBuilderT $ asks downloadURL
|
downloadURL' <- SlackBuilderT $ asks downloadURL
|
||||||
|
|
||||||
liftIO $ putStrLn $ "Upload the source tarball " <> relativeTarball
|
liftIO $ putStrLn $ "Upload the source tarball " <> relativeTarball
|
||||||
uploadCommand relativeTarball ("/" <> name')
|
uploadSource relativeTarball category'
|
||||||
liftIO $ mkURI $ downloadURL' <> "/" <> name' <> "/" <> Text.pack downloadFileName
|
liftIO $ mkURI $ downloadURL' <> "/" <> category' <> "/" <> Text.pack downloadFileName
|
||||||
defaultCreateProcess cwd' cmdSpec
|
defaultCreateProcess cwd' cmdSpec
|
||||||
= flip withCreateProcess (const . const . const waitForProcess)
|
= flip withCreateProcess (const . const . const waitForProcess)
|
||||||
$ CreateProcess
|
$ CreateProcess
|
||||||
|
Loading…
Reference in New Issue
Block a user