mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
742a67fc60
* add log package * add logrus dependency * add logging to karma step * add log stepName to generator, respect verbose flag
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/command"
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
)
|
|
|
|
func karmaExecuteTests(myKarmaExecuteTestsOptions karmaExecuteTestsOptions) error {
|
|
c := command.Command{}
|
|
// reroute command output to loging framework
|
|
// also log stdout as Karma reports into it
|
|
c.Stdout = log.Entry().Writer()
|
|
c.Stderr = log.Entry().Writer()
|
|
runKarma(myKarmaExecuteTestsOptions, &c)
|
|
return nil
|
|
}
|
|
|
|
func runKarma(myKarmaExecuteTestsOptions karmaExecuteTestsOptions, command execRunner) {
|
|
installCommandTokens := tokenize(myKarmaExecuteTestsOptions.InstallCommand)
|
|
command.Dir(myKarmaExecuteTestsOptions.ModulePath)
|
|
err := command.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...)
|
|
if err != nil {
|
|
log.Entry().
|
|
WithError(err).
|
|
WithField("command", myKarmaExecuteTestsOptions.InstallCommand).
|
|
Fatal("failed to execute install command")
|
|
}
|
|
|
|
runCommandTokens := tokenize(myKarmaExecuteTestsOptions.RunCommand)
|
|
command.Dir(myKarmaExecuteTestsOptions.ModulePath)
|
|
err = command.RunExecutable(runCommandTokens[0], runCommandTokens[1:]...)
|
|
if err != nil {
|
|
log.Entry().
|
|
WithError(err).
|
|
WithField("command", myKarmaExecuteTestsOptions.RunCommand).
|
|
Fatal("failed to execute run command")
|
|
}
|
|
}
|
|
|
|
func tokenize(command string) []string {
|
|
return strings.Split(command, " ")
|
|
}
|