Updated build script, and addded environment option for projects

This commit is contained in:
Tim Shannon 2016-04-20 06:38:53 +05:00
parent 6e482121ed
commit 481c2574a6
5 changed files with 24 additions and 11 deletions

View File

@ -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
```

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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