Compare commits

..

2 commits

Author SHA1 Message Date
9c0508c2c3
Docs: Add some docs
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-23 21:21:59 +02:00
4e2b785248
Feat: Allow to set branch 2022-07-23 21:17:55 +02:00
2 changed files with 17 additions and 4 deletions

View file

@ -4,8 +4,10 @@ A plugin to deploy to codeberg pages. Basically takes a folder and pushes it to
The following settings changes this plugin's behavior.
* param1 (optional) does something.
* param2 (optional) does something different.
* folder (required) the folder to deploy.
* ssh_key (required) the ssh key to access the repo.
* git_remote (optional) the git repote to push to. Default: `$DRONE_GIT_SSH_URL`
* git_branch (optional) the branch to push to. Default: `pages`
Below is an example `.drone.yml` that uses this plugin.
@ -20,6 +22,8 @@ steps:
settings:
folder: public
ssh_key: foo
git_remote: git@somegit.com/foo/bar
git_branch: pages
```
# Building
@ -46,6 +50,10 @@ docker run --rm -e PLUGIN_FOLDER=public -e PLUGIN_SSH_KEY=foo \
-e DRONE_COMMIT_BRANCH=master \
-e DRONE_BUILD_NUMBER=43 \
-e DRONE_BUILD_STATUS=success \
-e PLUGIN_FOLDER=public \
-e PLUGIN_SSH_KEY="-----BEGIN OPENSSH PRIVATE KEY-----\n....." \
-e PLUGIN_GIT_REMOTE=git@somegit.com/foo/bar \
-e PLUGIN_GIT_BRANCH=pages \
-w /drone/src \
-v $(pwd):/drone/src \
itsblue.dev/plugins/codeberg-pages-deploy

View file

@ -26,6 +26,7 @@ type Args struct {
Folder string `envconfig:"PLUGIN_FOLDER"`
SshKey string `envconfig:"PLUGIN_SSH_KEY"`
GitRemote string `envconfig:"PLUGIN_GIT_REMOTE"`
GitBranch string `envconfig:"PLUGIN_GIT_BRANCH"`
GitRemoteFromDrone string `envconfig:"DRONE_GIT_SSH_URL"`
}
@ -87,6 +88,10 @@ func checkArgs(args *Args) error {
args.GitRemote = args.GitRemoteFromDrone
}
if args.GitBranch == "" {
args.GitBranch = BRANCH_NAME
}
return nil
}
@ -127,7 +132,7 @@ func copyFiles(args Args) error {
func initRepo(args Args) error {
cmd := exec.Command(
"git",
"init", "-b", BRANCH_NAME, "/tmp/pages")
"init", "-b", args.GitBranch, "/tmp/pages")
if err := execute(cmd); err != nil {
return err
@ -149,7 +154,7 @@ func doCommit(args Args) error {
}
func push(args Args) error {
return execute(repo.RemotePushNamedBranch(args.GitRemote, BRANCH_NAME, BRANCH_NAME, true, false))
return execute(repo.RemotePushNamedBranch(args.GitRemote, args.GitBranch, args.GitBranch, true, false))
}
func execute(cmd *exec.Cmd) error {