Skip to content

Commit

Permalink
fix: add cron to workflow struct
Browse files Browse the repository at this point in the history
  • Loading branch information
smorihira committed Sep 4, 2024
1 parent 9cade3d commit 5bc73a5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion hack/actions/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
type Workflow struct {
Name string `yaml:"name"`
On struct {
Schedule struct {
Cron string `yaml:"cron"`
} `yaml:"schedule"`
Push struct {
Branches []string `yaml:"branches"`
Tags []string `yaml:"tags"`
Expand Down Expand Up @@ -72,6 +75,7 @@ type Data struct {
StageFiles []string
// TODO: 以下追加分(これでええんか?)
Name string
Cron string
PushBranches []string
PushTags []string
PullRequestPaths []string
Expand Down Expand Up @@ -278,11 +282,22 @@ func generateWorkflowStruct(data *Data) Workflow {
workflow.Jobs.Build.With.Platforms = data.BuildPlatforms
workflow.Jobs.Build.Secrets = data.BuildSecrets

if data.Cron != "" {
workflow.On.Schedule.Cron = data.Cron
}

return workflow
}

func sortedPullRequestPaths(data *Data) []string { // TODO: ContainerTypeごとなどいろいろ条件分岐
// イメージをビルドする全ワークフローに共通のパス
var pullRequestPaths = []string{"hack/docker/gen/main.go", "hack/actions/gen/main.go", ".github/actions/docker-build/action.yaml", ".github/workflows/_docker-image.yaml"}
// TODO: 残りの処理
return pullRequestPaths
}

func initializeData(data *Data) {
pullRequestPaths := make([]string, 0) // TODO: ContainerTypeごとなどいろいろ条件分岐
pullRequestPaths := sortedPullRequestPaths(data)

data.PushBranches = []string{"main", "release/v*.*", "!release/v*.*.*"}
data.PushTags = []string{"*.*.*", "v*.*.*", "*.*.*-*", "v*.*.*-*"}
Expand All @@ -292,6 +307,10 @@ func initializeData(data *Data) {
data.BuildTarget = data.Name
data.BuildPlatforms = "linux/amd64,linux/arm64" // TODO: ここも分岐必要??
data.BuildSecrets = "inherit"

if data.AliasImage {
data.Cron = ""
}
}

func main() {
Expand Down

0 comments on commit 5bc73a5

Please sign in to comment.