Skip to content

Commit

Permalink
internal/ci: specify go versions to use on generated workflow files (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
masseelch authored Sep 26, 2023
1 parent 6d194a8 commit fa3f99b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-go_oss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.20', '1.21' ]
go: [ "1.20", "1.21" ]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v4
Expand Down
2 changes: 1 addition & 1 deletion internal/ci/ci_go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
runs-on: {{ $.Runner }}
strategy:
matrix:
go: [ '1.20', '1.21' ]
go: {{ with $.GoVersions }}{{ . }}{{ end }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v4
Expand Down
3 changes: 2 additions & 1 deletion internal/ci/jobs_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ package main
//go:generate go run . -flavor Community -suffix oss

func init() {
jobs = append(jobs,
data.GoVersions = goVersions{"1.20", "1.21"}
data.Jobs = append(jobs,
Job{
Version: "tidb5",
Image: "pingcap/tidb:v5.4.0",
Expand Down
30 changes: 22 additions & 8 deletions internal/ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"log"
"os"
"path/filepath"
"strconv"
"strings"
"text/template"
)

Expand Down Expand Up @@ -164,19 +166,24 @@ var (
}
)

type goVersions []string

var data struct {
Jobs []Job
Flavor, Tags, Runner string
GoVersions goVersions
}

func main() {
var flavor, tags, suffix, runner string
flag.StringVar(&flavor, "flavor", "", "")
flag.StringVar(&tags, "tags", "", "")
var suffix string
flag.StringVar(&data.Flavor, "flavor", "", "")
flag.StringVar(&data.Tags, "tags", "", "")
flag.StringVar(&data.Runner, "runner", "ubuntu-latest", "")
flag.StringVar(&suffix, "suffix", "", "")
flag.StringVar(&runner, "runner", "ubuntu-latest", "")
flag.Parse()
for _, n := range []string{"dialect", "go", "revisions"} {
var buf bytes.Buffer
if err := tpl.ExecuteTemplate(&buf, fmt.Sprintf("ci_%s.tmpl", n), struct {
Jobs []Job
Flavor, Tags, Runner string
}{jobs, flavor, tags, runner}); err != nil {
if err := tpl.ExecuteTemplate(&buf, fmt.Sprintf("ci_%s.tmpl", n), data); err != nil {
log.Fatalln(err)
}
err := os.WriteFile(filepath.Clean(fmt.Sprintf("../../.github/workflows/ci-%s_%s.yaml", n, suffix)), buf.Bytes(), 0600)
Expand All @@ -185,3 +192,10 @@ func main() {
}
}
}

func (v goVersions) String() (s string) {
for i := range v {
v[i] = strconv.Quote(v[i])
}
return fmt.Sprintf("[ %s ]", strings.Join(v, ", "))
}

0 comments on commit fa3f99b

Please sign in to comment.