Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into kaniko-context-pr…
Browse files Browse the repository at this point in the history
…efix-fix
  • Loading branch information
maxatsap committed May 1, 2023
2 parents bd9270c + 6dad124 commit 2784ab5
Show file tree
Hide file tree
Showing 87 changed files with 3,225 additions and 653 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ AbapAddonAssemblyKit* @SAP/jenkins-library-abap
abapEnvironment* @SAP/jenkins-library-abap
AbapEnvironment* @SAP/jenkins-library-abap

ascAppUpload* @Mau04 @inf2381
AscAppUpload* @Mau04 @inf2381

#####################
# Integration tests #
Expand Down
20 changes: 17 additions & 3 deletions cmd/abapEnvironmentBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func runBuilds(conn *abapbuild.Connector, config *abapEnvironmentBuildOptions, u
}
finalValuesForOneBuild, err := runBuild(conn, config, utils, cummulatedValues)
if err != nil {
err = errors.Wrapf(err, "Build with input values %s failed", values)
err = errors.Wrapf(err, "Build with input values %s failed", values2string(values))
if config.StopOnFirstError {
return finalValues, err
}
Expand Down Expand Up @@ -406,12 +406,15 @@ func (vE *valuesEvaluator) appendStringValuesIfNotPresent(stringValues string, t

func (vE *valuesEvaluator) appendValuesIfNotPresent(values []abapbuild.Value, throwErrorIfPresent bool) error {
for _, value := range values {
if value.ValueID == "PHASE" || value.ValueID == "BUILD_FRAMEWORK_MODE" {
continue
}
_, present := vE.m[value.ValueID]
if present || (value.ValueID == "PHASE") {
if present {
if throwErrorIfPresent {
return errors.Errorf("Value_id %s already existed in the config", value.ValueID)
}
log.Entry().Infof("Value %s already existed -> discard this value", value)
log.Entry().Infof("Value '%s':'%s' already existed -> discard this value", value.ValueID, value.Value)
} else {
vE.m[value.ValueID] = value.Value
}
Expand Down Expand Up @@ -573,3 +576,14 @@ func Equal(a, b string) bool {
func Unequal(a, b string) bool {
return a != b
}

func values2string(values []abapbuild.Value) string {
var result string
for index, value := range values {
if index > 0 {
result = result + "; "
}
result = result + value.ValueID + " = " + value.Value
}
return result
}
13 changes: 12 additions & 1 deletion cmd/abapEnvironmentBuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestRunAbapEnvironmentBuild(t *testing.T) {
// test
err := runAbapEnvironmentBuild(&config, nil, utils, &cpe)
// assert
finalValues := `[{"value_id":"PACKAGES","value":"/BUILD/AUNIT_DUMMY_TESTS"},{"value_id":"BUILD_FRAMEWORK_MODE","value":"P"}]`
finalValues := `[{"value_id":"PACKAGES","value":"/BUILD/AUNIT_DUMMY_TESTS"}]`
err = json.Unmarshal([]byte(finalValues), &expectedValueList)
assert.NoError(t, err)
err = json.Unmarshal([]byte(cpe.abap.buildValues), &recordedValueList)
Expand Down Expand Up @@ -388,6 +388,17 @@ func TestEvaluateAddonDescriptor(t *testing.T) {
})
}

func TestValues2String(t *testing.T) {
t.Run("dito", func(t *testing.T) {
var myValues []abapbuild.Value
myValues = append(myValues, abapbuild.Value{ValueID: "Name", Value: "Hugo"})
myValues = append(myValues, abapbuild.Value{ValueID: "Age", Value: "43"})
myValues = append(myValues, abapbuild.Value{ValueID: "Hight", Value: "17cm"})
myString := values2string(myValues)
assert.Equal(t, "Name = Hugo; Age = 43; Hight = 17cm", myString)
})
}

var addonDescriptor = `{
"addonProduct":"/ITAPC1/I_CURRENCZPRODUCT",
"addonVersion":"1.0.0",
Expand Down
23 changes: 11 additions & 12 deletions cmd/abapEnvironmentCheckoutBranch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import (
var executionLogStringCheckout string

func init() {
executionLog := abaputils.PullEntity{
ToExecutionLog: abaputils.AbapLogs{
Results: []abaputils.LogResults{
{
Index: "1",
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
executionLog := abaputils.LogProtocolResults{
Results: []abaputils.LogProtocol{
{
ProtocolLine: 1,
OverviewIndex: 1,
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
},
}
Expand Down Expand Up @@ -55,9 +54,9 @@ func TestCheckoutBranchStep(t *testing.T) {
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringCheckout + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "S" } }`,
Expand All @@ -84,9 +83,9 @@ func TestCheckoutBranchStep(t *testing.T) {
logResultError := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Error", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringCheckout + `}`,
logResultError,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "E" } }`,
Expand Down Expand Up @@ -123,9 +122,9 @@ func TestCheckoutBranchStep(t *testing.T) {
logResultError := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Error", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringCheckout + `}`,
logResultError,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "E" } }`,
Expand Down
29 changes: 14 additions & 15 deletions cmd/abapEnvironmentCloneGitRepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ import (
var executionLogStringClone string

func init() {
executionLog := abaputils.PullEntity{
ToExecutionLog: abaputils.AbapLogs{
Results: []abaputils.LogResults{
{
Index: "1",
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
executionLog := abaputils.LogProtocolResults{
Results: []abaputils.LogProtocol{
{
ProtocolLine: 1,
OverviewIndex: 1,
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
},
}
Expand Down Expand Up @@ -78,16 +77,16 @@ repositories:
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : [] }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
Expand Down Expand Up @@ -124,9 +123,9 @@ repositories:
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
Expand Down Expand Up @@ -397,15 +396,15 @@ func TestALreadyCloned(t *testing.T) {
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
Expand Down Expand Up @@ -479,7 +478,7 @@ func TestALreadyCloned(t *testing.T) {
err := errors.New("Custom Error")
err, _ = handleCloneError(&resp, err, autils.ReturnedConnectionDetailsHTTP, client, repo)
if assert.Error(t, err, "Expected error") {
assert.Equal(t, "Pull of the repository / software component 'Test', commit 'abcd1234' failed on the ABAP system", err.Error(), "Expected different error message")
assert.Equal(t, "Pull of the repository / software component 'Test', commit 'abcd1234' failed on the ABAP system: Request to ABAP System not successful", err.Error(), "Expected different error message")
}
})

Expand Down
20 changes: 10 additions & 10 deletions cmd/abapEnvironmentPullGitRepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ var executionLogStringPull string
var logResultErrorPull string

func init() {
executionLog := abaputils.PullEntity{
ToExecutionLog: abaputils.AbapLogs{
Results: []abaputils.LogResults{
{
Index: "1",
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
executionLog := abaputils.LogProtocolResults{
Results: []abaputils.LogProtocol{
{
ProtocolLine: 1,
OverviewIndex: 1,
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
},
}
Expand Down Expand Up @@ -57,9 +56,9 @@ func TestPullStep(t *testing.T) {
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringPull + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
Expand All @@ -71,6 +70,7 @@ func TestPullStep(t *testing.T) {

err := runAbapEnvironmentPullGitRepo(&config, &autils, client)
assert.NoError(t, err, "Did not expect error")
assert.Equal(t, 0, len(client.BodyList), "Not all requests were done")
})

t.Run("Run Step Failure", func(t *testing.T) {
Expand Down
106 changes: 106 additions & 0 deletions cmd/ascAppUpload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package cmd

import (
"github.com/SAP/jenkins-library/pkg/asc"
"github.com/SAP/jenkins-library/pkg/command"
piperHttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/pkg/errors"
)

type ascAppUploadUtils interface {
command.ExecRunner
}

type ascAppUploadUtilsBundle struct {
*command.Command
*piperutils.Files
}

func newAscAppUploadUtils() ascAppUploadUtils {
utils := ascAppUploadUtilsBundle{
Command: &command.Command{},
Files: &piperutils.Files{},
}
// Reroute command output to logging framework
utils.Stdout(log.Writer())
utils.Stderr(log.Writer())
return &utils
}

func ascAppUpload(config ascAppUploadOptions, telemetryData *telemetry.CustomData) {
utils := newAscAppUploadUtils()
client := &piperHttp.Client{}

ascClient, err := asc.NewSystemInstance(client, config.ServerURL, config.AppToken)
if err != nil {
log.Entry().WithError(err).Fatalf("Failed to create ASC client talking to URL %v", config.ServerURL)
} else {
err = runAscAppUpload(&config, telemetryData, utils, ascClient)
}

if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}

func runAscAppUpload(config *ascAppUploadOptions, telemetryData *telemetry.CustomData, utils ascAppUploadUtils, ascClient asc.System) error {

if len(config.JamfTargetSystem) == 0 {
return errors.Errorf("jamfTargetSystem must be set")
}

log.Entry().Infof("Collect data to create new release in ASC")

app, err := ascClient.GetAppById(config.AppID)
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return errors.Wrapf(err, "failed to get app information")
}

log.Entry().Debugf("Found App with name %v", app.AppName)

log.Entry().Infof("Create release for %v in ASC (AppID %v)", app.AppName, app.AppId)

releaseResponse, err := ascClient.CreateRelease(app.AppId, config.ReleaseAppVersion, config.ReleaseDescription, config.ReleaseDate, config.ReleaseVisible)

if err != nil {
log.SetErrorCategory(log.ErrorService)
return errors.Wrapf(err, "failed to create release")
}

if releaseResponse.Status != "success" {
log.SetErrorCategory(log.ErrorService)
return errors.New(releaseResponse.Message)
}

log.Entry().Infof("Collect data to upload app to ASC & Jamf")

jamfAppInformationResponse, err := ascClient.GetJamfAppInfo(app.BundleId, config.JamfTargetSystem)
if err != nil {
log.SetErrorCategory(log.ErrorService)
return errors.Wrapf(err, "failed to get jamf app info")
}

jamfAppId := jamfAppInformationResponse.MobileDeviceApplication.General.Id

if jamfAppId == 0 {
return errors.Errorf("failed to get jamf app id")
}

log.Entry().Debugf("Got Jamf info for app %v, jamfId: %v", app.AppName, jamfAppId)

log.Entry().Infof("Upload ipa %v to ASC & Jamf", config.FilePath)

err = ascClient.UploadIpa(config.FilePath, jamfAppId, config.JamfTargetSystem, app.BundleId, releaseResponse.Data)
if err != nil {
log.SetErrorCategory(log.ErrorService)
return errors.Wrapf(err, "failed to upload ipa")
}

log.Entry().Infof("Successfully uploaded %v to ASC (AppId %v) & Jamf (Id %v)", config.FilePath, app.AppId, jamfAppId)

return nil
}
Loading

0 comments on commit 2784ab5

Please sign in to comment.