Skip to content

Commit

Permalink
feat: write a generateWorkflowStruct func
Browse files Browse the repository at this point in the history
  • Loading branch information
smorihira committed Sep 4, 2024
1 parent a064c2f commit a810929
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions hack/actions/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ type Data struct {
RunCommands []string
RunMounts []string
StageFiles []string
// TODO: 以下追加分?
ComponentName string
// TODO: 以下追加分(これでええんか?)
Name string
PushBranches []string
PushTags []string
PullRequestPaths []string
PullRequestTargetPaths []string
BuildUses string
BuildTarget string
BuildSecrets string
}

type ContainerType int
Expand Down Expand Up @@ -258,11 +265,22 @@ var (
)

func generateWorkflowStruct(data Data) Workflow {
return Workflow{}
var workflow Workflow

workflow.Name = data.Name
workflow.On.Push.Branches = data.PushBranches
workflow.On.Push.Tags = data.PushTags
workflow.On.PullRequest.Paths = data.PullRequestPaths
workflow.On.PullRequestTarget.Paths = data.PullRequestTargetPaths
workflow.Jobs.Build.Uses = data.BuildUses
workflow.Jobs.Build.With.Target = data.BuildTarget
workflow.Jobs.Build.Secrets = data.BuildSecrets

return workflow
}

func main() {
// この辺の処理は共通?
// TODO: この辺の処理は共通?
log.Init()
if len(os.Args) < minimumArgumentLength {
// skipcq: RVV-A0003
Expand All @@ -276,7 +294,7 @@ func main() {
syscall.SIGKILL,
syscall.SIGTERM)
defer cancel()
log.Debug(tmpl) // workflow型を表示?ここどうしよう?
log.Debug(tmpl) // TODO: workflow型を表示?ここどうしよう?

maintainer := os.Getenv(maintainerKey)
if maintainer == "" {
Expand Down Expand Up @@ -326,7 +344,7 @@ func main() {

// TODO: ContainerTypeごとの処理 (workflow生成でも重要そう)

// ↑ここまでdataの処理 (workflowの生成でもほとんど共通?)
// ↑ここまでdataの処理 (TODO: workflowの生成でもほとんど共通?)

// ↓ここからファイルの生成
log.Infof("Generating %s's workflow", name)
Expand All @@ -336,7 +354,7 @@ func main() {
log.Fatalf("error marshaling workflowStruct to YAML: %v", err)
}

// ここの書き方あってる??
// TODO: ここの書き方あってる??
buf := bytes.NewBuffer(make([]byte, 0, len(workflowYaml)))
buf.Write(workflowYaml)
file.OverWriteFile(egctx, file.Join(os.Args[1], ".github/workflows", "TODO: ファイル名"), buf, fs.ModePerm)
Expand Down

0 comments on commit a810929

Please sign in to comment.