Skip to content

Commit

Permalink
abapEnvironmentAssemblePackages Check for Build Errors (#5214)
Browse files Browse the repository at this point in the history
* Check for Build Errors
  • Loading branch information
tiloKo authored Jan 7, 2025
1 parent 04e5df1 commit f06e29f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
4 changes: 4 additions & 0 deletions cmd/abapEnvironmentAssemblePackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ func checkIfFailedAndPrintLogs(builds []buildWithRepository) error {
log.Entry().Errorf("Assembly of %s failed", builds[i].repo.PackageName)
buildFailed = true
}
if builds[i].build.ResultState == abapbuild.Erroneous {
log.Entry().Errorf("Assembly of %s revealed errors", builds[i].repo.PackageName)
buildFailed = true
}
if builds[i].build.BuildID != "" {
if err := builds[i].build.PrintLogs(); err != nil {
return err
Expand Down
26 changes: 13 additions & 13 deletions pkg/abap/build/bfw.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (

// RunState : Current Status of the Build
type RunState string
type resultState string
type ResultState string
type msgty string

const (
successful resultState = "SUCCESSFUL"
warning resultState = "WARNING"
erroneous resultState = "ERRONEOUS"
aborted resultState = "ABORTED"
Successful ResultState = "SUCCESSFUL"
Warning ResultState = "WARNING"
Erroneous ResultState = "ERRONEOUS"
Aborted ResultState = "ABORTED"

Initializing RunState = "INITIALIZING" // Initializing : Build Framework prepared
Accepted RunState = "ACCEPTED" // Accepted : Build Framework triggered
Expand All @@ -46,7 +46,7 @@ type jsonBuild struct {
Build struct {
BuildID string `json:"build_id"`
RunState RunState `json:"run_state"`
ResultState resultState `json:"result_state"`
ResultState ResultState `json:"result_state"`
Phase string `json:"phase"`
Entitytype string `json:"entitytype"`
Startedby string `json:"startedby"`
Expand All @@ -68,7 +68,7 @@ type jsonTask struct {
PluginClass string `json:"plugin_class"`
StartedAt string `json:"started_at"`
FinishedAt string `json:"finished_at"`
ResultState resultState `json:"result_state"`
ResultState ResultState `json:"result_state"`
}

type jsonLogs struct {
Expand Down Expand Up @@ -96,7 +96,7 @@ type Build struct {
Connector Connector
BuildID string `json:"build_id"`
RunState RunState `json:"run_state"`
ResultState resultState `json:"result_state"`
ResultState ResultState `json:"result_state"`
Phase string `json:"phase"`
Entitytype string `json:"entitytype"`
Startedby string `json:"startedby"`
Expand All @@ -114,7 +114,7 @@ type task struct {
PluginClass string `json:"plugin_class"`
StartedAt string `json:"started_at"`
FinishedAt string `json:"finished_at"`
ResultState resultState `json:"result_state"`
ResultState ResultState `json:"result_state"`
Logs []logStruct
Results []Result
}
Expand Down Expand Up @@ -221,11 +221,11 @@ func (b *Build) EvaluteIfBuildSuccessful(treatWarningsAsError bool) error {
if b.RunState == Failed {
return errors.Errorf("Build ended with runState failed")
}
if treatWarningsAsError && b.ResultState == warning {
return errors.Errorf("Build ended with resultState warning, setting to failed as configured")
if treatWarningsAsError && b.ResultState == Warning {
return errors.Errorf("Build ended with ResultState warning, setting to failed as configured")
}
if (b.ResultState == aborted) || (b.ResultState == erroneous) {
return errors.Errorf("Build ended with resultState %s", b.ResultState)
if (b.ResultState == Aborted) || (b.ResultState == Erroneous) {
return errors.Errorf("Build ended with ResultState %s", b.ResultState)
}
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/abap/build/bfw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestEvaluteIfBuildSuccessful(t *testing.T) {
t.Run("No error", func(t *testing.T) {
//arrange
build.RunState = Finished
build.ResultState = successful
build.ResultState = Successful
//act
err := build.EvaluteIfBuildSuccessful(treatWarningsAsError)
//assert
Expand All @@ -210,7 +210,7 @@ func TestEvaluteIfBuildSuccessful(t *testing.T) {
t.Run("ResultState aborted => Error", func(t *testing.T) {
//arrange
build.RunState = Finished
build.ResultState = aborted
build.ResultState = Aborted
//act
err := build.EvaluteIfBuildSuccessful(treatWarningsAsError)
//assert
Expand All @@ -219,7 +219,7 @@ func TestEvaluteIfBuildSuccessful(t *testing.T) {
t.Run("ResultState erroneous => Error", func(t *testing.T) {
//arrange
build.RunState = Finished
build.ResultState = erroneous
build.ResultState = Erroneous
//act
err := build.EvaluteIfBuildSuccessful(treatWarningsAsError)
//assert
Expand All @@ -228,7 +228,7 @@ func TestEvaluteIfBuildSuccessful(t *testing.T) {
t.Run("ResultState warning, treatWarningsAsError false => No error", func(t *testing.T) {
//arrange
build.RunState = Finished
build.ResultState = warning
build.ResultState = Warning
//act
err := build.EvaluteIfBuildSuccessful(treatWarningsAsError)
//assert
Expand All @@ -237,7 +237,7 @@ func TestEvaluteIfBuildSuccessful(t *testing.T) {
t.Run("ResultState warning, treatWarningsAsError true => error", func(t *testing.T) {
//arrange
build.RunState = Finished
build.ResultState = warning
build.ResultState = Warning
treatWarningsAsError = true
//act
err := build.EvaluteIfBuildSuccessful(treatWarningsAsError)
Expand Down

0 comments on commit f06e29f

Please sign in to comment.