Fix: don't use rsync
This commit is contained in:
parent
29d2eca187
commit
58a7f5bd1e
4 changed files with 52 additions and 26 deletions
|
@ -50,6 +50,7 @@ Note: you have to either use an image which includes go or set it up before runn
|
||||||
| git_branch | The branch to push to | pages |
|
| git_branch | The branch to push to | pages |
|
||||||
| git_name | The name to use for the commit | `[BOT] pages deployer` |
|
| git_name | The name to use for the commit | `[BOT] pages deployer` |
|
||||||
| git_email | The email to use for the commit | `noreply@pages.bot` |
|
| git_email | The email to use for the commit | `noreply@pages.bot` |
|
||||||
|
| commit_message | The commit message | `Update pages 🚀` |
|
||||||
| token | The token/password to use if pushing to a custom http remote | the gitea-supplied token (aka `GITHUB_TOKEN`) |
|
| token | The token/password to use if pushing to a custom http remote | the gitea-supplied token (aka `GITHUB_TOKEN`) |
|
||||||
| username | The username to use if pushing to a custom http remote | the actor (aka `GITHUB_ACTOR`) |
|
| username | The username to use if pushing to a custom http remote | the actor (aka `GITHUB_ACTOR`) |
|
||||||
| force | Force commit and overwrite all previous commits | `false` |
|
| force | Force commit and overwrite all previous commits | `false` |
|
7
go.mod
7
go.mod
|
@ -4,4 +4,9 @@ go 1.21.0
|
||||||
|
|
||||||
require github.com/appleboy/drone-git-push v1.0.5
|
require github.com/appleboy/drone-git-push v1.0.5
|
||||||
|
|
||||||
require github.com/kelseyhightower/envconfig v1.4.0 // indirect
|
require (
|
||||||
|
github.com/kelseyhightower/envconfig v1.4.0 // indirect
|
||||||
|
github.com/otiai10/copy v1.14.0 // indirect
|
||||||
|
golang.org/x/sync v0.3.0 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||||
|
)
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -2,3 +2,9 @@ github.com/appleboy/drone-git-push v1.0.5 h1:2ndC+lcFpsbnaIt9dZ0acniewJnSAh6SOqD
|
||||||
github.com/appleboy/drone-git-push v1.0.5/go.mod h1:A71Q1/0OVhVe872aipwdVrpcCyz2VxhspfZN1nAUZWg=
|
github.com/appleboy/drone-git-push v1.0.5/go.mod h1:A71Q1/0OVhVe872aipwdVrpcCyz2VxhspfZN1nAUZWg=
|
||||||
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
||||||
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
||||||
|
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
|
||||||
|
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
|
||||||
|
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||||
|
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
|
20
main.go
20
main.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kelseyhightower/envconfig"
|
"github.com/kelseyhightower/envconfig"
|
||||||
|
"github.com/otiai10/copy"
|
||||||
|
|
||||||
"github.com/appleboy/drone-git-push/repo"
|
"github.com/appleboy/drone-git-push/repo"
|
||||||
)
|
)
|
||||||
|
@ -27,6 +28,7 @@ type Args struct {
|
||||||
GitBranch string `envconfig:"INPUT_GIT_BRANCH"`
|
GitBranch string `envconfig:"INPUT_GIT_BRANCH"`
|
||||||
GitName string `envconfig:"INPUT_GIT_NAME" default:"[BOT] pages deployer"`
|
GitName string `envconfig:"INPUT_GIT_NAME" default:"[BOT] pages deployer"`
|
||||||
GitEmail string `envconfig:"INPUT_GIT_EMAIL" default:"noreply@pages.bot"`
|
GitEmail string `envconfig:"INPUT_GIT_EMAIL" default:"noreply@pages.bot"`
|
||||||
|
CommitMessage string `envconfig:"INPUT_COMMIT_MESSAGE" default:"Update pages 🚀"`
|
||||||
Token string `envconfig:"INPUT_TOKEN"`
|
Token string `envconfig:"INPUT_TOKEN"`
|
||||||
Username string `envconfig:"INPUT_USERNAME"`
|
Username string `envconfig:"INPUT_USERNAME"`
|
||||||
Force bool `envconfig:"INPUT_FORCE" default:"false"`
|
Force bool `envconfig:"INPUT_FORCE" default:"false"`
|
||||||
|
@ -180,8 +182,20 @@ func copyFiles(args Args) error {
|
||||||
args.RemoteFolder = "/" + args.RemoteFolder
|
args.RemoteFolder = "/" + args.RemoteFolder
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("rsync", "-av", args.Folder, "/tmp/pages"+args.RemoteFolder, "--exclude", ".git", "--ignore-times", "--delete")
|
// if remote folder is a subdir, delete it
|
||||||
if err := execute(cmd); err != nil {
|
if args.RemoteFolder != "/" {
|
||||||
|
if err := os.RemoveAll("/tmp/pages" + args.RemoteFolder); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
opt := copy.Options{
|
||||||
|
Skip: func(info os.FileInfo, src, dest string) (bool, error) {
|
||||||
|
return strings.HasSuffix(src, ".git"), nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := copy.Copy(args.Folder, "/tmp/pages"+args.RemoteFolder, opt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +265,7 @@ func doCommit(args Args) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := execute(repo.ForceCommit("Update pages 🚀", true, args.GitName, args.GitEmail)); err != nil {
|
if err := execute(repo.ForceCommit(args.CommitMessage, true, args.GitName, args.GitEmail)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue