Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip timestamps before searching report string #12616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/imagebuilder/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (
)

// reportRegex is a regular expression that matches the image build report
var reportRegex = regexp.MustCompile(`(?s)---IMAGE BUILD REPORT---\n(.*)\n---END OF IMAGE BUILD REPORT---`)
var (
reportRegex = regexp.MustCompile(`(?s)---IMAGE BUILD REPORT---\n(.*)\n---END OF IMAGE BUILD REPORT---`)

timestampRegex = regexp.MustCompile(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z\s+`)
)

type BuildReport struct {
// Status is the overall status of the build including signing and pushing
Expand Down Expand Up @@ -44,11 +48,16 @@ func (br *BuildReport) GetImages() []string {
}

func NewBuildReportFromLogs(log string) (*BuildReport, error) {
// Strip all timestamps from log
log = timestampRegex.ReplaceAllString(log, "")

// Find the report in the log
matches := reportRegex.FindStringSubmatch(log)
if len(matches) < 2 {
return nil, nil
}

// Parse the report data
var report BuildReport
if err := json.Unmarshal([]byte(matches[1]), &report); err != nil {
return nil, err
Expand Down
66 changes: 31 additions & 35 deletions pkg/imagebuilder/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,41 @@ import (

var _ = Describe("Report", func() {
Describe("NewReportFromLogs", func() {
logs := `Starting: prepare_image_build_report
==============================================================================
Task : Python script
Description : Run a Python file or inline script
Version : 0.248.1
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/python-script
==============================================================================
/usr/bin/python /home/vsts/work/1/s/scripts/prepare_image_build_report.py --image-build-report-file /home/vsts/work/1/s/image-report.json --image-name ginkgo-test-image/ginkgo --sign-step-succeeded true --job-status Succeeded --image-build-report-file /home/vsts/work/_temp/generated-tags.json --images-to-sign=europe-docker.pkg.dev/kyma-project/prod/ginkgo-test-image/ginkgo:1.23.0-50049457 --images-to-sign=europe-docker.pkg.dev/kyma-project/prod/ginkgo-test-image/ginkgo:wartosc --images-to-sign=europe-docker.pkg.dev/kyma-project/prod/ginkgo-test-image/ginkgo:innytag --images-to-sign=europe-docker.pkg.dev/kyma-project/prod/ginkgo-test-image/ginkgo:v20250129-50049457 --images-to-sign=europe-docker.pkg.dev/kyma-project/prod/ginkgo-test-image/ginkgo:1.23.0
---IMAGE BUILD REPORT---
{
"status": "Succeeded",
"pushed": true,
"signed": true,
"is_production": true,
"image_spec": {
"image_name": "ginkgo-test-image/ginkgo",
"tags": [
"1.23.0-50049457",
"wartosc",
"innytag",
"v20250129-50049457",
"1.23.0"
],
"repository_path": "europe-docker.pkg.dev/kyma-project/prod/"
}
}
---END OF IMAGE BUILD REPORT---

Finishing: prepare_image_build_report`
logs := `2025-01-31T08:32:23.5327056Z ##[section]Starting: prepare_image_build_report
2025-01-31T08:32:23.5434336Z ==============================================================================
2025-01-31T08:32:23.5434499Z Task : Python script
2025-01-31T08:32:23.5434594Z Description : Run a Python file or inline script
2025-01-31T08:32:23.5434703Z Version : 0.248.1
2025-01-31T08:32:23.5434803Z Author : Microsoft Corporation
2025-01-31T08:32:23.5434910Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/python-script
2025-01-31T08:32:23.5435059Z ==============================================================================
2025-01-31T08:32:23.6965198Z [command]/opt/hostedtoolcache/Python/3.13.1/x64/bin/python /home/vsts/work/1/s/scripts/prepare_image_build_report.py --image-name github-tools-sap/conduit-cli --image-build-succeeded true --sign-step-succeeded $(sign_images.signing_success) --job-status Succeeded --images-to-sign=europe-docker.pkg.dev/kyma-project/dev/github-tools-sap/conduit-cli:PR-477
2025-01-31T08:32:23.7344251Z ---IMAGE BUILD REPORT---
2025-01-31T08:32:23.7345746Z {
2025-01-31T08:32:23.7346062Z "status": "Succeeded",
2025-01-31T08:32:23.7357582Z "pushed": true,
2025-01-31T08:32:23.7358184Z "signed": false,
2025-01-31T08:32:23.7358759Z "is_production": false,
2025-01-31T08:32:23.7359525Z "image_spec": {
2025-01-31T08:32:23.7360295Z "image_name": "github-tools-sap/conduit-cli",
2025-01-31T08:32:23.7360618Z "tags": [
2025-01-31T08:32:23.7361207Z "PR-477"
2025-01-31T08:32:23.7361687Z ],
2025-01-31T08:32:23.7362370Z "repository_path": "europe-docker.pkg.dev/kyma-project/dev/"
2025-01-31T08:32:23.7362690Z }
2025-01-31T08:32:23.7363276Z }
2025-01-31T08:32:23.7363903Z ---END OF IMAGE BUILD REPORT---
2025-01-31T08:32:23.7416532Z
2025-01-31T08:32:23.7530550Z ##[section]Finishing: prepare_image_build_report`
expectedReport := &BuildReport{
Status: "Succeeded",
IsPushed: true,
IsSigned: true,
IsProduction: true,
IsSigned: false,
IsProduction: false,
ImageSpec: ImageSpec{
Name: "ginkgo-test-image/ginkgo",
Tags: []string{"1.23.0-50049457", "wartosc", "innytag", "v20250129-50049457", "1.23.0"},
RepositoryPath: "europe-docker.pkg.dev/kyma-project/prod/",
Name: "github-tools-sap/conduit-cli",
Tags: []string{"PR-477"},
RepositoryPath: "europe-docker.pkg.dev/kyma-project/dev/",
},
}

Expand Down
Loading