Skip to content

Commit

Permalink
refactor: replace paths and components names with constants
Browse files Browse the repository at this point in the history
  • Loading branch information
smorihira committed Sep 5, 2024
1 parent 105b0ed commit a9dfcfd
Showing 1 changed file with 174 additions and 85 deletions.
259 changes: 174 additions & 85 deletions hack/actions/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,6 @@ var license string = `#

var licenseTmpl *template.Template = template.Must(template.New("license").Parse(license))

const baseWorkflowTmpl string = `name: "%s"
on:
schedule:
- cron: "0 * * * *"
push:
branches:
- "main"
- "release/v*.*"
- "!release/v*.*.*"
tags:
- "*.*.*"
- "v*.*.*"
- "*.*.*-*"
- "v*.*.*-*"
pull_request:
paths:
- "hack/docker/gen/main.go"
- "dockers/%s/Dockerfile"
- "hack/actions/gen/main.go"
- ".github/workflows/dockers-%s-images.yml"
- ".github/actions/docker-build/action.yaml"
- ".github/workflows/_docker-image.yaml"
- "cmd/%s/**"
- "pkg/%s/**"
pull_request_target:
paths: []
jobs:
build:
uses: "./.github/workflows/_docker-image.yaml"
with:
target: "%s"
platforms: ""
secrets: "inherit"
`

type (
Workflow struct {
Name string `yaml:"name"`
Expand Down Expand Up @@ -269,29 +233,154 @@ var (
}
)

const baseWorkflowTmpl string = `name: "Build docker image: %s"
on:
schedule:
- cron: "0 * * * *"
push:
branches:
- "main"
- "release/v*.*"
- "!release/v*.*.*"
tags:
- "*.*.*"
- "v*.*.*"
- "*.*.*-*"
- "v*.*.*-*"
pull_request:
paths:
- "hack/docker/gen/main.go"
- "dockers/%s/Dockerfile"
- "hack/actions/gen/main.go"
- ".github/workflows/dockers-%s-image.yml"
- ".github/actions/docker-build/action.yaml"
- ".github/workflows/_docker-image.yaml"
- "cmd/%s/**"
- "pkg/%s/**"
pull_request_target:
paths: []
jobs:
build:
uses: "./.github/workflows/_docker-image.yaml"
with:
target: "%s"
platforms: ""
secrets: "inherit"
`

const (
cmdBenchOperatorsPath = "cmd/tools/benchmark/operators/**"
pkgBenchOperatorsPath = "pkg/tools/benchmark/operators/**"
cmdBenchJobsPath = "cmd/tools/benchmark/jobs/**"
pkgBenchJobsPath = "pkg/tools/benchmark/jobs/**"

agentInternalPath = "pkg/agent/internal/**"
gatewayInternalPath = "pkg/gateway/internal/**"

apisGrpcPath = "apis/grpc/**"
apisProtoPath = "apis/proto/**"

hackPath = "hack/**"

chartsValdPath = "charts/vald"
helmOperatorPath = "charts/vald-helm-operator"
chartPath = chartsValdPath + "/Chart.yaml"
valuesPath = chartsValdPath + "/values.yaml"
templatesPath = chartsValdPath + "/templates/**"
helmOperatorChartPath = helmOperatorPath + "/Chart.yaml"
helmOperatorValuesPath = helmOperatorPath + "/values.yaml"
helmOperatorTemplatesPath = helmOperatorPath + "/templates/**"

goModPath = "go.mod"
goSumPath = "go.sum"

cargoLockPath = "rust/Cargo.lock"
cargoTomlPath = "rust/Cargo.toml"
rustBinAgentDirPath = "rust/bin/agent"
rustNgtRsPath = "rust/libs/ngt-rs/**"
rustNgtPath = "rust/libs/ngt/**"
rustProtoPath = "rust/libs/proto/**"

internalPath = "internal/**"
internalStoragePath = "internal/db/storage/blob/**"
excludeTestFilesPath = "!internal/**/*_test.go"
excludeMockFilesPath = "!internal/**/*_mock.go"
excludeDbPath = "!internal/db/**"
excludeK8sPath = "!internal/k8s/**"

versionsPath = "versions"
operatorSDKVersionPath = versionsPath + "/OPERATOR_SDK_VERSION"
goVersionPath = versionsPath + "/GO_VERSION"
rustVersionPath = versionsPath + "/RUST_VERSION"
faissVersionPath = versionsPath + "/FAISS_VERSION"
ngtVersionPath = versionsPath + "/NGT_VERSION"

makefilePath = "Makefile"
makefileDirPath = "Makefile.d/**"
)

const (
agentNgt = "agent-ngt"
agentFaiss = "agent-faiss"
agentSidecar = "agent-sidecar"
agent = "agent"

discovererK8s = "discoverer-k8s"

gateway = "gateway"
gatewayLb = "gateway-lb"
gatewayFilter = "gateway-filter"
gatewayMirror = "gateway-mirror"

managerIndex = "manager-index"

indexCorrection = "index-correction"
indexCreation = "index-creation"
indexSave = "index-save"
indexOperator = "index-operator"

readreplicaRotate = "readreplica-rotate"

benchJob = "benchmark-job"
benchOperator = "benchmark-operator"

helmOperator = "helm-operator"

loadtest = "loadtest"

ciContainer = "ci-container"
devContainer = "dev-container"

buildbase = "buildbase"
buildkit = "buildkit"
binfmt = "binfmt"
buildkitSyftScanner = "buildkit-syft-scanner"
)

func (data *Data) appendPaths(paths ...string) {
data.PullRequestPaths = append(data.PullRequestPaths, paths...)
}

func (data *Data) appendComponentsPaths() {
switch data.Name {
// the benchmark components trigger each other, not just themselves
case "benchmark-job":
case benchJob:
data.appendPaths(
"cmd/tools/benchmark/operators/**",
"pkg/tools/benchmark/operators/**",
cmdBenchOperatorsPath,
pkgBenchOperatorsPath,
)
case "benchmark-operator":
case benchOperator:
data.appendPaths(
"cmd/tools/benchmark/jobs/**",
"pkd/tools/benchmark/jobs/**",
cmdBenchJobsPath,
pkgBenchJobsPath,
)
// append components' internals
case "agent-faiss", "agent-ngt":
data.appendPaths("pkg/agent/internal/**")
case agentFaiss, agentNgt:
data.appendPaths(agentInternalPath)
default:
if strings.Contains(strings.ToLower(data.Name), "gateway") {
data.appendPaths("pkg/gateway/internal/**")
if strings.Contains(strings.ToLower(data.Name), gateway) {
data.appendPaths(gatewayInternalPath)
}
}
}
Expand All @@ -300,69 +389,69 @@ func (data *Data) appendContainerTypeDependingPaths() {
switch data.ContainerType {
case HelmOperator:
data.appendPaths(
"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",
chartPath,
valuesPath,
templatesPath,
helmOperatorChartPath,
helmOperatorValuesPath,
helmOperatorTemplatesPath,
operatorSDKVersionPath,
)
case DevContainer, CIContainer:
data.appendPaths(
"apis/grpc/**",
"apis/proto/**",
"hack/**",
apisGrpcPath,
apisProtoPath,
hackPath,
)
case Go:
data.appendPaths(
"apis/grpc/**",
"apis/proto/**",
"go.mod",
"go.sum",
"versions/GO_VERSION",
"internal/**",
"!internal/**/*_test.go",
"!internal/**/*_mock.go",
"!internal/db/**",
apisGrpcPath,
apisProtoPath,
goModPath,
goSumPath,
goVersionPath,
internalPath,
excludeTestFilesPath,
excludeMockFilesPath,
excludeDbPath,
)
switch data.Name {
case "discovorer-k8s", "index-operator", "gateway-mirror", "readreplica-rotate", "agent-ngt", "benchmark-job", "benchmark-operator":
case discovererK8s, indexOperator, gatewayMirror, readreplicaRotate, agentNgt, benchJob, benchOperator:
default:
data.appendPaths("!internal/k8s/**")
data.appendPaths(excludeK8sPath)
}
case Rust:
data.appendPaths(
"apis/grpc/**",
"apis/proto/**",
"rust/Cargo.lock",
"rust/Cargo.toml",
"rust/bin/agent/**",
"rust/libs/ngt-rs/**",
"rust/libs/ngt/**",
"rust/libs/proto/**",
"versions/RUST_VERSION",
"versions/FAISS_VERSION",
"versions/NGT_VERSION",
apisGrpcPath,
apisProtoPath,
cargoLockPath,
cargoTomlPath,
rustBinAgentDirPath,
rustNgtRsPath,
rustNgtPath,
rustProtoPath,
rustVersionPath,
faissVersionPath,
ngtVersionPath,
)
}
if strings.EqualFold(data.Name, "agent-faiss") || data.ContainerType == Rust {
data.appendPaths("versions/FAISS_VERSION")
if strings.EqualFold(data.Name, agentFaiss) || data.ContainerType == Rust {
data.appendPaths(faissVersionPath)
}
if strings.EqualFold(data.Name, "agent-ngt") || data.ContainerType == Rust {
data.appendPaths("versions/NGT_VERSION")
if strings.EqualFold(data.Name, agentNgt) || data.ContainerType == Rust {
data.appendPaths(ngtVersionPath)
}
}

func (data *Data) setPullRequestPaths() {
data.appendComponentsPaths()
data.appendContainerTypeDependingPaths()

if data.Name == "agent-sidecar" {
data.appendPaths("internal/db/storage/blob/**")
if data.Name == agentSidecar {
data.appendPaths(internalStoragePath)
}
if !data.AliasImage {
data.appendPaths("Makefile", "Makefile.d/**")
data.appendPaths(makefilePath, makefileDirPath)
}
}

Expand Down

0 comments on commit a9dfcfd

Please sign in to comment.