summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Main.hs2
-rw-r--r--app/SlackBuilder/CommandLine.hs7
-rw-r--r--app/SlackBuilder/Config.hs2
-rw-r--r--app/SlackBuilder/Download.hs42
-rw-r--r--config/config.toml.example1
-rw-r--r--lib/download.rb11
6 files changed, 54 insertions, 11 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 8d955a1..2e92865 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -36,6 +36,8 @@ main = do
commit packagePath version >> pure Nothing
ExistsCommand urlPath -> pure . Text.pack . show
<$> remoteFileExists urlPath
+ ArchiveCommand repo nameVersion tarball tagPrefix ->
+ cloneAndArchive repo nameVersion tarball tagPrefix >> pure Nothing
chooseTransformFunction (Just "php") = phpTransform
chooseTransformFunction (Just "rdiff-backup") = Text.stripPrefix "v"
chooseTransformFunction _ = stripPrefix "v"
diff --git a/app/SlackBuilder/CommandLine.hs b/app/SlackBuilder/CommandLine.hs
index 4218e6b..8df1b97 100644
--- a/app/SlackBuilder/CommandLine.hs
+++ b/app/SlackBuilder/CommandLine.hs
@@ -26,6 +26,7 @@ data SlackBuilderCommand
| SlackBuildCommand Text Text
| CommitCommand Text Text
| ExistsCommand Text
+ | ArchiveCommand Text Text String Text
deriving (Eq, Show)
data PackagistArguments = PackagistArguments
@@ -67,6 +68,7 @@ slackBuilderCommand = subparser
<> command "slackbuild" (info slackBuildCommand mempty)
<> command "commit" (info commitCommand mempty)
<> command "exists" (info existsCommand mempty)
+ <> command "archive" (info archiveCommand mempty)
where
slackBuildCommand = SlackBuildCommand
<$> argument str (metavar "PATH")
@@ -75,3 +77,8 @@ slackBuilderCommand = subparser
<$> argument str (metavar "PATH")
<*> argument str (metavar "VERSION")
existsCommand = ExistsCommand <$> argument str (metavar "PATH")
+ archiveCommand = ArchiveCommand
+ <$> argument str (metavar "REPO")
+ <*> argument str (metavar "NAME_VERSION")
+ <*> argument str (metavar "TARBALL")
+ <*> argument str (metavar "TAG_PREFIX")
diff --git a/app/SlackBuilder/Config.hs b/app/SlackBuilder/Config.hs
index 5168666..d7652e8 100644
--- a/app/SlackBuilder/Config.hs
+++ b/app/SlackBuilder/Config.hs
@@ -12,6 +12,7 @@ data Settings = Settings
, repository :: !FilePath
, branch :: Text
, downloadURL :: Text
+ , remotePath :: Text
} deriving (Eq, Show)
settingsCodec :: Toml.TomlCodec Settings
@@ -20,3 +21,4 @@ settingsCodec = Settings
<*> Toml.string "repository" .= repository
<*> Toml.text "branch" .= branch
<*> Toml.text "download_url" .= downloadURL
+ <*> Toml.text "remote_path" .= remotePath
diff --git a/app/SlackBuilder/Download.hs b/app/SlackBuilder/Download.hs
index 83db687..cbdcbb8 100644
--- a/app/SlackBuilder/Download.hs
+++ b/app/SlackBuilder/Download.hs
@@ -1,5 +1,6 @@
module SlackBuilder.Download
- ( commit
+ ( cloneAndArchive
+ , commit
, hostedSources
, remoteFileExists
, updateSlackBuildVersion
@@ -83,3 +84,42 @@ remoteFileExists url = hostedSources url
{ httpConfigCheckResponse = const $ const $ const Nothing
}
go uri = req HEAD uri NoReqBody ignoreResponse mempty
+
+uploadCommand :: Text -> Text -> SlackBuilderT ()
+uploadCommand localPath remotePath' = do
+ remoteRoot <- SlackBuilderT $ asks remotePath
+ liftIO $ callProcess "scp" $ Text.unpack <$>
+ [ "slackbuilds/" <> localPath
+ , remoteRoot <> remotePath'
+ ]
+
+cloneAndArchive :: Text -> Text -> FilePath -> Text -> SlackBuilderT ()
+cloneAndArchive repo nameVersion tarball tagPrefix = do
+ let (_, version) = Text.breakOnEnd "-" nameVersion
+ nameVersion' = Text.unpack nameVersion
+
+ repository' <- SlackBuilderT $ asks repository
+ liftIO $ callProcess "rm" ["-rf", nameVersion']
+
+ liftIO $ callProcess "git" ["clone", Text.unpack repo, nameVersion']
+ liftIO $ callProcess "git"
+ [ "-C"
+ , nameVersion'
+ , "checkout"
+ , Text.unpack $ tagPrefix <> version
+ ]
+ liftIO $ callProcess "git"
+ [ "-C"
+ , nameVersion'
+ , "submodule"
+ , "update"
+ , "--init"
+ , "--recursive"
+ ]
+
+ liftIO $ callProcess "tar"
+ [ "Jcvf"
+ , repository' </> tarball
+ , nameVersion'
+ ]
+ liftIO $ callProcess "rm" ["-rf", nameVersion']
diff --git a/config/config.toml.example b/config/config.toml.example
index 194841c..7efe248 100644
--- a/config/config.toml.example
+++ b/config/config.toml.example
@@ -2,3 +2,4 @@ gh_token = ""
repository = "./slackbuilds"
branch = "user/nick/updates"
download_url = "https://example.com/some/path"
+remote_path = "example.com:/srv/httpd/some/path"
diff --git a/lib/download.rb b/lib/download.rb
index 1d48e68..9b962b0 100644
--- a/lib/download.rb
+++ b/lib/download.rb
@@ -109,16 +109,7 @@ module SlackBuilder
end
private_class_method def self.clone_and_archive(repo, name_version, tarball, tag_prefix = 'v')
- _, _, version = name_version.rpartition '-'
-
- rm_rf name_version
-
- sh 'git', 'clone', repo, name_version
- sh 'git', '-C', name_version, 'checkout', "#{tag_prefix}#{version}"
- sh 'git', '-C', name_version, 'submodule', 'update', '--init', '--recursive'
-
- sh 'tar', 'Jcvf', "slackbuilds/#{tarball}", name_version
- rm_rf name_version
+ sh './bin/slackbuilder', 'archive', repo, name_version, tarball, tag_prefix
end
end