Support repository directory in the clone function

This commit is contained in:
Eugen Wissner 2023-08-18 07:50:18 +02:00
parent fd649b66f5
commit 258604f22d
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
6 changed files with 54 additions and 11 deletions

View File

@ -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"

View File

@ -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")

View File

@ -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

View File

@ -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']

View File

@ -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"

View File

@ -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