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

Add support for merge group in image-builder #12361

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion cmd/image-builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -343,4 +358,4 @@ func determineUsedCISystem(envGetter func(key string) string, envLookup func(key
}

return "", fmt.Errorf("cannot determine ci system: unknown system")
}
}
2 changes: 2 additions & 0 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/azuredevops/pipelines/templatesParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"] = "schedule"
KacperMalachowski marked this conversation as resolved.
Show resolved Hide resolved
}

// SetPullNumber sets optional parameter PullNumber.
func (p OCIImageBuilderTemplateParams) SetPullNumber(number string) {
p["PullNumber"] = number
Expand Down
Loading