diff --git a/cmd/image-builder/config.go b/cmd/image-builder/config.go index 98d85be5debf..0354051a4c13 100644 --- a/cmd/image-builder/config.go +++ b/cmd/image-builder/config.go @@ -305,6 +305,21 @@ func loadGithubActionsGitState() (GitStateConfig, error) { BaseCommitRef: gitRef, }, nil + case "merge_group": + var payload github.MergeGroupEvent + err = json.Unmarshal(data, &payload) + if err != nil { + return GitStateConfig{}, fmt.Errorf("failed to parse event payload: %s", err) + } + return GitStateConfig{ + RepositoryName: *payload.Repo.Name, + RepositoryOwner: *payload.Repo.Owner.Login, + JobType: "merge_group", + BaseCommitSHA: commitSHA, + BaseCommitRef: gitRef, + PullHeadCommitSHA: *payload.MergeGroup.HeadSHA, + }, nil + default: return GitStateConfig{}, fmt.Errorf("GITHUB_EVENT_NAME environment variable is set to unsupported value \"%s\", please set it to supported value", eventName) } @@ -343,4 +358,4 @@ func determineUsedCISystem(envGetter func(key string) string, envLookup func(key } return "", fmt.Errorf("cannot determine ci system: unknown system") -} \ No newline at end of file +} diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index 6b05222afb50..ec32942d106c 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -215,6 +215,8 @@ func prepareADOTemplateParameters(options options) (adopipelines.OCIImageBuilder templateParameters.SetWorkflowDispatchJobType() case "schedule": templateParameters.SetScheduleJobType() + case "merge_group": + templateParameters.SetMergeGroupJobType() default: return nil, fmt.Errorf("unknown JobType received, ensure image-builder runs on supported event") } diff --git a/pkg/azuredevops/pipelines/templatesParams.go b/pkg/azuredevops/pipelines/templatesParams.go index 9f9d0cb37e51..6ab0e209915e 100644 --- a/pkg/azuredevops/pipelines/templatesParams.go +++ b/pkg/azuredevops/pipelines/templatesParams.go @@ -9,7 +9,7 @@ import ( "strconv" ) -var validJobTypes = []string{"presubmit", "postsubmit", "workflow_dispatch", "schedule"} +var validJobTypes = []string{"presubmit", "postsubmit", "workflow_dispatch", "schedule", "merge_group"} func GetValidJobTypes() []string { return validJobTypes @@ -59,6 +59,11 @@ func (p OCIImageBuilderTemplateParams) SetScheduleJobType() { p["JobType"] = "schedule" } +// SetMergeGroup sets required parameter JobType to merge_group. +func (p OCIImageBuilderTemplateParams) SetMergeGroupJobType() { + p["JobType"] = "merge_group" +} + // SetPullNumber sets optional parameter PullNumber. func (p OCIImageBuilderTemplateParams) SetPullNumber(number string) { p["PullNumber"] = number