mirror of
https://github.com/thegeeklab/wp-git-action.git
synced 2024-11-24 12:40:39 +00:00
59 lines
829 B
Go
59 lines
829 B
Go
package plugin
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/thegeeklab/wp-git-action/git"
|
|
"golang.org/x/sys/execabs"
|
|
)
|
|
|
|
// helper function to simply wrap os execte command.
|
|
func execute(cmd *execabs.Cmd) error {
|
|
log.Debug().Msgf("+ %s", strings.Join(cmd.Args, " "))
|
|
|
|
cmd.Env = os.Environ()
|
|
cmd.Stderr = os.Stderr
|
|
cmd.Stdin = os.Stdin
|
|
|
|
return cmd.Run()
|
|
}
|
|
|
|
func rsyncDirectories(pages Pages, repo git.Repository) *execabs.Cmd {
|
|
args := []string{
|
|
"-r",
|
|
"--exclude",
|
|
".git",
|
|
}
|
|
|
|
for _, item := range pages.Exclude.Value() {
|
|
args = append(
|
|
args,
|
|
"--exclude",
|
|
item,
|
|
)
|
|
}
|
|
|
|
if pages.Delete {
|
|
args = append(
|
|
args,
|
|
"--delete",
|
|
)
|
|
}
|
|
|
|
args = append(
|
|
args,
|
|
".",
|
|
repo.WorkDir,
|
|
)
|
|
|
|
cmd := execabs.Command(
|
|
"rsync",
|
|
args...,
|
|
)
|
|
cmd.Dir = pages.Directory
|
|
|
|
return cmd
|
|
}
|