2022-11-27 13:33:39 +00:00
|
|
|
package plugin
|
2019-06-07 10:32:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
2022-12-02 21:21:35 +00:00
|
|
|
|
2023-02-08 09:16:10 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2022-12-02 21:21:35 +00:00
|
|
|
"github.com/thegeeklab/drone-git-action/git"
|
2023-02-08 09:16:10 +00:00
|
|
|
"golang.org/x/sys/execabs"
|
2019-06-07 10:32:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// helper function to simply wrap os execte command.
|
2023-02-08 09:16:10 +00:00
|
|
|
func execute(cmd *execabs.Cmd) error {
|
|
|
|
logrus.Debug("+", strings.Join(cmd.Args, " "))
|
2019-06-07 10:32:16 +00:00
|
|
|
|
|
|
|
cmd.Env = os.Environ()
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
|
|
|
|
return cmd.Run()
|
|
|
|
}
|
|
|
|
|
2023-02-08 09:16:10 +00:00
|
|
|
func rsyncDirectories(pages Pages, repo git.Repository) *execabs.Cmd {
|
2022-12-02 21:21:35 +00:00
|
|
|
args := []string{
|
|
|
|
"-r",
|
|
|
|
"--exclude",
|
|
|
|
".git",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range pages.Exclude.Value() {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"--exclude",
|
|
|
|
item,
|
|
|
|
)
|
2019-06-07 10:32:16 +00:00
|
|
|
}
|
|
|
|
|
2022-12-02 21:21:35 +00:00
|
|
|
if pages.Delete {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"--delete",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
".",
|
|
|
|
repo.WorkDir,
|
|
|
|
)
|
|
|
|
|
2023-02-08 09:16:10 +00:00
|
|
|
cmd := execabs.Command(
|
2022-12-02 21:21:35 +00:00
|
|
|
"rsync",
|
|
|
|
args...,
|
|
|
|
)
|
|
|
|
cmd.Dir = pages.Directory
|
2019-06-07 10:32:16 +00:00
|
|
|
|
2022-12-02 21:21:35 +00:00
|
|
|
return cmd
|
2019-06-07 10:32:16 +00:00
|
|
|
}
|