From db8d4bc97ee24eff434ac3c40f8822857dd0b96b Mon Sep 17 00:00:00 2001 From: smorihira Date: Wed, 4 Sep 2024 18:31:55 +0900 Subject: [PATCH] feat: add build platform choice logic to initializeData --- hack/actions/gen/main.go | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/hack/actions/gen/main.go b/hack/actions/gen/main.go index 7068af82967..8a60ef75f9e 100644 --- a/hack/actions/gen/main.go +++ b/hack/actions/gen/main.go @@ -291,11 +291,40 @@ func generateWorkflowStruct(data *Data) Workflow { func sortedPullRequestPaths(data *Data) []string { // TODO: ContainerTypeごとなどいろいろ条件分岐 // イメージをビルドする全ワークフローに共通のパス - pullRequestPaths := []string{"hack/docker/gen/main.go", "hack/actions/gen/main.go", ".github/actions/docker-build/action.yaml", ".github/workflows/_docker-image.yaml"} - // TODO: 残りの処理 + pullRequestPaths := []string{ + "hack/docker/gen/main.go", + "hack/actions/gen/main.go", + ".github/actions/docker-build/action.yaml", + ".github/workflows/_docker-image.yaml", + } + return pullRequestPaths } +func buildPlatforms(name string) (string, bool) { + baseImages := map[string]struct{}{ + "binfmt": {}, + "buildbase": {}, + "buildkit": {}, + "buildkit-syft-scanner": {}, + } + + amdOnlyImages := map[string]struct{}{ + "ci-container": {}, + "dev-container": {}, + "loadtest": {}, + } + + if _, ok := baseImages[name]; ok { + return "linux/amd64,linux/arm64", true + } + if _, ok := amdOnlyImages[name]; ok { + return "linux/amd64", true + } + + return "", false +} + func initializeData(data *Data) { pullRequestPaths := sortedPullRequestPaths(data) @@ -305,12 +334,14 @@ func initializeData(data *Data) { data.PullRequestTargetPaths = pullRequestPaths data.BuildUses = "./.github/workflows/_docker-image.yaml" data.BuildTarget = data.Name - data.BuildPlatforms = "linux/amd64,linux/arm64" // TODO: ここも分岐必要?? data.BuildSecrets = "inherit" if data.AliasImage { data.Cron = "" } + if buildPlatforms, ok := buildPlatforms(data.Name); ok { + data.BuildPlatforms = buildPlatforms + } } func main() {