Backport beta changes

This commit is contained in:
Janos Dobronszki
2021-10-21 14:57:48 +01:00
parent 3d50a3ac06
commit 649fd71ea9
3 changed files with 76 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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