Skip to content

Commit

Permalink
Merge pull request #17 from sambaiz/feature/pre_command
Browse files Browse the repository at this point in the history
preCommands option
  • Loading branch information
sambaiz authored Aug 29, 2019
2 parents 71d44b2 + df7d733 commit 044de67
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ targets:
master:
contexts:
env: prd
preCommands:
# Optional. Run before command.
- npm run build
deployUsers:
# Optional. If specified, only these users are allowed to deploy.
# If not, all users are allowed to deploy.
Expand Down
6 changes: 6 additions & 0 deletions functions/operation/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/sambaiz/cdkbot/functions/operation/constant"
"github.com/sambaiz/cdkbot/functions/operation/git"
"github.com/sambaiz/cdkbot/functions/operation/platform"
"os/exec"
"regexp"
"strings"
)
Expand Down Expand Up @@ -126,6 +127,11 @@ func (r *Runner) setup(ctx context.Context, cloneHead bool) (string, *config.Con
if err := r.cdk.Setup(cdkPath); err != nil {
return "", nil, nil, nil, err
}

for _, preCommand := range cfg.PreCommands {
command := strings.Split(preCommand, " ")
exec.Command(command[0], command[1:]...)
}
return cdkPath, cfg, &target, pr, nil
}

Expand Down
1 change: 1 addition & 0 deletions functions/operation/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Reader struct{}
type Config struct {
CDKRoot string `yaml:"cdkRoot"`
Targets map[string]Target `yaml:"targets"`
PreCommands []string `yaml:"preCommands"`
DeployUsers []string `yaml:"deployUsers"`
}

Expand Down
1 change: 1 addition & 0 deletions functions/operation/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestReaderRead(t *testing.T) {
},
},
},
PreCommands: []string{"npm run build"},
DeployUsers: []string{"sambaiz"},
},
},
Expand Down
2 changes: 2 additions & 0 deletions functions/operation/config/test_config/cdkbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ targets:
master:
contexts:
env: prd
preCommands:
- npm run build
deployUsers:
- sambaiz

0 comments on commit 044de67

Please sign in to comment.