From 649fd71ea96b7f491c65645952c2c3e127bbc36d Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 21 Oct 2021 14:57:48 +0100 Subject: [PATCH] Backport beta changes --- .github/workflows/publish.yml | 12 +++++++++++ cmd/clients/gen_test.go | 27 +++++++++++++++++++++++++ cmd/clients/main.go | 38 ++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 277e024..b96993b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -84,3 +84,15 @@ jobs: npm install npm run build npm publish --access public + + - name: npm install beta + working-directory: services + if: github.ref == 'refs/heads/beta' + env: + IS_BETA: yep + run: | + git status + cd clients/ts; + npm install + npm run build + npm publish --access public --tag beta \ No newline at end of file diff --git a/cmd/clients/gen_test.go b/cmd/clients/gen_test.go index df0b005..7dd64a3 100644 --- a/cmd/clients/gen_test.go +++ b/cmd/clients/gen_test.go @@ -6,9 +6,36 @@ import ( "strings" "testing" + "github.com/Masterminds/semver/v3" "github.com/getkin/kin-openapi/openapi3" ) +func TestSemver(t *testing.T) { + v, _ := semver.NewVersion("0.0.0-beta1") + if incBeta(*v).String() != "0.0.0-beta2" { + t.Fatal(v) + } + + v1, _ := semver.NewVersion("0.0.1") + if !v1.GreaterThan(v) { + t.Fatal("no good") + } + + v2, _ := semver.NewVersion("0.0.0") + if !v2.GreaterThan(v) { + t.Fatal("no good") + } + + if v.String() != "0.0.0-beta1" { + t.Fatal("no good") + } + + v3, _ := semver.NewVersion("0.0.0-beta2") + if !v3.GreaterThan(v) { + t.Fatal("no good") + } +} + type tspec struct { openapi string tsresult string diff --git a/cmd/clients/main.go b/cmd/clients/main.go index 4b66516..2ea1e90 100644 --- a/cmd/clients/main.go +++ b/cmd/clients/main.go @@ -13,6 +13,7 @@ import ( "path/filepath" "regexp" "sort" + "strconv" "strings" "text/template" @@ -525,6 +526,8 @@ func main() { type npmVers struct { Versions []string `json:"versions"` } + beta := os.Getenv("IS_BETA") != "" + npmOutput := &npmVers{} var latest *semver.Version if len(outp) > 0 { @@ -547,11 +550,26 @@ func main() { if v.GreaterThan(latest) { latest = v } + } + if latest == nil { latest, _ = semver.NewVersion("0.0.0") } - newV := latest.IncPatch() + + var newV semver.Version + if beta { + // bump a beta version + if strings.Contains(latest.String(), "beta") { + newV = incBeta(*latest) + } else { + // make beta out of latest non beta version + v, _ := semver.NewVersion(latest.IncPatch().String() + "-beta1") + newV = *v + } + } else { + newV = newV.IncPatch() + } // add file list to gitignore f, err = os.OpenFile(filepath.Join(tsPath, ".gitignore"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0744) @@ -603,6 +621,24 @@ func main() { } } +func incBeta(ver semver.Version) semver.Version { + s := ver.String() + parts := strings.Split(s, "beta") + if len(parts) < 2 { + panic("not a beta version " + s) + } + i, err := strconv.ParseInt(parts[1], 10, 64) + if err != nil { + panic(err) + } + i++ + v, err := semver.NewVersion(parts[0] + "beta" + fmt.Sprintf("%v", i)) + if err != nil { + panic(err) + } + return *v +} + func schemaToType(language, serviceName, typeName string, schemas map[string]*openapi3.SchemaRef) string { var recurse func(props map[string]*openapi3.SchemaRef, level int) string