Skip to content

Commit

Permalink
chore: resolve a issue with the sarif upload test case
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippHeuer committed Mar 5, 2024
1 parent 961368b commit a9f48de
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# generated artifacts
.dist/*
.tmp/*

23 changes: 12 additions & 11 deletions actions/github/githubpublishsarif/github-sarif-upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ func (a Action) Execute() (err error) {
}
for _, report := range *artifacts {
// get report content
sarif, err := a.Sdk.ArtifactDownloadByteArray(cidsdk.ArtifactDownloadByteArrayRequest{
sarif, reportErr := a.Sdk.ArtifactDownloadByteArray(cidsdk.ArtifactDownloadByteArrayRequest{
ID: report.ID,
})
if err != nil {
return fmt.Errorf("failed to load report %s", report.Name)
if reportErr != nil {
return fmt.Errorf("failed to load report %s: %w", report.Name, reportErr)
}

// encoding
sarifEncoded, err := encoding.GZIPBase64EncodeBytes(sarif)
if err != nil {
return fmt.Errorf("failed to encode sarif report (gzip/base64)")
sarifEncoded, reportErr := encoding.GZIPBase64EncodeBytes(sarif)
if reportErr != nil {
return fmt.Errorf("failed to encode sarif report (gzip/base64): %w", err)
}

// git reference (sarif upload with pull request ref will result in pull request comments)
Expand All @@ -67,15 +67,16 @@ func (a Action) Execute() (err error) {
// upload
_ = a.Sdk.Log(cidsdk.LogMessageRequest{Level: "info", Message: "uploading sarif report to github code scanning api", Context: map[string]interface{}{"report": report.Name, "ref": ref, "commit_hash": ctx.Env["NCI_COMMIT_HASH"]}})
sarifAnalysis := &github.SarifAnalysis{CommitSHA: github.String(ctx.Env["NCI_COMMIT_HASH"]), Ref: github.String(ref), Sarif: github.String(sarifEncoded), CheckoutURI: github.String(ctx.Config.ProjectDir)}
sarifId, _, err := client.CodeScanning.UploadSarif(context.Background(), organization, repository, sarifAnalysis)
if err != nil {
// "job scheduled on GitHub side" is not a error, job just isn't completed yet
if strings.Contains(err.Error(), "job scheduled on GitHub side") {
sarifId, _, reportErr := client.CodeScanning.UploadSarif(context.Background(), organization, repository, sarifAnalysis)

if reportErr != nil {
// "job scheduled on GitHub side" is not an error, job just isn't completed yet
if strings.Contains(reportErr.Error(), "job scheduled on GitHub side") {
_ = a.Sdk.Log(cidsdk.LogMessageRequest{Level: "info", Message: "sarif upload successful", Context: map[string]interface{}{"report": report.Name, "state": "github_job_pending"}})
} else {
return fmt.Errorf("failed to upload sarif to github code-scanning api: %s", err.Error())
}
} else {
} else if sarifId != nil {
_ = a.Sdk.Log(cidsdk.LogMessageRequest{Level: "info", Message: "sarif upload successful", Context: map[string]interface{}{"report": report.Name, "state": "ok", "id": *sarifId.ID, "url": *sarifId.URL}})
}
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/cidverse/cid-actions-go
go 1.21

require (
github.com/cidverse/cid-sdk-go v0.0.0-20240205184845-858438ab8005
github.com/cidverse/cidverseutils v0.0.0-20231103225801-e7f71d0c6aba
github.com/cidverse/cid-sdk-go v0.0.0-20240302200041-f4b4b4ae14d0
github.com/cidverse/cidverseutils v0.0.0-20240302003507-f592801a7e1a
github.com/containers/image/v5 v5.30.0
github.com/go-resty/resty/v2 v2.11.0
github.com/google/go-github/v60 v60.0.0
Expand Down Expand Up @@ -46,6 +46,6 @@ require (
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/cidverse/cid-sdk-go v0.0.0-20240205184845-858438ab8005 h1:OTBR4Sp/d5lN0p5p2M4/HmqfZ9C1qOljlNb6ao7sty8=
github.com/cidverse/cid-sdk-go v0.0.0-20240205184845-858438ab8005/go.mod h1:qDlFs3yZMg06T3j/xyFnAjIF8ZSCALpChf6ZfbYFTqA=
github.com/cidverse/cidverseutils v0.0.0-20231103225801-e7f71d0c6aba h1:7z1+V18zViJmUovZ3P8nIbRdegA5viST6BsBUBNfrMw=
github.com/cidverse/cidverseutils v0.0.0-20231103225801-e7f71d0c6aba/go.mod h1:VRpKsgkaw9kS2Ya7/Hzd2gnbYqiMSSPR9L9ZLaymG04=
github.com/cidverse/cid-sdk-go v0.0.0-20240302200041-f4b4b4ae14d0 h1:3orjoFtmNgoABSoei3xYyz0erpXuGSot4Fp06d2xz64=
github.com/cidverse/cid-sdk-go v0.0.0-20240302200041-f4b4b4ae14d0/go.mod h1:9T5DHVcr3sEOQ9N2ZJwIofeA2mp+j+n/50cQNJFQLtM=
github.com/cidverse/cidverseutils v0.0.0-20240302003507-f592801a7e1a h1:bnLhBQh+pGkf5lMfkC5nVVvooMFeWhrn3nlYbZ2UZ+s=
github.com/cidverse/cidverseutils v0.0.0-20240302003507-f592801a7e1a/go.mod h1:m71LmY0gEvKZ2jxFboMdGCcN9DgFlOmwNGH2TjM2nS4=
github.com/containers/image/v5 v5.30.0 h1:CmHeSwI6W2kTRWnUsxATDFY5TEX4b58gPkaQcEyrLIA=
github.com/containers/image/v5 v5.30.0/go.mod h1:gSD8MVOyqBspc0ynLsuiMR9qmt8UQ4jpVImjmK0uXfk=
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 h1:Qzk5C6cYglewc+UyGf6lc8Mj2UaPTHy/iF2De0/77CA=
Expand Down Expand Up @@ -173,8 +173,8 @@ google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAs
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down

0 comments on commit a9f48de

Please sign in to comment.