forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request harness#735 from PierreKircher/master
deploy plugin for "DEIS PAAS"
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package deis | ||
|
||
import ( | ||
"fmt" | ||
"github.com/drone/drone/plugin/condition" | ||
"github.com/drone/drone/shared/build/buildfile" | ||
) | ||
|
||
const ( | ||
// Gommand to the current commit hash | ||
CmdRevParse = "COMMIT=$(git rev-parse HEAD)" | ||
|
||
// Command to set the git user and email based on the | ||
// individual that made the commit. | ||
CmdGlobalEmail = "git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')" | ||
CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')" | ||
) | ||
|
||
// deploy: | ||
// deis: | ||
// app: safe-island-6261 | ||
// deisurl: deis.myurl.tdl:2222/ | ||
|
||
type Deis struct { | ||
App string `yaml:"app,omitempty"` | ||
Force bool `yaml:"force,omitempty"` | ||
Deisurl string `yaml:"deisurl,omitempty"` | ||
Condition *condition.Condition `yaml:"when,omitempty"` | ||
} | ||
|
||
func (h *Deis) Write(f *buildfile.Buildfile) { | ||
f.WriteCmdSilent(CmdRevParse) | ||
f.WriteCmdSilent(CmdGlobalUser) | ||
f.WriteCmdSilent(CmdGlobalEmail) | ||
|
||
// git@deis.yourdomain.com:2222/drone.git | ||
|
||
f.WriteCmd(fmt.Sprintf("git remote add deis ssh://git@%s%s.git", h.Deisurl , h.App)) | ||
|
||
switch h.Force { | ||
case true: | ||
// this is useful when the there are artifacts generated | ||
// by the build script, such as less files converted to css, | ||
// that need to be deployed to Deis. | ||
f.WriteCmd(fmt.Sprintf("git add -A")) | ||
f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'")) | ||
f.WriteCmd(fmt.Sprintf("git push deis HEAD:master --force")) | ||
case false: | ||
// otherwise we just do a standard git push | ||
f.WriteCmd(fmt.Sprintf("git push deis $COMMIT:master")) | ||
} | ||
} | ||
|
||
func (h *Deis) GetCondition() *condition.Condition { | ||
return h.Condition | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package deis | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/drone/drone/shared/build/buildfile" | ||
"github.com/franela/goblin" | ||
) | ||
|
||
func Test_Deis(t *testing.T) { | ||
|
||
g := goblin.Goblin(t) | ||
g.Describe("Deis Deploy", func() { | ||
|
||
g.It("Should set git.config", func() { | ||
b := new(buildfile.Buildfile) | ||
h := Deis{ | ||
App: "drone", | ||
Deisurl: "deis.yourdomain.com:2222", | ||
} | ||
|
||
h.Write(b) | ||
out := b.String() | ||
g.Assert(strings.Contains(out, CmdRevParse)).Equal(true) | ||
g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true) | ||
g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) | ||
}) | ||
|
||
g.It("Should add remote", func() { | ||
b := new(buildfile.Buildfile) | ||
h := Deis{ | ||
App: "drone", | ||
Deisurl: "deis.yourdomain.com:2222/", | ||
} | ||
|
||
h.Write(b) | ||
out := b.String() | ||
g.Assert(strings.Contains(out, "\ngit remote add deis ssh://git@deis.yourdomain.com:2222/drone.git\n")).Equal(true) | ||
}) | ||
|
||
g.It("Should push to remote", func() { | ||
b := new(buildfile.Buildfile) | ||
d := Deis{ | ||
App: "drone", | ||
} | ||
|
||
d.Write(b) | ||
out := b.String() | ||
g.Assert(strings.Contains(out, "\ngit push deis $COMMIT:master\n")).Equal(true) | ||
}) | ||
|
||
g.It("Should force push to remote", func() { | ||
b := new(buildfile.Buildfile) | ||
h := Deis{ | ||
Force: true, | ||
App: "drone", | ||
} | ||
|
||
h.Write(b) | ||
out := b.String() | ||
g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true) | ||
g.Assert(strings.Contains(out, "\ngit commit -m 'adding build artifacts'\n")).Equal(true) | ||
g.Assert(strings.Contains(out, "\ngit push deis HEAD:master --force\n")).Equal(true) | ||
}) | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters