Fix: don't use rsync

This commit is contained in:
Dorian Zedler 2023-11-03 09:26:41 +01:00
parent 29d2eca187
commit 58a7f5bd1e
Signed by: dorian
GPG key ID: 989DE36109AFA354
4 changed files with 52 additions and 26 deletions

View file

@ -41,15 +41,16 @@ Note: you have to either use an image which includes go or set it up before runn
## Options
| parameter | description | default |
| ------------- | ------------------------------------------------------------ | --------------------------------------------- |
| folder | The folder to deploy from | |
| remote_folder | The folder to deploy to in the remote repo | `/` |
| ssh_key | The private ssh key to use if pushing to an ssh remote | empty |
| git_remote | A custom git remote to push to | the current repo |
| git_branch | The branch to push to | pages |
| git_name | The name to use for the commit | `[BOT] pages deployer` |
| git_email | The email to use for the commit | `noreply@pages.bot` |
| 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`) |
| force | Force commit and overwrite all previous commits | `false` |
| parameter | description | default |
| ------------- | ------------------------------------------------------------ | --------------------------------------------- |
| folder | The folder to deploy from | |
| remote_folder | The folder to deploy to in the remote repo | `/` |
| ssh_key | The private ssh key to use if pushing to an ssh remote | empty |
| git_remote | A custom git remote to push to | the current repo |
| git_branch | The branch to push to | pages |
| git_name | The name to use for the commit | `[BOT] pages deployer` |
| 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`) |
| 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` |

7
go.mod
View file

@ -4,4 +4,9 @@ go 1.21.0
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
View file

@ -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/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
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=

40
main.go
View file

@ -14,22 +14,24 @@ import (
"strings"
"github.com/kelseyhightower/envconfig"
"github.com/otiai10/copy"
"github.com/appleboy/drone-git-push/repo"
)
// Args provides plugin execution arguments.
type Args struct {
Folder string `required:"true" envconfig:"INPUT_FOLDER"`
RemoteFolder string `envconfig:"INPUT_REMOTE_FOLDER" default:"/"`
SshKey string `envconfig:"INPUT_SSH_KEY"`
GitRemote string `envconfig:"INPUT_GIT_REMOTE"`
GitBranch string `envconfig:"INPUT_GIT_BRANCH"`
GitName string `envconfig:"INPUT_GIT_NAME" default:"[BOT] pages deployer"`
GitEmail string `envconfig:"INPUT_GIT_EMAIL" default:"noreply@pages.bot"`
Token string `envconfig:"INPUT_TOKEN"`
Username string `envconfig:"INPUT_USERNAME"`
Force bool `envconfig:"INPUT_FORCE" default:"false"`
Folder string `required:"true" envconfig:"INPUT_FOLDER"`
RemoteFolder string `envconfig:"INPUT_REMOTE_FOLDER" default:"/"`
SshKey string `envconfig:"INPUT_SSH_KEY"`
GitRemote string `envconfig:"INPUT_GIT_REMOTE"`
GitBranch string `envconfig:"INPUT_GIT_BRANCH"`
GitName string `envconfig:"INPUT_GIT_NAME" default:"[BOT] pages deployer"`
GitEmail string `envconfig:"INPUT_GIT_EMAIL" default:"noreply@pages.bot"`
CommitMessage string `envconfig:"INPUT_COMMIT_MESSAGE" default:"Update pages 🚀"`
Token string `envconfig:"INPUT_TOKEN"`
Username string `envconfig:"INPUT_USERNAME"`
Force bool `envconfig:"INPUT_FORCE" default:"false"`
GithubToken string `envconfig:"GITHUB_TOKEN"`
GithubTokenActor string `envconfig:"GITHUB_ACTOR"`
@ -180,8 +182,20 @@ func copyFiles(args Args) error {
args.RemoteFolder = "/" + args.RemoteFolder
}
cmd := exec.Command("rsync", "-av", args.Folder, "/tmp/pages"+args.RemoteFolder, "--exclude", ".git", "--ignore-times", "--delete")
if err := execute(cmd); err != nil {
// if remote folder is a subdir, delete it
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
}
@ -251,7 +265,7 @@ func doCommit(args Args) error {
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
}