Skip to content

Commit

Permalink
Add debug logs, cean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperMalachowski committed Jan 31, 2025
1 parent 2b39eae commit c470112
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
9 changes: 3 additions & 6 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,25 +399,22 @@ func buildInADO(o options) error {

o.logger.Debugw("Extracted built images from ADO logs", "images", images)

if o.dryRun {
fmt.Println("Running in dry-run mode. Skipping extracting images and results from ADO.")
images = []string{"registry/repo/image1:tag1", "registry/repo/image2:tag2"}
}
data, err := json.Marshal(images)
if err != nil {
return fmt.Errorf("cannot marshal list of images: %w", err)
}

o.logger.Debugw("Set GitHub outputs", "images", string(data), "adoResult", string(*pipelineRunResult))

err = actions.SetOutput("images", string(data))
if err != nil {
return fmt.Errorf("cannot set images GitHub output: %w", err)
}
fmt.Println("images GitHub output set")

err = actions.SetOutput("adoResult", string(*pipelineRunResult))
if err != nil {
return fmt.Errorf("cannot set adoResult GitHub output: %w", err)
}
fmt.Println("adoResult GitHub output set")
}

if o.buildReportPath != "" {
Expand Down
8 changes: 2 additions & 6 deletions pkg/imagebuilder/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
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+`)
timestampRegex = regexp.MustCompile(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z\s`)
)

type BuildReport struct {
Expand All @@ -36,10 +36,6 @@ type ImageSpec struct {
func (br *BuildReport) GetImages() []string {
var images []string

if br == nil {
return images
}

for _, tag := range br.ImageSpec.Tags {
images = append(images, fmt.Sprintf("%s%s:%s", br.ImageSpec.RepositoryPath, br.ImageSpec.Name, tag))
}
Expand All @@ -54,7 +50,7 @@ func NewBuildReportFromLogs(log string) (*BuildReport, error) {
// Find the report in the log
matches := reportRegex.FindStringSubmatch(log)
if len(matches) < 2 {
return nil, nil
return nil, fmt.Errorf("no image build report found in log")
}

// Parse the report data
Expand Down
12 changes: 7 additions & 5 deletions pkg/imagebuilder/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ var _ = Describe("Report", func() {

Expect(actual).To(Equal(expectedReport))
})

It("returns an error if the log does not contain the image build report", func() {
logs := `2025-01-31T08:32:23.5327056Z ##[section]Starting: prepare_image_build_report`

_, err := NewBuildReportFromLogs(logs)
Expect(err).To(HaveOccurred())
})
})

Describe("GetImages", func() {
Expand Down Expand Up @@ -86,11 +93,6 @@ var _ = Describe("Report", func() {

Expect(report.GetImages()).To(BeEmpty())
})

It("returns an empty list if build report is nil", func() {
var nilReport *BuildReport
Expect(nilReport.GetImages()).To(BeEmpty())
})
})

Describe("WriteReportToFile", func() {
Expand Down

0 comments on commit c470112

Please sign in to comment.