From 4d71643214dee677310801061e57dc942bf40bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Lindstr=C3=B6m?= Date: Tue, 11 Feb 2014 19:23:15 +0000 Subject: [PATCH] implement git deploy method This commit implements the git deploy method. This is basically a copy of the Heroku deploy method except it uses a target instead of an app. The target can be anything that git accepts as a url. An example of deploy using git can be: deploy: git: target: git@example.com:myapp.git --- pkg/plugin/deploy/git.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pkg/plugin/deploy/git.go b/pkg/plugin/deploy/git.go index b2b65d9ca..cc8a3e837 100644 --- a/pkg/plugin/deploy/git.go +++ b/pkg/plugin/deploy/git.go @@ -1 +1,38 @@ package deploy + +import ( + "fmt" + "github.com/drone/drone/pkg/build/buildfile" +) + +type Git struct { + Target string `yaml:"target,omitempty"` + Force bool `yaml:"force,omitempty"` + Branch string `yaml:"branch,omitempty"` +} + +func (g *Git) Write(f *buildfile.Buildfile) { + // get the current commit hash + f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)") + + // set the git user and email based on the individual + // that made the commit. + f.WriteCmdSilent("git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')") + f.WriteCmdSilent("git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')") + + // add target as a git remote + f.WriteCmd(fmt.Sprintf("git remote add deploy %s", g.Target)) + + switch g.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 git remote. + f.WriteCmd(fmt.Sprintf("git add -A")) + f.WriteCmd(fmt.Sprintf("git commit -m 'add build artifacts'")) + f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:master --force")) + case false: + // otherwise we just do a standard git push + f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:master")) + } +}