From 1cc6f3fc02c09633452ee917b60a1762d9d0409b Mon Sep 17 00:00:00 2001 From: Matthias Diester Date: Thu, 18 Jan 2024 11:11:02 +0100 Subject: [PATCH] Add timestamp fields to resource objects Update CRDs to include timestamp fields. Add timestamp fields for Git and Bundle results. --- deploy/crds/shipwright.io_buildruns.yaml | 26 +++++ pkg/apis/build/v1alpha1/buildrun_types.go | 10 ++ pkg/apis/build/v1beta1/buildrun_types.go | 10 ++ .../buildrun/resources/sources/bundle.go | 31 ++++-- .../buildrun/resources/sources/git.go | 67 +++++++------ .../buildrun/resources/sources/git_test.go | 57 +++++------ .../buildrun/resources/taskrun_test.go | 22 ++--- test/integration/build_to_buildruns_test.go | 1 + test/integration/build_to_git_test.go | 6 +- test/integration/build_to_taskruns_test.go | 1 + test/integration/buildrun_status_test.go | 96 +++++++++++++++++++ test/v1alpha1_samples/catalog.go | 3 + 12 files changed, 243 insertions(+), 87 deletions(-) create mode 100644 test/integration/buildrun_status_test.go diff --git a/deploy/crds/shipwright.io_buildruns.yaml b/deploy/crds/shipwright.io_buildruns.yaml index d3cb6e5b2e..d654b8125b 100644 --- a/deploy/crds/shipwright.io_buildruns.yaml +++ b/deploy/crds/shipwright.io_buildruns.yaml @@ -6313,6 +6313,15 @@ spec: digest: description: Digest hold the image digest result type: string + image_timestamp: + description: ImageTimestamp holds the (bundle) image timestamp + result + type: string + source_timestamp: + description: SourceTimestamp holds the source timestamp, + meaning the most recent timestamp of all files that are + used as source + type: string type: object git: description: Git holds the results emitted from from the step @@ -6330,6 +6339,10 @@ spec: commitSha: description: CommitSha holds the commit sha of git source type: string + commitTimestamp: + description: CommitTimestamp holds the commit timestamp + of a git source + type: string type: object name: description: Name is the name of source @@ -12543,6 +12556,10 @@ spec: commitSha: description: CommitSha holds the commit sha of git source type: string + commitTimestamp: + description: CommitTimestamp holds the commit timestamp of + a git source + type: string type: object ociArtifact: description: OciArtifact holds the results emitted from the source @@ -12551,6 +12568,15 @@ spec: digest: description: Digest hold the image digest result type: string + image_timestamp: + description: ImageTimestamp holds the (bundle) image timestamp + result + type: string + source_timestamp: + description: SourceTimestamp holds the source timestamp, meaning + the most recent timestamp of all files that are used as + source + type: string type: object type: object startTime: diff --git a/pkg/apis/build/v1alpha1/buildrun_types.go b/pkg/apis/build/v1alpha1/buildrun_types.go index f8458f82b2..60c551355d 100644 --- a/pkg/apis/build/v1alpha1/buildrun_types.go +++ b/pkg/apis/build/v1alpha1/buildrun_types.go @@ -123,6 +123,13 @@ type SourceResult struct { type BundleSourceResult struct { // Digest hold the image digest result Digest string `json:"digest,omitempty"` + + // ImageTimestamp holds the (bundle) image timestamp result + ImageTimestamp string `json:"image_timestamp,omitempty"` + + // SourceTimestamp holds the source timestamp, meaning the most recent + // timestamp of all files that are used as source + SourceTimestamp string `json:"source_timestamp,omitempty"` } // GitSourceResult holds the results emitted from the git source @@ -133,6 +140,9 @@ type GitSourceResult struct { // CommitAuthor holds the commit author of a git source CommitAuthor string `json:"commitAuthor,omitempty"` + // CommitTimestamp holds the commit timestamp of a git source + CommitTimestamp string `json:"commitTimestamp,omitempty"` + // BranchName holds the default branch name of the git source // this will be set only when revision is not specified in Build object BranchName string `json:"branchName,omitempty"` diff --git a/pkg/apis/build/v1beta1/buildrun_types.go b/pkg/apis/build/v1beta1/buildrun_types.go index 7a40e822b0..b09938552a 100644 --- a/pkg/apis/build/v1beta1/buildrun_types.go +++ b/pkg/apis/build/v1beta1/buildrun_types.go @@ -128,6 +128,13 @@ type SourceResult struct { type OciArtifactSourceResult struct { // Digest hold the image digest result Digest string `json:"digest,omitempty"` + + // ImageTimestamp holds the (bundle) image timestamp result + ImageTimestamp string `json:"image_timestamp,omitempty"` + + // SourceTimestamp holds the source timestamp, meaning the most recent + // timestamp of all files that are used as source + SourceTimestamp string `json:"source_timestamp,omitempty"` } // GitSourceResult holds the results emitted from the git source @@ -138,6 +145,9 @@ type GitSourceResult struct { // CommitAuthor holds the commit author of a git source CommitAuthor string `json:"commitAuthor,omitempty"` + // CommitTimestamp holds the commit timestamp of a git source + CommitTimestamp string `json:"commitTimestamp,omitempty"` + // BranchName holds the default branch name of the git source // this will be set only when revision is not specified in Build object // diff --git a/pkg/reconciler/buildrun/resources/sources/bundle.go b/pkg/reconciler/buildrun/resources/sources/bundle.go index 8b7eda6402..536928b4a1 100644 --- a/pkg/reconciler/buildrun/resources/sources/bundle.go +++ b/pkg/reconciler/buildrun/resources/sources/bundle.go @@ -24,10 +24,20 @@ func AppendBundleStep( name string, ) { // append the result - taskSpec.Results = append(taskSpec.Results, pipelineapi.TaskResult{ - Name: fmt.Sprintf("%s-source-%s-image-digest", prefixParamsResultsVolumes, name), - Description: "The digest of the bundle image.", - }) + taskSpec.Results = append(taskSpec.Results, + pipelineapi.TaskResult{ + Name: fmt.Sprintf("%s-source-%s-image-digest", prefixParamsResultsVolumes, name), + Description: "The digest of the bundle image.", + }, + pipelineapi.TaskResult{ + Name: fmt.Sprintf("%s-source-%s-image-timestamp", prefixParamsResultsVolumes, name), + Description: "The timestamp of the bundle image.", + }, + pipelineapi.TaskResult{ + Name: fmt.Sprintf("%s-source-%s-source-timestamp", prefixParamsResultsVolumes, name), + Description: "The timestamp of the most recent source file.", + }, + ) // initialize the step from the template and the build-specific arguments bundleStep := pipelineapi.Step{ @@ -39,6 +49,8 @@ func AppendBundleStep( "--image", source.BundleContainer.Image, "--target", fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), "--result-file-image-digest", fmt.Sprintf("$(results.%s-source-%s-image-digest.path)", prefixParamsResultsVolumes, name), + "--result-file-image-timestamp", fmt.Sprintf("$(results.%s-source-%s-image-timestamp.path)", prefixParamsResultsVolumes, name), + "--result-file-source-timestamp", fmt.Sprintf("$(results.%s-source-%s-source-timestamp.path)", prefixParamsResultsVolumes, name), }, Env: cfg.BundleContainerTemplate.Env, ComputeResources: cfg.BundleContainerTemplate.Resources, @@ -76,12 +88,19 @@ func AppendBundleStep( // AppendBundleResult append bundle source result to build run func AppendBundleResult(buildRun *build.BuildRun, name string, results []pipelineapi.TaskRunResult) { imageDigest := findResultValue(results, fmt.Sprintf("%s-source-%s-image-digest", prefixParamsResultsVolumes, name)) + imageTimestamp := findResultValue(results, fmt.Sprintf("%s-source-%s-image-timestamp", prefixParamsResultsVolumes, name)) + sourceTimestamp := findResultValue(results, fmt.Sprintf("%s-source-%s-source-timestamp", prefixParamsResultsVolumes, name)) + + if strings.TrimSpace(imageDigest) != "" || + strings.TrimSpace(imageTimestamp) != "" || + strings.TrimSpace(sourceTimestamp) != "" { - if strings.TrimSpace(imageDigest) != "" { buildRun.Status.Sources = append(buildRun.Status.Sources, build.SourceResult{ Name: name, Bundle: &build.BundleSourceResult{ - Digest: imageDigest, + Digest: imageDigest, + ImageTimestamp: imageTimestamp, + SourceTimestamp: sourceTimestamp, }, }) } diff --git a/pkg/reconciler/buildrun/resources/sources/git.go b/pkg/reconciler/buildrun/resources/sources/git.go index 640e2c7af2..ad03cfcb37 100644 --- a/pkg/reconciler/buildrun/resources/sources/git.go +++ b/pkg/reconciler/buildrun/resources/sources/git.go @@ -15,9 +15,10 @@ import ( ) const ( - commitSHAResult = "commit-sha" - commitAuthorResult = "commit-author" - branchName = "branch-name" + commitSHAResult = "commit-sha" + commitAuthorResult = "commit-author" + commitTimestampResult = "commit-timestamp" + branchName = "branch-name" ) // AppendGitStep appends the Git step and results and volume if needed to the TaskSpec @@ -28,16 +29,24 @@ func AppendGitStep( name string, ) { // append the result - taskSpec.Results = append(taskSpec.Results, pipelineapi.TaskResult{ - Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitSHAResult), - Description: "The commit SHA of the cloned source.", - }, pipelineapi.TaskResult{ - Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitAuthorResult), - Description: "The author of the last commit of the cloned source.", - }, pipelineapi.TaskResult{ - Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, branchName), - Description: "The name of the branch used of the cloned source.", - }) + taskSpec.Results = append(taskSpec.Results, + pipelineapi.TaskResult{ + Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitSHAResult), + Description: "The commit SHA of the cloned source.", + }, + pipelineapi.TaskResult{ + Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitAuthorResult), + Description: "The author of the last commit of the cloned source.", + }, + pipelineapi.TaskResult{ + Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitTimestampResult), + Description: "The commit timestamp of the last commit of the cloned source.", + }, + pipelineapi.TaskResult{ + Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, branchName), + Description: "The name of the branch used of the cloned source.", + }, + ) // initialize the step from the template and the build-specific arguments gitStep := pipelineapi.Step{ @@ -46,20 +55,14 @@ func AppendGitStep( ImagePullPolicy: cfg.GitContainerTemplate.ImagePullPolicy, Command: cfg.GitContainerTemplate.Command, Args: []string{ - "--url", - *source.URL, - "--target", - fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), - "--result-file-commit-sha", - fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitSHAResult), - "--result-file-commit-author", - fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitAuthorResult), - "--result-file-branch-name", - fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, branchName), - "--result-file-error-message", - fmt.Sprintf("$(results.%s-error-message.path)", prefixParamsResultsVolumes), - "--result-file-error-reason", - fmt.Sprintf("$(results.%s-error-reason.path)", prefixParamsResultsVolumes), + "--url", *source.URL, + "--target", fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), + "--result-file-commit-sha", fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitSHAResult), + "--result-file-commit-author", fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitAuthorResult), + "--result-file-commit-timestamp", fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitTimestampResult), + "--result-file-branch-name", fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, branchName), + "--result-file-error-message", fmt.Sprintf("$(results.%s-error-message.path)", prefixParamsResultsVolumes), + "--result-file-error-reason", fmt.Sprintf("$(results.%s-error-reason.path)", prefixParamsResultsVolumes), }, Env: cfg.GitContainerTemplate.Env, ComputeResources: cfg.GitContainerTemplate.Resources, @@ -111,15 +114,17 @@ func AppendGitStep( func AppendGitResult(buildRun *buildv1alpha1.BuildRun, name string, results []pipelineapi.TaskRunResult) { commitAuthor := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitAuthorResult)) commitSha := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitSHAResult)) + commitTimestamp := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitTimestampResult)) branchName := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, branchName)) - if strings.TrimSpace(commitAuthor) != "" || strings.TrimSpace(commitSha) != "" || strings.TrimSpace(branchName) != "" { + if strings.TrimSpace(commitAuthor) != "" || strings.TrimSpace(commitSha) != "" || strings.TrimSpace(branchName) != "" || strings.TrimSpace(commitTimestamp) != "" { buildRun.Status.Sources = append(buildRun.Status.Sources, buildv1alpha1.SourceResult{ Name: name, Git: &buildv1alpha1.GitSourceResult{ - CommitAuthor: commitAuthor, - CommitSha: commitSha, - BranchName: branchName, + CommitAuthor: commitAuthor, + CommitSha: commitSha, + CommitTimestamp: commitTimestamp, + BranchName: branchName, }, }) } diff --git a/pkg/reconciler/buildrun/resources/sources/git_test.go b/pkg/reconciler/buildrun/resources/sources/git_test.go index 2f97e64b57..acf970742a 100644 --- a/pkg/reconciler/buildrun/resources/sources/git_test.go +++ b/pkg/reconciler/buildrun/resources/sources/git_test.go @@ -36,10 +36,11 @@ var _ = Describe("Git", func() { }) It("adds results for the commit sha, commit author and branch name", func() { - Expect(len(taskSpec.Results)).To(Equal(3)) + Expect(len(taskSpec.Results)).To(Equal(4)) Expect(taskSpec.Results[0].Name).To(Equal("shp-source-default-commit-sha")) Expect(taskSpec.Results[1].Name).To(Equal("shp-source-default-commit-author")) - Expect(taskSpec.Results[2].Name).To(Equal("shp-source-default-branch-name")) + Expect(taskSpec.Results[2].Name).To(Equal("shp-source-default-commit-timestamp")) + Expect(taskSpec.Results[3].Name).To(Equal("shp-source-default-branch-name")) }) It("adds a step", func() { @@ -47,20 +48,14 @@ var _ = Describe("Git", func() { Expect(taskSpec.Steps[0].Name).To(Equal("source-default")) Expect(taskSpec.Steps[0].Image).To(Equal(cfg.GitContainerTemplate.Image)) Expect(taskSpec.Steps[0].Args).To(Equal([]string{ - "--url", - "https://github.com/shipwright-io/build", - "--target", - "$(params.shp-source-root)", - "--result-file-commit-sha", - "$(results.shp-source-default-commit-sha.path)", - "--result-file-commit-author", - "$(results.shp-source-default-commit-author.path)", - "--result-file-branch-name", - "$(results.shp-source-default-branch-name.path)", - "--result-file-error-message", - "$(results.shp-error-message.path)", - "--result-file-error-reason", - "$(results.shp-error-reason.path)", + "--url", "https://github.com/shipwright-io/build", + "--target", "$(params.shp-source-root)", + "--result-file-commit-sha", "$(results.shp-source-default-commit-sha.path)", + "--result-file-commit-author", "$(results.shp-source-default-commit-author.path)", + "--result-file-commit-timestamp", "$(results.shp-source-default-commit-timestamp.path)", + "--result-file-branch-name", "$(results.shp-source-default-branch-name.path)", + "--result-file-error-message", "$(results.shp-error-message.path)", + "--result-file-error-reason", "$(results.shp-error-reason.path)", })) }) }) @@ -83,10 +78,11 @@ var _ = Describe("Git", func() { }) It("adds results for the commit sha, commit author and branch name", func() { - Expect(len(taskSpec.Results)).To(Equal(3)) + Expect(len(taskSpec.Results)).To(Equal(4)) Expect(taskSpec.Results[0].Name).To(Equal("shp-source-default-commit-sha")) Expect(taskSpec.Results[1].Name).To(Equal("shp-source-default-commit-author")) - Expect(taskSpec.Results[2].Name).To(Equal("shp-source-default-branch-name")) + Expect(taskSpec.Results[2].Name).To(Equal("shp-source-default-commit-timestamp")) + Expect(taskSpec.Results[3].Name).To(Equal("shp-source-default-branch-name")) }) It("adds a volume for the secret", func() { @@ -101,22 +97,15 @@ var _ = Describe("Git", func() { Expect(taskSpec.Steps[0].Name).To(Equal("source-default")) Expect(taskSpec.Steps[0].Image).To(Equal(cfg.GitContainerTemplate.Image)) Expect(taskSpec.Steps[0].Args).To(Equal([]string{ - "--url", - "git@github.com:shipwright-io/build.git", - "--target", - "$(params.shp-source-root)", - "--result-file-commit-sha", - "$(results.shp-source-default-commit-sha.path)", - "--result-file-commit-author", - "$(results.shp-source-default-commit-author.path)", - "--result-file-branch-name", - "$(results.shp-source-default-branch-name.path)", - "--result-file-error-message", - "$(results.shp-error-message.path)", - "--result-file-error-reason", - "$(results.shp-error-reason.path)", - "--secret-path", - "/workspace/shp-source-secret", + "--url", "git@github.com:shipwright-io/build.git", + "--target", "$(params.shp-source-root)", + "--result-file-commit-sha", "$(results.shp-source-default-commit-sha.path)", + "--result-file-commit-author", "$(results.shp-source-default-commit-author.path)", + "--result-file-commit-timestamp", "$(results.shp-source-default-commit-timestamp.path)", + "--result-file-branch-name", "$(results.shp-source-default-branch-name.path)", + "--result-file-error-message", "$(results.shp-error-message.path)", + "--result-file-error-reason", "$(results.shp-error-reason.path)", + "--secret-path", "/workspace/shp-source-secret", })) Expect(len(taskSpec.Steps[0].VolumeMounts)).To(Equal(1)) Expect(taskSpec.Steps[0].VolumeMounts[0].Name).To(Equal("shp-a-secret")) diff --git a/pkg/reconciler/buildrun/resources/taskrun_test.go b/pkg/reconciler/buildrun/resources/taskrun_test.go index 3a4f21a5fd..dab4e959e3 100644 --- a/pkg/reconciler/buildrun/resources/taskrun_test.go +++ b/pkg/reconciler/buildrun/resources/taskrun_test.go @@ -84,20 +84,14 @@ var _ = Describe("GenerateTaskrun", func() { Expect(got.Steps[0].Name).To(Equal("source-default")) Expect(got.Steps[0].Command[0]).To(Equal("/ko-app/git")) Expect(got.Steps[0].Args).To(Equal([]string{ - "--url", - *build.Spec.Source.URL, - "--target", - "$(params.shp-source-root)", - "--result-file-commit-sha", - "$(results.shp-source-default-commit-sha.path)", - "--result-file-commit-author", - "$(results.shp-source-default-commit-author.path)", - "--result-file-branch-name", - "$(results.shp-source-default-branch-name.path)", - "--result-file-error-message", - "$(results.shp-error-message.path)", - "--result-file-error-reason", - "$(results.shp-error-reason.path)", + "--url", *build.Spec.Source.URL, + "--target", "$(params.shp-source-root)", + "--result-file-commit-sha", "$(results.shp-source-default-commit-sha.path)", + "--result-file-commit-author", "$(results.shp-source-default-commit-author.path)", + "--result-file-commit-timestamp", "$(results.shp-source-default-commit-timestamp.path)", + "--result-file-branch-name", "$(results.shp-source-default-branch-name.path)", + "--result-file-error-message", "$(results.shp-error-message.path)", + "--result-file-error-reason", "$(results.shp-error-reason.path)", })) }) diff --git a/test/integration/build_to_buildruns_test.go b/test/integration/build_to_buildruns_test.go index ccae8c58a2..104441f8f8 100644 --- a/test/integration/build_to_buildruns_test.go +++ b/test/integration/build_to_buildruns_test.go @@ -39,6 +39,7 @@ var _ = Describe("Integration tests Build and BuildRuns", func() { Expect(err).To(BeNil()) }) + // Delete the ClusterBuildStrategies after each test case AfterEach(func() { diff --git a/test/integration/build_to_git_test.go b/test/integration/build_to_git_test.go index 0f0cefdc80..71add4753b 100644 --- a/test/integration/build_to_git_test.go +++ b/test/integration/build_to_git_test.go @@ -7,10 +7,12 @@ package integration_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - test "github.com/shipwright-io/build/test/v1alpha1_samples" + corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" + + "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + test "github.com/shipwright-io/build/test/v1alpha1_samples" ) var _ = Describe("Integration tests Build and referenced Source url", func() { diff --git a/test/integration/build_to_taskruns_test.go b/test/integration/build_to_taskruns_test.go index 6766cfcd3b..2279500594 100644 --- a/test/integration/build_to_taskruns_test.go +++ b/test/integration/build_to_taskruns_test.go @@ -31,6 +31,7 @@ var _ = Describe("Integration tests Build and TaskRun", func() { err = tb.CreateClusterBuildStrategy(cbsObject) Expect(err).To(BeNil()) }) + // Delete the ClusterBuildStrategies after each test case AfterEach(func() { _, err = tb.GetBuild(buildObject.Name) diff --git a/test/integration/buildrun_status_test.go b/test/integration/buildrun_status_test.go new file mode 100644 index 0000000000..6612fd7bed --- /dev/null +++ b/test/integration/buildrun_status_test.go @@ -0,0 +1,96 @@ +// Copyright The Shipwright Contributors +// +// SPDX-License-Identifier: Apache-2.0 + +package integration_test + +import ( + "fmt" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/rand" + "k8s.io/utils/pointer" +) + +var _ = Describe("Checking BuildRun Status fields", func() { + Context("Verifying BuildRun status source results", func() { + var ( + strategyName string + buildRunName string + ) + + BeforeEach(func() { + id := rand.String(5) + strategyName = fmt.Sprintf("cbs-%s", id) + buildRunName = fmt.Sprintf("buildrun-%s", id) + }) + + AfterEach(func() { + tb.DeleteBR(buildRunName) + tb.DeleteClusterBuildStrategy(strategyName) + }) + + It("should have the correct commit timestamp for Git sources", func() { + // Use an empty strategy to only have the source step + strategy := tb.Catalog.ClusterBuildStrategy(strategyName) + Expect(tb.CreateClusterBuildStrategy(strategy)).To(Succeed()) + + // Setup BuildRun with fixed revision where we know the commit details + Expect(tb.CreateBR(&v1alpha1.BuildRun{ + ObjectMeta: metav1.ObjectMeta{Name: buildRunName}, + Spec: v1alpha1.BuildRunSpec{ + BuildSpec: &v1alpha1.BuildSpec{ + Strategy: v1alpha1.Strategy{Kind: (*v1alpha1.BuildStrategyKind)(&strategy.Kind), Name: strategy.Name}, + Source: v1alpha1.Source{ + URL: pointer.String("https://github.com/shipwright-io/sample-go"), + Revision: pointer.String("v0.1.0"), + }, + }, + }, + })).ToNot(HaveOccurred()) + + buildRun, err := tb.GetBRTillCompletion(buildRunName) + Expect(err).ToNot(HaveOccurred()) + Expect(buildRun).ToNot(BeNil()) + + Expect(buildRun.Status.Sources).ToNot(BeEmpty()) + Expect(buildRun.Status.Sources[0].Git).ToNot(BeNil()) + Expect(buildRun.Status.Sources[0].Git.CommitTimestamp).To(Equal("1619426578")) + }) + + It("should have the correct commit timestamp for Bundle sources", func() { + // Use an empty strategy to only have the source step + strategy := tb.Catalog.ClusterBuildStrategy(strategyName) + Expect(tb.CreateClusterBuildStrategy(strategy)).To(Succeed()) + + // Setup BuildRun with fixed image sha where we know the timestamp details + Expect(tb.CreateBR(&v1alpha1.BuildRun{ + ObjectMeta: metav1.ObjectMeta{Name: buildRunName}, + Spec: v1alpha1.BuildRunSpec{ + BuildSpec: &v1alpha1.BuildSpec{ + Strategy: v1alpha1.Strategy{Kind: (*v1alpha1.BuildStrategyKind)(&strategy.Kind), Name: strategy.Name}, + Source: v1alpha1.Source{ + BundleContainer: &v1alpha1.BundleContainer{ + Image: "ghcr.io/shipwright-io/sample-go/source-bundle@sha256:9a5e264c19980387b8416e0ffa7460488272fb8a6a56127c657edaa2682daab2", + }, + }, + }, + }, + })).ToNot(HaveOccurred()) + + buildRun, err := tb.GetBRTillCompletion(buildRunName) + Expect(err).ToNot(HaveOccurred()) + Expect(buildRun).ToNot(BeNil()) + + Expect(buildRun.Status.Sources).ToNot(BeEmpty()) + Expect(buildRun.Status.Sources[0].Bundle).ToNot(BeNil()) + Expect(buildRun.Status.Sources[0].Bundle.ImageTimestamp).To(Equal("1691650402")) + Expect(buildRun.Status.Sources[0].Bundle.SourceTimestamp).To(Equal("1691650396")) + }) + }) +}) diff --git a/test/v1alpha1_samples/catalog.go b/test/v1alpha1_samples/catalog.go index 15a64b0ed5..22b82f0231 100644 --- a/test/v1alpha1_samples/catalog.go +++ b/test/v1alpha1_samples/catalog.go @@ -225,6 +225,9 @@ func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName strin // ClusterBuildStrategy to support tests func (c *Catalog) ClusterBuildStrategy(name string) *build.ClusterBuildStrategy { return &build.ClusterBuildStrategy{ + TypeMeta: metav1.TypeMeta{ + Kind: string(build.ClusterBuildStrategyKind), + }, ObjectMeta: metav1.ObjectMeta{ Name: name, },