From 481c2574a6d63855e53f1012acf5ae49e20888fb Mon Sep 17 00:00:00 2001 From: Tim Shannon Date: Wed, 20 Apr 2016 06:38:53 +0500 Subject: [PATCH] Updated build script, and addded environment option for projects --- README.md | 10 +++++++++- build.sh | 6 ++---- cycle.go | 10 +++++----- exec.go | 7 ++++++- project.go | 2 ++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3350abb..c4bf67c 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,17 @@ You'll setup a project which will need the following information: 5. Path to the release file 6. Script to set release name / version +An optional set of environment strings can be set to define the environment in which the scripts run. +``` +"environment": [ +"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin", +"GOPATH=@dir" +] +``` + Projects will be defined in a project.json file for now. I may add a web interface later. -@dir in any of the script strings will be replaced with an absolute path to the current working directory of the specific version being worked on. +@dir in any of the script strings or environment entries will be replaced with an absolute path to the current working directory of the specific version being worked on. ``` sh ./build.sh @dir ``` diff --git a/build.sh b/build.sh index 4616cfc..3da48b2 100644 --- a/build.sh +++ b/build.sh @@ -2,10 +2,8 @@ dir=$1 -export GOPATH=$dir - -echo working dir: $dir - go get -u git.townsourced.com/townsourced/ironsmith +cd $dir/src/git.townsourced.com/townsourced/ironsmith + go-bindata web/... && go build -a -v -o ironsmith diff --git a/cycle.go b/cycle.go index 0fc3aac..cfb975a 100644 --- a/cycle.go +++ b/cycle.go @@ -94,13 +94,13 @@ func (p *Project) fetch() { } //fetch project - fetchResult, err := runCmd(p.Fetch, tempDir) + fetchResult, err := runCmd(p.Fetch, tempDir, p.Environment) if p.errHandled(err) { return } // fetched succesfully, determine version - version, err := runCmd(p.Version, tempDir) + version, err := runCmd(p.Version, tempDir, p.Environment) if p.errHandled(err) { return @@ -152,7 +152,7 @@ func (p *Project) build() { return } - output, err := runCmd(p.Build, p.workingDir()) + output, err := runCmd(p.Build, p.workingDir(), p.Environment) if p.errHandled(err) { return @@ -173,7 +173,7 @@ func (p *Project) test() { if p.Test == "" { return } - output, err := runCmd(p.Test, p.workingDir()) + output, err := runCmd(p.Test, p.workingDir(), p.Environment) if p.errHandled(err) { return @@ -195,7 +195,7 @@ func (p *Project) release() { return } - output, err := runCmd(p.Release, p.workingDir()) + output, err := runCmd(p.Release, p.workingDir(), p.Environment) if p.errHandled(err) { return diff --git a/exec.go b/exec.go index 6399a6d..ebe5a31 100644 --- a/exec.go +++ b/exec.go @@ -10,9 +10,13 @@ import ( "strings" ) -func runCmd(cmd, dir string) ([]byte, error) { +func runCmd(cmd, dir string, env []string) ([]byte, error) { s := strings.Fields(strings.Replace(cmd, "@dir", dir, -1)) + for i := range env { + env[i] = strings.Replace(env[i], "@dir", dir, -1) + } + var args []string if len(s) > 1 { @@ -22,6 +26,7 @@ func runCmd(cmd, dir string) ([]byte, error) { ec := exec.Command(s[0], args...) ec.Dir = dir + ec.Env = env vlog("Executing command: %s in dir %s\n", cmd, dir) diff --git a/project.go b/project.go index e3a7596..c124c28 100644 --- a/project.go +++ b/project.go @@ -48,6 +48,8 @@ The project lifecycle goes like this, each step calling the next if successful type Project struct { Name string `json:"name"` // name of the project + Environment []string `json:"environment"` // Environment for each of the scripts below, if empty will use the current processes environment + Fetch string `json:"fetch"` //Script to fetch the latest project code into the current directory Build string `json:"build"` //Script to build the latest project code Test string `json:"test"` //Script to test the latest project code