mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 11:51:02 +00:00
Merge pull request #201 from kirs/feature/bash-deployment
Deployment with Bash command
This commit is contained in:
commit
2a85813d14
4 changed files with 117 additions and 0 deletions
|
@ -210,6 +210,7 @@ Drone currently has these `deploy` and `publish` plugins implemented (more to co
|
|||
- [nodejitsu](#docs)
|
||||
- [ssh](#docs)
|
||||
- [tsuru](#docs)
|
||||
- [bash](#docs)
|
||||
|
||||
**publish**
|
||||
- [Amazon s3](#docs)
|
||||
|
|
18
pkg/plugin/deploy/bash.go
Normal file
18
pkg/plugin/deploy/bash.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package deploy
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
)
|
||||
|
||||
type Bash struct {
|
||||
Script []string `yaml:"script,omitempty"`
|
||||
Command string `yaml:"command,omitempty"`
|
||||
}
|
||||
|
||||
func (g *Bash) Write(f *buildfile.Buildfile) {
|
||||
g.Script = append(g.Script, g.Command)
|
||||
|
||||
for _, cmd := range g.Script {
|
||||
f.WriteCmd(cmd)
|
||||
}
|
||||
}
|
94
pkg/plugin/deploy/bash_test.go
Normal file
94
pkg/plugin/deploy/bash_test.go
Normal file
|
@ -0,0 +1,94 @@
|
|||
package deploy
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/drone/drone/pkg/build/buildfile"
|
||||
|
||||
"launchpad.net/goyaml"
|
||||
)
|
||||
|
||||
// emulate Build struct
|
||||
type buildWithBash struct {
|
||||
Deploy *Deploy `yaml:"deploy,omitempty"`
|
||||
}
|
||||
|
||||
var sampleYmlWithBash = `
|
||||
deploy:
|
||||
bash:
|
||||
command: 'echo bash_deployed'
|
||||
`
|
||||
|
||||
var sampleYmlWithScript = `
|
||||
deploy:
|
||||
bash:
|
||||
script:
|
||||
- ./bin/deploy.sh
|
||||
- ./bin/check.sh
|
||||
`
|
||||
|
||||
var sampleYmlWithBashAndScript = `
|
||||
deploy:
|
||||
bash:
|
||||
command: ./bin/some_cmd.sh
|
||||
script:
|
||||
- ./bin/deploy.sh
|
||||
- ./bin/check.sh
|
||||
`
|
||||
|
||||
func setUpWithBash(input string) (string, error) {
|
||||
var buildStruct buildWithBash
|
||||
err := goyaml.Unmarshal([]byte(input), &buildStruct)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
bf := buildfile.New()
|
||||
buildStruct.Deploy.Write(bf)
|
||||
return bf.String(), err
|
||||
}
|
||||
|
||||
func TestBashDeployment(t *testing.T) {
|
||||
bscr, err := setUpWithBash(sampleYmlWithBash)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(bscr, "echo bash_deployed") {
|
||||
t.Error("Expect script to contains bash command")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBashDeploymentWithScript(t *testing.T) {
|
||||
bscr, err := setUpWithBash(sampleYmlWithScript)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(bscr, "./bin/deploy.sh") {
|
||||
t.Error("Expect script to contains bash script")
|
||||
}
|
||||
|
||||
if !strings.Contains(bscr, "./bin/check.sh") {
|
||||
t.Error("Expect script to contains bash script")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBashDeploymentWithBashAndScript(t *testing.T) {
|
||||
bscr, err := setUpWithBash(sampleYmlWithBashAndScript)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(bscr, "./bin/deploy.sh") {
|
||||
t.Error("Expect script to contains bash script")
|
||||
}
|
||||
|
||||
if !strings.Contains(bscr, "./bin/check.sh") {
|
||||
t.Error("Expect script to contains bash script")
|
||||
}
|
||||
|
||||
if !strings.Contains(bscr, "./bin/some_cmd.sh") {
|
||||
t.Error("Expect script to contains bash script")
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ type Deploy struct {
|
|||
Openshift *Openshift `yaml:"openshift,omitempty"`
|
||||
SSH *SSH `yaml:"ssh,omitempty"`
|
||||
Tsuru *Tsuru `yaml:"tsuru,omitempty"`
|
||||
Bash *Bash `yaml:"bash,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Deploy) Write(f *buildfile.Buildfile) {
|
||||
|
@ -55,4 +56,7 @@ func (d *Deploy) Write(f *buildfile.Buildfile) {
|
|||
if d.Tsuru != nil {
|
||||
d.Tsuru.Write(f)
|
||||
}
|
||||
if d.Bash != nil {
|
||||
d.Bash.Write(f)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue