-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is optional now, and considered GA when not set. Semver pre-release tags should be used now to publish non-ga versions. More information in #225
- Loading branch information
Showing
11 changed files
with
179 additions
and
12 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
code/go/internal/validator/semantic/validate_prerelease.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package semantic | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
|
||
ve "github.com/elastic/package-spec/code/go/internal/errors" | ||
) | ||
|
||
var ( | ||
// Prereleases allowed as literals. | ||
literalPrereleases = []string{ | ||
// For convenience with previous recommendations | ||
"next", | ||
"SNAPSHOT", | ||
} | ||
|
||
// Prereleases allowed, potentially with additional numbering. | ||
numberedPrereleases = []string{ | ||
"beta", | ||
"rc", | ||
"preview", | ||
} | ||
) | ||
|
||
// ValidatePrerelease validates additional restrictions on the prerelease tags. | ||
func ValidatePrerelease(pkgRoot string) ve.ValidationErrors { | ||
manifestVersion, err := readManifestVersion(pkgRoot) | ||
if err != nil { | ||
return ve.ValidationErrors{err} | ||
} | ||
|
||
err = validatePrerelease(manifestVersion) | ||
if err != nil { | ||
return ve.ValidationErrors{err} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validatePrerelease(manifestVersion string) error { | ||
version, err := semver.NewVersion(manifestVersion) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if version.Major() == 0 && version.Prerelease() != "" { | ||
return fmt.Errorf("versions below 1.0.0 are considered technical previews, please remove prerelease tag (version: %s)", manifestVersion) | ||
} | ||
|
||
if err := validatePrereleaseTag(version.Prerelease()); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// prereleaseNumberPattern is the pattern that the number after the prerelease tag must match. | ||
// It has to start with a number, hyphen or dot, and end with number or letter. | ||
const prereleaseNumberPattern = "(([0-9]|[.-][0-9A-Za-z])([0-9A-Za-z-.]*[0-9A-Za-z])?)?" | ||
|
||
func validatePrereleaseTag(tag string) error { | ||
if tag == "" { | ||
return nil | ||
} | ||
|
||
for _, literal := range literalPrereleases { | ||
if tag == literal { | ||
return nil | ||
} | ||
} | ||
|
||
for _, numbered := range numberedPrereleases { | ||
if tag == numbered { | ||
return nil | ||
} | ||
|
||
pattern := regexp.MustCompile(fmt.Sprintf("^%s%s$", numbered, prereleaseNumberPattern)) | ||
if pattern.MatchString(tag) { | ||
return nil | ||
} | ||
} | ||
|
||
return ve.ValidationErrors{ | ||
fmt.Errorf("prerelease tag (%s) should be one of [%s], or one of [%s] followed by numbers", | ||
tag, | ||
strings.Join(literalPrereleases, ", "), | ||
strings.Join(numberedPrereleases, ", "), | ||
), | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
code/go/internal/validator/semantic/validate_prerelease_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package semantic | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidatePrerelease(t *testing.T) { | ||
cases := []struct { | ||
version string | ||
valid bool | ||
}{ | ||
{"0.1.0", true}, | ||
{"0.1.0-beta", false}, | ||
{"0.1.0-rc1", false}, | ||
{"1.0.0-beta", true}, | ||
{"1.0.0-beta1", true}, | ||
{"1.0.0-beta-1.0", true}, | ||
{"1.0.0-beta.42", true}, | ||
{"1.0.0-beta.alpha", true}, | ||
{"1.0.0-beta+20220202", true}, | ||
{"1.0.0-beta2+20220202", true}, | ||
{"1.0.0-rc1", true}, | ||
{"1.0.0-preview1", true}, | ||
{"1.0.0-betapreview", false}, | ||
{"1.0.0-alphabeta", false}, | ||
{"1.0.0-123", false}, | ||
{"1.0.0-123", false}, | ||
{"1.0.0-beta.", false}, | ||
{"1.0.0-beta..", false}, | ||
{"1.0.0-beta-", false}, | ||
{"1.0.0-beta--", false}, | ||
{"1.0.0-beta---", false}, | ||
{"1.0.0-beta1.", false}, | ||
{"1.0.0-beta1-", false}, | ||
{"1.0.0-.", false}, | ||
{"1.0.0--", false}, | ||
|
||
// For convenience with previous recommendations | ||
{"1.0.0-SNAPSHOT", true}, | ||
{"1.0.0-next", true}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.version, func(t *testing.T) { | ||
err := validatePrerelease(c.version) | ||
if c.valid { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
title: Nginx access logs | ||
type: logs | ||
release: experimental | ||
streams: | ||
- input: logfile | ||
vars: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
test/packages/good/data_stream/k8s_data_stream_no_definitions/manifest.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters