Skip to content

Commit

Permalink
fix: modify pullRequestPaths func and etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
smorihira committed Sep 5, 2024
1 parent 069c463 commit 05aea61
Showing 1 changed file with 90 additions and 59 deletions.
149 changes: 90 additions & 59 deletions hack/actions/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,33 @@ type Workflow struct {
}

type Data struct {
AliasImage bool
ConfigExists bool
Year int
ContainerType ContainerType
AppName string
BinDir string
BuildUser string
BuilderImage string
BuilderTag string
BuildStageName string
Maintainer string
PackageDir string
RootDir string
RuntimeImage string
RuntimeTag string
RuntimeUser string
Arguments map[string]string
Environments map[string]string
Entrypoints []string
EnvironmentsSlice []string
ExtraCopies []string
ExtraImages []string
ExtraPackages []string
Preprocess []string
RunCommands []string
RunMounts []string
StageFiles []string
// TODO: 以下追加分(これでええんか?)
AliasImage bool
ConfigExists bool
Year int
ContainerType ContainerType
AppName string
BinDir string
BuildUser string
BuilderImage string
BuilderTag string
BuildStageName string
Maintainer string
PackageDir string
RootDir string
RuntimeImage string
RuntimeTag string
RuntimeUser string
Arguments map[string]string
Environments map[string]string
Entrypoints []string
EnvironmentsSlice []string
ExtraCopies []string
ExtraImages []string
ExtraPackages []string
Preprocess []string
RunCommands []string
RunMounts []string
StageFiles []string
Name string
Cron string
PushBranches []string
Expand All @@ -136,7 +135,6 @@ const (
Other
)

// TODO: 必要な定数はここに追加
const (
organization = "vdaas"
repository = "vald"
Expand Down Expand Up @@ -171,7 +169,6 @@ func (c ContainerType) String() string {
return containerTypeName[c]
}

// TODO: 必要な変数はここに追加
var (
containerTypeName = map[ContainerType]string{
Go: "Go",
Expand Down Expand Up @@ -331,7 +328,18 @@ func generateWorkflowStruct(data *Data) Workflow {
}

func appendComponentsPaths(paths []string, data *Data) []string {
paths = append(paths, "cmd/"+data.PackageDir+"/**", "pkg/"+data.PackageDir+"/**")
if strings.Split(data.Name, "-")[0] != "benchmark" {
paths = append(paths, "cmd/"+data.PackageDir+"/**", "pkg/"+data.PackageDir+"/**")
} else {
// note: this is an exception
// the benchmark components trigger each other, not just themselves
paths = append(paths,
"cmd/tools/benchmark/jobs/**",
"pkd/tools/benchmark/jobs/**",
"cmd/tools/benchmark/operators/**",
"pkg/tools/benchmark/operators/**",
)
}

// append components' internals
if data.Name == "agent-faiss" || data.Name == "agent-ngt" {
Expand All @@ -354,6 +362,18 @@ func appendContainerTypeDependingPaths(paths []string, data *Data) []string {
paths = append(paths, "apis/grpc/**")
}

if ct == HelmOperator {
paths = append(paths,
"charts/vald/Chart.yaml",
"charts/vald/values.yaml",
"charts/vald/templates/**",
"charts/vald-helm-operator/Chart.yaml",
"charts/vald-helm-operator/values.yaml",
"charts/vald-helm-operator/templates/**",
"versions/OPERATOR_SDK_VERSION",
)
}

if ct == Go {
paths = append(paths,
"go.mod",
Expand All @@ -362,8 +382,13 @@ func appendContainerTypeDependingPaths(paths []string, data *Data) []string {
"internal/**",
"!internal/**/*_test.go",
"!internal/db/**",
"!internal/k8s/**",
"!internal/**/*_mock.go",
)

switch data.Name { // note: this is an exception
case "discovorer-k8s", "index-operator", "gateway-mirror", "readreplica-rotate", "agent-ngt", "benchmark-job", "benchmark-operator":
paths = append(paths, "!internal/k8s/**")
}
}

if ct == Rust {
Expand Down Expand Up @@ -391,12 +416,8 @@ func appendContainerTypeDependingPaths(paths []string, data *Data) []string {
func pullRequestPaths(data *Data) []string {
pullRequestPaths := []string{
// common paths in every image-building workflow
"hack/docker/gen/main.go",
"dockers/" + data.PackageDir + "/Dockerfile",
"hack/actions/gen/main.go",
".github/workflows/dockers-" + data.Name + "-image.yml",
".github/actions/docker-build/action.yaml",
".github/workflows/_docker-image.yaml",
}

if !data.AliasImage {
Expand All @@ -406,46 +427,57 @@ func pullRequestPaths(data *Data) []string {
pullRequestPaths = appendComponentsPaths(pullRequestPaths, data)
pullRequestPaths = appendContainerTypeDependingPaths(pullRequestPaths, data)

return pullRequestPaths
}

func buildPlatforms(name string) (string, bool) {
baseImages := map[string]struct{}{
"binfmt": {},
"buildbase": {},
"buildkit": {},
"buildkit-syft-scanner": {},
if data.Name == "agent-sidecar" { // note: this is an exception
pullRequestPaths = append(pullRequestPaths, "internal/db/storage/blob/**")
}

amdOnlyImages := map[string]struct{}{
"ci-container": {},
"dev-container": {},
"loadtest": {},
}
return pullRequestPaths
}

if _, ok := baseImages[name]; ok {
func buildPlatforms(data *Data) (string, bool) {
if data.AliasImage {
return "linux/amd64,linux/arm64", true
}
if _, ok := amdOnlyImages[name]; ok {
if data.ContainerType == CIContainer || data.Name == "loadtest" {
return "linux/amd64", true
}

return "", false
}

const baseWorkflow = `on:
push:
branches:
- "main"
- "release/v*.*"
- "!release/v*.*.*"
tags:
- "*.*.*"
- "v*.*.*"
- "*.*.*-*"
- "v*.*.*-*"
pull_request:
paths:
- "hack/docker/gen/main.go",
- "hack/actions/gen/main.go",
- ".github/actions/docker-build/action.yaml",
- ".github/workflows/_docker-image.yaml",
jobs:
build:
uses: ./.github/workflows/_docker-image.yaml
secrets: inherit
`

func initializeData(data *Data) {
data.PushBranches = []string{"main", "release/v*.*", "!release/v*.*.*"}
data.PushTags = []string{"*.*.*", "v*.*.*", "*.*.*-*", "v*.*.*-*"}
yaml.NewDecoder(strings.NewReader(baseWorkflow)).Decode(data)
data.PullRequestPaths = pullRequestPaths(data)
data.PullRequestTargetPaths = data.PullRequestPaths
data.BuildUses = "./.github/workflows/_docker-image.yaml"
data.BuildTarget = data.Name
data.BuildSecrets = "inherit"

if data.AliasImage {
data.Cron = ""
}
if buildPlatforms, ok := buildPlatforms(data.Name); ok {
if buildPlatforms, ok := buildPlatforms(data); ok {
data.BuildPlatforms = buildPlatforms
}
}
Expand All @@ -464,7 +496,6 @@ func main() {
syscall.SIGKILL,
syscall.SIGTERM)
defer cancel()
// log.Debug(tmpl) TODO: workflow型を表示?ここどうしよう?

maintainer := os.Getenv(maintainerKey)
if maintainer == "" {
Expand Down Expand Up @@ -596,7 +627,7 @@ func main() {
},
Entrypoints: []string{"{{$.BinDir}}/{{.AppName}}", "run", "--watches-file=" + helmOperatorWatchFile},
},
"vald-cli-loadtest": { // TODO: ここだけnameの命名規則が違う??
"vald-loadtest": { // note: this name is a little different from that of docker/gen/main.go
AppName: "loadtest",
PackageDir: "tools/cli/loadtest",
ExtraPackages: append(clangBuildDeps, "libhdf5-dev", "libaec-dev"),
Expand Down

0 comments on commit 05aea61

Please sign in to comment.