Skip to content

Commit

Permalink
Reset branch after fetching and remove terminal escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
ebeigarts committed Aug 31, 2017
1 parent eed70eb commit 815bca1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bin/deploy-stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash


echo '-----> Adding BUILD_ENV to build environment...'
echo '-----> Compiling Ruby/Rails'
echo $'remote: \e[1G-----> Adding BUILD_ENV to build environment...'
echo $'remote: \e[1G-----> Compiling Ruby/Rails'
sleep 2
echo '=====> Application deployed:'
echo ' http://ruby-rails-sample.dokku.me'
echo $'remote: \e[1G=====> Application deployed:'
echo $'remote: \e[1G http://ruby-rails-sample.dokku.me'

exit 0
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "errors"
import "bytes"
import "io"
import "log"
import "regexp"
import "github.com/google/go-github/github"

func main() {
Expand Down Expand Up @@ -137,13 +138,22 @@ func fetchRepo(repoPath string) (error) {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
cmd = exec.Command("git", "reset", "--hard", "origin/HEAD")
cmd.Dir = repoPath
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
return err
}

func deployToDokku(repoPath string, ref string) (*exec.Cmd) {
log.Println("Deploying repo ", repoPath)
cmd := exec.Command("git", "push", "-f", "dokku", ref + ":master")
cmd.Dir = repoPath
// cmd := exec.Command("bin/deploy-stub")
return cmd
}

Expand Down Expand Up @@ -203,6 +213,11 @@ func createDeploymentGist(ctx context.Context, client *github.Client, deployment

func updateDeploymentGist(ctx context.Context, client *github.Client, gist *github.Gist, content string) (*github.Gist, *github.Response, error) {
log.Println("Gist update")

// Remove Terminal Escape codes - "remote:\e[1G"
re := regexp.MustCompile(".*\x1b\\[1G")
content = re.ReplaceAllString(content, "")

file := gist.Files["output.txt"]
file.Content = github.String(content)
gist.Files["output.txt"] = file
Expand Down

0 comments on commit 815bca1

Please sign in to comment.