diff --git a/cmd/image-builder/config.go b/cmd/image-builder/config.go index ee67c1ffb8f1..cc55726f525c 100644 --- a/cmd/image-builder/config.go +++ b/cmd/image-builder/config.go @@ -173,7 +173,7 @@ func loadADOGitState() (GitStateConfig, error) { if !present { return GitStateConfig{}, fmt.Errorf("JOB_TYPE environment variable is not set, please set it to valid job type") } - if !slices.Contains([]string{"presubmit", "postsubmit"}, jobType) { + if !slices.Contains(adoPipelines.GetValidJobTypes(), jobType) { return GitStateConfig{}, fmt.Errorf("image builder is running for unsupported event %s", jobType) } @@ -266,7 +266,7 @@ func loadGithubActionsGitState() (GitStateConfig, error) { return GitStateConfig{ RepositoryName: *payload.Repo.Name, RepositoryOwner: *payload.Repo.Owner.Login, - JobType: "on-demand", + JobType: "workflow_dispatch", BaseCommitSHA: os.Getenv("GITHUB_SHA"), BaseCommitRef: os.Getenv("GITHUB_REF"), }, nil diff --git a/cmd/image-builder/config_test.go b/cmd/image-builder/config_test.go index 00e062d78538..4abdb9ec5fb4 100644 --- a/cmd/image-builder/config_test.go +++ b/cmd/image-builder/config_test.go @@ -260,7 +260,7 @@ func TestLoadGitStateConfig(t *testing.T) { gitState: GitStateConfig{ RepositoryName: "test-infra", RepositoryOwner: "KacperMalachowski", - JobType: "on-demand", + JobType: "workflow_dispatch", BaseCommitSHA: "d42f5051757b3e0699eb979d7581404e36fc0eee", BaseCommitRef: "refs/heads/main", isPullRequest: false, diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index a3f21133c9c6..8d9fd4b0fee5 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -201,8 +201,8 @@ func prepareADOTemplateParameters(options options) (adopipelines.OCIImageBuilder templateParameters.SetPresubmitJobType() } else if options.gitState.JobType == "postsubmit" { templateParameters.SetPostsubmitJobType() - } else if options.gitState.JobType == "on-demand" { - templateParameters.SetOnDemandJobType() + } else if options.gitState.JobType == "workflow_dispatch" { + templateParameters.SetWorkflowDispatchJobType() } if options.gitState.IsPullRequest() { diff --git a/cmd/image-builder/main_test.go b/cmd/image-builder/main_test.go index 02724c37e4dd..b215e5ee4599 100644 --- a/cmd/image-builder/main_test.go +++ b/cmd/image-builder/main_test.go @@ -654,7 +654,7 @@ func Test_prepareADOTemplateParameters(t *testing.T) { name: "On demand job type with base commit SHA and base commit ref", options: options{ gitState: GitStateConfig{ - JobType: "on-demand", + JobType: "workflow_dispatch", BaseCommitSHA: "abc123", BaseCommitRef: "main", }, @@ -666,7 +666,7 @@ func Test_prepareADOTemplateParameters(t *testing.T) { "Context": "", "Dockerfile": "", "ExportTags": "false", - "JobType": "on-demand", + "JobType": "workflow_dispatch", "Name": "", "PullBaseSHA": "abc123", "BaseRef": "main", diff --git a/pkg/azuredevops/pipelines/templatesParams.go b/pkg/azuredevops/pipelines/templatesParams.go index fdd2cd55a2a9..79cc11d76ebc 100644 --- a/pkg/azuredevops/pipelines/templatesParams.go +++ b/pkg/azuredevops/pipelines/templatesParams.go @@ -5,9 +5,16 @@ package pipelines import ( "encoding/base64" "fmt" + "slices" "strconv" ) +var validJobTypes = []string{"presubmit", "postsubmit", "workflow_dispatch"} + +func GetValidJobTypes() []string { + return validJobTypes +} + // ErrRequiredParamNotSet is returned when the required template parameter is not set type ErrRequiredParamNotSet string @@ -42,9 +49,9 @@ func (p OCIImageBuilderTemplateParams) SetPostsubmitJobType() { p["JobType"] = "postsubmit" } -// SetOnDemandJobType sets required parameter JobType to on-demand. -func (p OCIImageBuilderTemplateParams) SetOnDemandJobType() { - p["JobType"] = "on-demand" +// SetWorkflowDispatchJobType sets required parameter JobType to workflow_dispatch. +func (p OCIImageBuilderTemplateParams) SetWorkflowDispatchJobType() { + p["JobType"] = "workflow_dispatch" } // SetPullNumber sets optional parameter PullNumber. @@ -149,8 +156,8 @@ func (p OCIImageBuilderTemplateParams) Validate() error { if jobType, ok = p["JobType"]; !ok { return ErrRequiredParamNotSet("JobType") } - if jobType != "presubmit" && jobType != "postsubmit" && jobType != "on-demand" { - return fmt.Errorf("JobType must be either presubmit, postsubmit or on-demand, got: %s", jobType) + if !slices.Contains(validJobTypes, jobType) { + return fmt.Errorf("JobType must be either presubmit, postsubmit or workflow_dispatch, got: %s", jobType) } if _, ok = p["PullBaseSHA"]; !ok { return ErrRequiredParamNotSet("BaseSHA") diff --git a/pkg/azuredevops/pipelines/templatesParams_test.go b/pkg/azuredevops/pipelines/templatesParams_test.go index 8c8092da4dbc..01a11618c4e5 100644 --- a/pkg/azuredevops/pipelines/templatesParams_test.go +++ b/pkg/azuredevops/pipelines/templatesParams_test.go @@ -36,9 +36,9 @@ var _ = Describe("Test OCIImageBuilderTemplateParams", func() { Expect(params["JobType"]).To(Equal("postsubmit")) }) - It("sets the correct JobType to on-demand", func() { - params.SetOnDemandJobType() - Expect(params["JobType"]).To(Equal("on-demand")) + It("sets the correct JobType to workflow_dispatch", func() { + params.SetWorkflowDispatchJobType() + Expect(params["JobType"]).To(Equal("workflow_dispatch")) }) It("sets the correct PullNumber", func() { @@ -117,7 +117,7 @@ var _ = Describe("Test OCIImageBuilderTemplateParams", func() { Expect(err).NotTo(BeNil()) }) - It("returns error if JobType is not presubmit or postsubmit or on-demand", func() { + It("returns error if JobType is not presubmit or postsubmit or workflow_dispatch", func() { params["JobType"] = "otherType" err := params.Validate()