mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 17:00:30 +00:00
Added run helper function
This commit is contained in:
parent
209d71c1f6
commit
7df78a2864
1 changed files with 36 additions and 11 deletions
47
make.go
47
make.go
|
@ -276,19 +276,44 @@ func clean() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// trace is a helper fucntion that writes a command
|
||||
// run is a helper function that executes commands
|
||||
// and assigns stdout and stderr targets
|
||||
func run(command string, args ...string) error {
|
||||
cmd := exec.Command(command, args...)
|
||||
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
trace(cmd.Args)
|
||||
err := cmd.Run()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// helper function to parse the git revision
|
||||
func rev() string {
|
||||
cmd := exec.Command(
|
||||
"git",
|
||||
"rev-parse",
|
||||
"--short",
|
||||
"HEAD")
|
||||
|
||||
raw, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
return "HEAD"
|
||||
}
|
||||
|
||||
return strings.Trim(string(raw), "\n")
|
||||
}
|
||||
|
||||
// trace is a helper function that writes a command
|
||||
// to stdout similar to bash +x
|
||||
func trace(args []string) {
|
||||
print("+ ")
|
||||
println(strings.Join(args, " "))
|
||||
}
|
||||
|
||||
// helper function to parse the git revision
|
||||
func rev() string {
|
||||
cmd := exec.Command("git", "rev-parse", "--short", "HEAD")
|
||||
raw, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "HEAD"
|
||||
}
|
||||
return strings.Trim(string(raw), "\n")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue