Skip to content

Commit

Permalink
feat: add build platform choice logic to initializeData
Browse files Browse the repository at this point in the history
  • Loading branch information
smorihira committed Sep 4, 2024
1 parent 4818731 commit db8d4bc
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions hack/actions/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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() {
Expand Down

0 comments on commit db8d4bc

Please sign in to comment.