github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/plugin/deploy/git.go (about) 1 package deploy 2 3 import ( 4 "fmt" 5 "github.com/drone/drone/pkg/build/buildfile" 6 ) 7 8 type Git struct { 9 Target string `yaml:"target,omitempty"` 10 Force bool `yaml:"force,omitempty"` 11 Branch string `yaml:"branch,omitempty"` 12 } 13 14 func (g *Git) Write(f *buildfile.Buildfile) { 15 // get the current commit hash 16 f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)") 17 18 // set the git user and email based on the individual 19 // that made the commit. 20 f.WriteCmdSilent("git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')") 21 f.WriteCmdSilent("git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')") 22 23 // add target as a git remote 24 f.WriteCmd(fmt.Sprintf("git remote add deploy %s", g.Target)) 25 26 destinationBranch := g.Branch 27 if destinationBranch == "" { 28 destinationBranch = "master" 29 } 30 31 switch g.Force { 32 case true: 33 // this is useful when the there are artifacts generated 34 // by the build script, such as less files converted to css, 35 // that need to be deployed to git remote. 36 f.WriteCmd(fmt.Sprintf("git add -A")) 37 f.WriteCmd(fmt.Sprintf("git commit -m 'add build artifacts'")) 38 f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s --force", destinationBranch)) 39 case false: 40 // otherwise we just do a standard git push 41 f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s", destinationBranch)) 42 } 43 }