From 461ea4dcce6f1ad3068c1ea32bac3ff996d362de Mon Sep 17 00:00:00 2001 From: mtojek Date: Mon, 23 May 2022 12:52:53 +0200 Subject: [PATCH 1/9] Add Version field to Package --- code/go/internal/validator/common_spec.go | 5 ++++ code/go/internal/validator/folder_spec.go | 33 +++++++++++------------ code/go/internal/validator/package.go | 3 +++ code/go/internal/validator/spec.go | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/code/go/internal/validator/common_spec.go b/code/go/internal/validator/common_spec.go index b049cf080..75bff8e94 100644 --- a/code/go/internal/validator/common_spec.go +++ b/code/go/internal/validator/common_spec.go @@ -19,6 +19,11 @@ type commonSpec struct { DevelopmentFolder bool `yaml:"developmentFolder"` Limits commonSpecLimits `yaml:",inline"` + + // Release type of the spec: beta, ga. + // Packages using beta features won't be able to go GA. + // Default release: ga + Release string `yaml:"release"` } type commonSpecLimits struct { diff --git a/code/go/internal/validator/folder_spec.go b/code/go/internal/validator/folder_spec.go index 53e24e41a..5c5211592 100644 --- a/code/go/internal/validator/folder_spec.go +++ b/code/go/internal/validator/folder_spec.go @@ -16,7 +16,6 @@ import ( "gopkg.in/yaml.v3" ve "github.com/elastic/package-spec/code/go/internal/errors" - "github.com/elastic/package-spec/code/go/internal/fspath" "github.com/elastic/package-spec/code/go/internal/spectypes" ) @@ -71,24 +70,24 @@ func (s *folderSpec) load(fs fs.FS, specPath string) error { return nil } -func (s *folderSpec) validate(packageName string, fsys fspath.FS, path string) ve.ValidationErrors { +func (s *folderSpec) validate(pkg *Package, path string) ve.ValidationErrors { var errs ve.ValidationErrors - files, err := fs.ReadDir(fsys, path) + files, err := fs.ReadDir(pkg, path) if err != nil { - errs = append(errs, errors.Wrapf(err, "could not read folder [%s]", fsys.Path(path))) + errs = append(errs, errors.Wrapf(err, "could not read folder [%s]", pkg.Path(path))) return errs } // This is not taking into account if the folder is for development. Enforce // this limit in all cases to avoid having to read too many files. if contentsLimit := s.Limits.TotalContentsLimit; contentsLimit > 0 && len(files) > contentsLimit { - errs = append(errs, errors.Errorf("folder [%s] exceeds the limit of %d files", fsys.Path(path), contentsLimit)) + errs = append(errs, errors.Errorf("folder [%s] exceeds the limit of %d files", pkg.Path(path), contentsLimit)) return errs } for _, file := range files { fileName := file.Name() - itemSpec, err := s.findItemSpec(packageName, fileName) + itemSpec, err := s.findItemSpec(pkg.Name, fileName) if err != nil { errs = append(errs, err) continue @@ -100,7 +99,7 @@ func (s *folderSpec) validate(packageName string, fsys fspath.FS, path string) v if !s.DevelopmentFolder && strings.Contains(fileName, "-") { errs = append(errs, fmt.Errorf(`file "%s" is invalid: directory name inside package %s contains -: %s`, - fsys.Path(path, fileName), packageName, fileName)) + pkg.Path(path, fileName), pkg.Name, fileName)) } } continue @@ -108,7 +107,7 @@ func (s *folderSpec) validate(packageName string, fsys fspath.FS, path string) v if itemSpec == nil && !s.AdditionalContents { // No spec found for current folder item and we do not allow additional contents in folder. - errs = append(errs, fmt.Errorf("item [%s] is not allowed in folder [%s]", fileName, fsys.Path(path))) + errs = append(errs, fmt.Errorf("item [%s] is not allowed in folder [%s]", fileName, pkg.Path(path))) continue } @@ -151,7 +150,7 @@ func (s *folderSpec) validate(packageName string, fsys fspath.FS, path string) v } subFolderPath := filepath.Join(path, fileName) - subErrs := subFolderSpec.validate(packageName, fsys, subFolderPath) + subErrs := subFolderSpec.validate(pkg, subFolderPath) if len(subErrs) > 0 { errs = append(errs, subErrs...) } @@ -163,21 +162,21 @@ func (s *folderSpec) validate(packageName string, fsys fspath.FS, path string) v } } else { if !itemSpec.isSameType(file) { - errs = append(errs, fmt.Errorf("[%s] is a file but is expected to be a folder", fsys.Path(fileName))) + errs = append(errs, fmt.Errorf("[%s] is a file but is expected to be a folder", pkg.Path(fileName))) continue } itemPath := filepath.Join(path, file.Name()) - itemValidationErrs := itemSpec.validate(s.fs, fsys, s.specPath, itemPath) + itemValidationErrs := itemSpec.validate(s.fs, pkg, s.specPath, itemPath) if itemValidationErrs != nil { for _, ive := range itemValidationErrs { - errs = append(errs, errors.Wrapf(ive, "file \"%s\" is invalid", fsys.Path(itemPath))) + errs = append(errs, errors.Wrapf(ive, "file \"%s\" is invalid", pkg.Path(itemPath))) } } - info, err := fs.Stat(fsys, itemPath) + info, err := fs.Stat(pkg, itemPath) if err != nil { - errs = append(errs, errors.Wrapf(err, "failed to obtain file size for \"%s\"", fsys.Path(itemPath))) + errs = append(errs, errors.Wrapf(err, "failed to obtain file size for \"%s\"", pkg.Path(itemPath))) } else { s.totalContents++ s.totalSize += spectypes.FileSize(info.Size()) @@ -186,7 +185,7 @@ func (s *folderSpec) validate(packageName string, fsys fspath.FS, path string) v } if sizeLimit := s.Limits.TotalSizeLimit; sizeLimit > 0 && s.totalSize > sizeLimit { - errs = append(errs, errors.Errorf("folder [%s] exceeds the total size limit of %s", fsys.Path(path), sizeLimit)) + errs = append(errs, errors.Errorf("folder [%s] exceeds the total size limit of %s", pkg.Path(path), sizeLimit)) } // validate that required items in spec are all accounted for @@ -204,9 +203,9 @@ func (s *folderSpec) validate(packageName string, fsys fspath.FS, path string) v if !fileFound { var err error if itemSpec.Name != "" { - err = fmt.Errorf("expecting to find [%s] %s in folder [%s]", itemSpec.Name, itemSpec.ItemType, fsys.Path(path)) + err = fmt.Errorf("expecting to find [%s] %s in folder [%s]", itemSpec.Name, itemSpec.ItemType, pkg.Path(path)) } else if itemSpec.Pattern != "" { - err = fmt.Errorf("expecting to find %s matching pattern [%s] in folder [%s]", itemSpec.ItemType, itemSpec.Pattern, fsys.Path(path)) + err = fmt.Errorf("expecting to find %s matching pattern [%s] in folder [%s]", itemSpec.ItemType, itemSpec.Pattern, pkg.Path(path)) } errs = append(errs, err) } diff --git a/code/go/internal/validator/package.go b/code/go/internal/validator/package.go index ecc07aca6..a524d3370 100644 --- a/code/go/internal/validator/package.go +++ b/code/go/internal/validator/package.go @@ -19,6 +19,7 @@ import ( type Package struct { Name string Type string + Version string SpecVersion *semver.Version fs fs.FS @@ -66,6 +67,7 @@ func NewPackageFromFS(location string, fsys fs.FS) (*Package, error) { var manifest struct { Name string `yaml:"name"` Type string `yaml:"type"` + Version string `yaml:"version"` SpecVersion string `yaml:"format_version"` } if err := yaml.Unmarshal(data, &manifest); err != nil { @@ -85,6 +87,7 @@ func NewPackageFromFS(location string, fsys fs.FS) (*Package, error) { p := Package{ Name: manifest.Name, Type: manifest.Type, + Version: manifest.Version, SpecVersion: specVersion, fs: fsys, diff --git a/code/go/internal/validator/spec.go b/code/go/internal/validator/spec.go index 2d7cb526a..e60d33810 100644 --- a/code/go/internal/validator/spec.go +++ b/code/go/internal/validator/spec.go @@ -59,7 +59,7 @@ func (s Spec) ValidatePackage(pkg Package) ve.ValidationErrors { } // Syntactic validations - errs = rootSpec.validate(pkg.Name, &pkg, ".") + errs = rootSpec.validate(&pkg, ".") if len(errs) != 0 { return errs } From 940799ae47337bb98a493bb3f625214ebe4ca4f4 Mon Sep 17 00:00:00 2001 From: mtojek Date: Mon, 23 May 2022 13:26:06 +0200 Subject: [PATCH 2/9] Fix tests --- code/go/internal/validator/folder_spec.go | 6 +++++- code/go/internal/validator/package.go | 13 ++++++++++-- code/go/pkg/validator/validator_test.go | 24 ++++++++++++---------- test/packages/no_spec_version/manifest.yml | 3 ++- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/code/go/internal/validator/folder_spec.go b/code/go/internal/validator/folder_spec.go index 5c5211592..673ab2081 100644 --- a/code/go/internal/validator/folder_spec.go +++ b/code/go/internal/validator/folder_spec.go @@ -85,6 +85,10 @@ func (s *folderSpec) validate(pkg *Package, path string) ve.ValidationErrors { return errs } + if s.Release == "beta" && pkg.Version.Prerelease() == "" { + errs = append(errs, errors.Wrapf(err, "spec [%s] has beta features, that can't be used by packages marked as GA", pkg.Path(path))) + } + for _, file := range files { fileName := file.Name() itemSpec, err := s.findItemSpec(pkg.Name, fileName) @@ -94,7 +98,7 @@ func (s *folderSpec) validate(pkg *Package, path string) ve.ValidationErrors { } if itemSpec == nil && s.AdditionalContents { - // No spec found for current folder item but we do allow additional contents in folder. + // No spec found for current folder item, but we do allow additional contents in folder. if file.IsDir() { if !s.DevelopmentFolder && strings.Contains(fileName, "-") { errs = append(errs, diff --git a/code/go/internal/validator/package.go b/code/go/internal/validator/package.go index a524d3370..c9569d6a5 100644 --- a/code/go/internal/validator/package.go +++ b/code/go/internal/validator/package.go @@ -19,7 +19,7 @@ import ( type Package struct { Name string Type string - Version string + Version *semver.Version SpecVersion *semver.Version fs fs.FS @@ -78,6 +78,15 @@ func NewPackageFromFS(location string, fsys fs.FS) (*Package, error) { return nil, errors.New("package type undefined in the package manifest file") } + if manifest.Version == "" { + return nil, errors.New("package version undefined in the package manifest file") + } + + packageVersion, err := semver.NewVersion(manifest.Version) + if err != nil { + return nil, errors.Wrapf(err, "could not read package version from package manifest file [%v]", pkgManifestPath) + } + specVersion, err := semver.NewVersion(manifest.SpecVersion) if err != nil { return nil, errors.Wrapf(err, "could not read specification version from package manifest file [%v]", pkgManifestPath) @@ -87,7 +96,7 @@ func NewPackageFromFS(location string, fsys fs.FS) (*Package, error) { p := Package{ Name: manifest.Name, Type: manifest.Type, - Version: manifest.Version, + Version: packageVersion, SpecVersion: specVersion, fs: fsys, diff --git a/code/go/pkg/validator/validator_test.go b/code/go/pkg/validator/validator_test.go index d108804b9..b089e5aeb 100644 --- a/code/go/pkg/validator/validator_test.go +++ b/code/go/pkg/validator/validator_test.go @@ -70,7 +70,7 @@ func TestValidateFile(t *testing.T) { "missing_version": { "manifest.yml", []string{ - "field version: Invalid type. Expected: string, given: null", + "package version undefined in the package manifest file", }, }, "bad_time_series": { @@ -97,19 +97,21 @@ func TestValidateFile(t *testing.T) { require.NoError(t, errs) } else { require.Error(t, errs) - require.Len(t, errs, len(test.expectedErrContains)) vErrs, ok := errs.(errors.ValidationErrors) - require.True(t, ok) - - var errMessages []string - for _, vErr := range vErrs { - errMessages = append(errMessages, vErr.Error()) - } + if ok { + require.Len(t, errs, len(test.expectedErrContains)) + var errMessages []string + for _, vErr := range vErrs { + errMessages = append(errMessages, vErr.Error()) + } - for _, expectedErrMessage := range test.expectedErrContains { - expectedErr := errPrefix + expectedErrMessage - require.Contains(t, errMessages, expectedErr) + for _, expectedErrMessage := range test.expectedErrContains { + expectedErr := errPrefix + expectedErrMessage + require.Contains(t, errMessages, expectedErr) + } + return } + require.Equal(t, errs.Error(), test.expectedErrContains[0]) } }) } diff --git a/test/packages/no_spec_version/manifest.yml b/test/packages/no_spec_version/manifest.yml index 519d6788c..d53053651 100644 --- a/test/packages/no_spec_version/manifest.yml +++ b/test/packages/no_spec_version/manifest.yml @@ -1,3 +1,4 @@ # no format_version in this file name: mypackage -type: integration \ No newline at end of file +type: integration +version: 1.0.0 \ No newline at end of file From 8d99e6333450f0a9171cfd970a11b551c952705e Mon Sep 17 00:00:00 2001 From: mtojek Date: Mon, 23 May 2022 13:39:47 +0200 Subject: [PATCH 3/9] Fix: error message --- code/go/internal/validator/folder_spec.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/go/internal/validator/folder_spec.go b/code/go/internal/validator/folder_spec.go index 673ab2081..143feeba4 100644 --- a/code/go/internal/validator/folder_spec.go +++ b/code/go/internal/validator/folder_spec.go @@ -85,8 +85,9 @@ func (s *folderSpec) validate(pkg *Package, path string) ve.ValidationErrors { return errs } + // Don't enable beta features for packages marked as GA. if s.Release == "beta" && pkg.Version.Prerelease() == "" { - errs = append(errs, errors.Wrapf(err, "spec [%s] has beta features, that can't be used by packages marked as GA", pkg.Path(path))) + errs = append(errs, errors.Errorf("spec for [%s] defines beta features which can't be enabled for packages marked as GA", pkg.Path(path))) } for _, file := range files { From b7ea2215f3501a467e09a482f11ffa673cd8b606 Mon Sep 17 00:00:00 2001 From: mtojek Date: Mon, 23 May 2022 13:44:57 +0200 Subject: [PATCH 4/9] Fix changelog --- versions/1/changelog.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/versions/1/changelog.yml b/versions/1/changelog.yml index ec2f2374a..2e694b01b 100644 --- a/versions/1/changelog.yml +++ b/versions/1/changelog.yml @@ -6,7 +6,10 @@ changes: - description: Prepare for next version type: enhancement - link: https://github.com/elastic/package-spec/pull/? + link: https://github.com/elastic/package-spec/pull/337 + - description: Define beta features in spec + type: enhancement + link: https://github.com/elastic/package-spec/pull/341 - version: 1.9.0 changes: - description: Prepare for next version From 907a760d24f04692e70b895e93ba74b67138d95b Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Mon, 23 May 2022 14:09:40 +0200 Subject: [PATCH 5/9] Update code/go/internal/validator/folder_spec.go Co-authored-by: Josh Dover <1813008+joshdover@users.noreply.github.com> --- code/go/internal/validator/folder_spec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/go/internal/validator/folder_spec.go b/code/go/internal/validator/folder_spec.go index 143feeba4..ef23476d7 100644 --- a/code/go/internal/validator/folder_spec.go +++ b/code/go/internal/validator/folder_spec.go @@ -87,7 +87,7 @@ func (s *folderSpec) validate(pkg *Package, path string) ve.ValidationErrors { // Don't enable beta features for packages marked as GA. if s.Release == "beta" && pkg.Version.Prerelease() == "" { - errs = append(errs, errors.Errorf("spec for [%s] defines beta features which can't be enabled for packages marked as GA", pkg.Path(path))) + errs = append(errs, errors.Errorf("spec for [%s] defines beta features which can't be enabled for packages with a stable semantic version", pkg.Path(path))) } for _, file := range files { From f057be5a84746469218d2033ca2501223e93395f Mon Sep 17 00:00:00 2001 From: mtojek Date: Mon, 23 May 2022 14:18:28 +0200 Subject: [PATCH 6/9] Log warning --- code/go/internal/validator/folder_spec.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/go/internal/validator/folder_spec.go b/code/go/internal/validator/folder_spec.go index ef23476d7..b8dce4e93 100644 --- a/code/go/internal/validator/folder_spec.go +++ b/code/go/internal/validator/folder_spec.go @@ -8,6 +8,7 @@ import ( "fmt" "io/fs" "io/ioutil" + "log" "path/filepath" "regexp" "strings" @@ -88,6 +89,8 @@ func (s *folderSpec) validate(pkg *Package, path string) ve.ValidationErrors { // Don't enable beta features for packages marked as GA. if s.Release == "beta" && pkg.Version.Prerelease() == "" { errs = append(errs, errors.Errorf("spec for [%s] defines beta features which can't be enabled for packages with a stable semantic version", pkg.Path(path))) + } else if s.Release == "beta" && pkg.Version.Prerelease() != "" { + log.Printf("Warning: package with non-stable semantic version and active beta features (enabled in [%s]) can't be released as stable version.q", pkg.Path(path)) } for _, file := range files { From 6223fffa102b0ae5fa2219e654226b51ae4af267 Mon Sep 17 00:00:00 2001 From: mtojek Date: Mon, 23 May 2022 15:09:00 +0200 Subject: [PATCH 7/9] Spec testing --- code/go/internal/validator/package.go | 2 +- code/go/internal/validator/package_test.go | 1 + code/go/internal/validator/spec_test.go | 30 +++++++++++++++++++ .../testdata/fakespec/1/fake/beta/spec.yml | 3 ++ .../testdata/fakespec/1/fake/ga/spec.yml | 2 ++ .../testdata/fakespec/1/fake/spec.yml | 12 ++++++++ .../packages/features_beta/beta/.empty | 0 .../packages/features_beta/changelog.yml | 6 ++++ .../testdata/packages/features_beta/ga/.empty | 0 .../packages/features_beta/manifest.yml | 4 +++ .../packages/features_ga/changelog.yml | 6 ++++ .../testdata/packages/features_ga/ga/.empty | 0 .../packages/features_ga/manifest.yml | 4 +++ 13 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 code/go/internal/validator/testdata/fakespec/1/fake/beta/spec.yml create mode 100644 code/go/internal/validator/testdata/fakespec/1/fake/ga/spec.yml create mode 100644 code/go/internal/validator/testdata/fakespec/1/fake/spec.yml create mode 100644 code/go/internal/validator/testdata/packages/features_beta/beta/.empty create mode 100644 code/go/internal/validator/testdata/packages/features_beta/changelog.yml create mode 100644 code/go/internal/validator/testdata/packages/features_beta/ga/.empty create mode 100644 code/go/internal/validator/testdata/packages/features_beta/manifest.yml create mode 100644 code/go/internal/validator/testdata/packages/features_ga/changelog.yml create mode 100644 code/go/internal/validator/testdata/packages/features_ga/ga/.empty create mode 100644 code/go/internal/validator/testdata/packages/features_ga/manifest.yml diff --git a/code/go/internal/validator/package.go b/code/go/internal/validator/package.go index c9569d6a5..e143d2a2d 100644 --- a/code/go/internal/validator/package.go +++ b/code/go/internal/validator/package.go @@ -89,7 +89,7 @@ func NewPackageFromFS(location string, fsys fs.FS) (*Package, error) { specVersion, err := semver.NewVersion(manifest.SpecVersion) if err != nil { - return nil, errors.Wrapf(err, "could not read specification version from package manifest file [%v]", pkgManifestPath) + return nil, errors.Wrapf(err, "could not read specification version from package manifest file [%v]", manifest.SpecVersion) } // Instantiate Package object and return it diff --git a/code/go/internal/validator/package_test.go b/code/go/internal/validator/package_test.go index 9c56b334b..75f264e03 100644 --- a/code/go/internal/validator/package_test.go +++ b/code/go/internal/validator/package_test.go @@ -47,3 +47,4 @@ func TestNewPackage(t *testing.T) { }) } } + diff --git a/code/go/internal/validator/spec_test.go b/code/go/internal/validator/spec_test.go index 04eea52e0..08d61c466 100644 --- a/code/go/internal/validator/spec_test.go +++ b/code/go/internal/validator/spec_test.go @@ -5,6 +5,7 @@ package validator import ( + "github.com/elastic/package-spec/code/go/internal/fspath" "testing" "github.com/Masterminds/semver/v3" @@ -33,3 +34,32 @@ func TestNewSpec(t *testing.T) { } } } + +func TestNoBetaFeatures_Package_GA(t *testing.T) { + // given + s := Spec{ + *semver.MustParse("1.0.0"), + fspath.DirFS("testdata/fakespec"), + "1", + } + pkg, err := NewPackage("testdata/packages/features_ga") + require.NoError(t, err) + + err = s.ValidatePackage(*pkg) + require.Empty(t, err) +} + +func TestBetaFeatures_Package_GA(t *testing.T) { + // given + s := Spec{ + *semver.MustParse("1.0.0"), + fspath.DirFS("testdata/fakespec"), + "1", + } + pkg, err := NewPackage("testdata/packages/features_beta") + require.NoError(t, err) + + errs := s.ValidatePackage(*pkg) + require.Len(t,errs, 1) + require.Equal(t, errs[0].Error(), "spec for [testdata/packages/features_beta/beta] defines beta features which can't be enabled for packages with a stable semantic version") +} \ No newline at end of file diff --git a/code/go/internal/validator/testdata/fakespec/1/fake/beta/spec.yml b/code/go/internal/validator/testdata/fakespec/1/fake/beta/spec.yml new file mode 100644 index 000000000..717fef864 --- /dev/null +++ b/code/go/internal/validator/testdata/fakespec/1/fake/beta/spec.yml @@ -0,0 +1,3 @@ +spec: + additionalContents: true + release: beta diff --git a/code/go/internal/validator/testdata/fakespec/1/fake/ga/spec.yml b/code/go/internal/validator/testdata/fakespec/1/fake/ga/spec.yml new file mode 100644 index 000000000..cf2bcdfe4 --- /dev/null +++ b/code/go/internal/validator/testdata/fakespec/1/fake/ga/spec.yml @@ -0,0 +1,2 @@ +spec: + additionalContents: true \ No newline at end of file diff --git a/code/go/internal/validator/testdata/fakespec/1/fake/spec.yml b/code/go/internal/validator/testdata/fakespec/1/fake/spec.yml new file mode 100644 index 000000000..2edaece8e --- /dev/null +++ b/code/go/internal/validator/testdata/fakespec/1/fake/spec.yml @@ -0,0 +1,12 @@ +spec: + additionalContents: true + contents: + - description: Folder containing beta features + type: folder + name: beta + $ref: "./beta/spec.yml" + - description: Folder containing GA features + type: folder + name: ga + required: true + $ref: "./ga/spec.yml" \ No newline at end of file diff --git a/code/go/internal/validator/testdata/packages/features_beta/beta/.empty b/code/go/internal/validator/testdata/packages/features_beta/beta/.empty new file mode 100644 index 000000000..e69de29bb diff --git a/code/go/internal/validator/testdata/packages/features_beta/changelog.yml b/code/go/internal/validator/testdata/packages/features_beta/changelog.yml new file mode 100644 index 000000000..b96bca624 --- /dev/null +++ b/code/go/internal/validator/testdata/packages/features_beta/changelog.yml @@ -0,0 +1,6 @@ +# newer versions go on top +- version: "2.3.4" + changes: + - description: Initial draft of the package + type: enhancement + link: https://github.com/elastic/package-spec/pull/341 \ No newline at end of file diff --git a/code/go/internal/validator/testdata/packages/features_beta/ga/.empty b/code/go/internal/validator/testdata/packages/features_beta/ga/.empty new file mode 100644 index 000000000..e69de29bb diff --git a/code/go/internal/validator/testdata/packages/features_beta/manifest.yml b/code/go/internal/validator/testdata/packages/features_beta/manifest.yml new file mode 100644 index 000000000..6db2183d1 --- /dev/null +++ b/code/go/internal/validator/testdata/packages/features_beta/manifest.yml @@ -0,0 +1,4 @@ +format_version: 1.0.0 +name: features_beta +version: 2.3.4 +type: fake \ No newline at end of file diff --git a/code/go/internal/validator/testdata/packages/features_ga/changelog.yml b/code/go/internal/validator/testdata/packages/features_ga/changelog.yml new file mode 100644 index 000000000..8981d7328 --- /dev/null +++ b/code/go/internal/validator/testdata/packages/features_ga/changelog.yml @@ -0,0 +1,6 @@ +# newer versions go on top +- version: "1.2.3" + changes: + - description: Initial draft of the package + type: enhancement + link: https://github.com/elastic/package-spec/pull/341 \ No newline at end of file diff --git a/code/go/internal/validator/testdata/packages/features_ga/ga/.empty b/code/go/internal/validator/testdata/packages/features_ga/ga/.empty new file mode 100644 index 000000000..e69de29bb diff --git a/code/go/internal/validator/testdata/packages/features_ga/manifest.yml b/code/go/internal/validator/testdata/packages/features_ga/manifest.yml new file mode 100644 index 000000000..f0cea2e91 --- /dev/null +++ b/code/go/internal/validator/testdata/packages/features_ga/manifest.yml @@ -0,0 +1,4 @@ +format_version: 1.0.0 +name: features_ga +version: 1.2.3 +type: fake \ No newline at end of file From 8f524424f8c0bf50db5188acf5908c6db9f37dce Mon Sep 17 00:00:00 2001 From: mtojek Date: Tue, 24 May 2022 14:16:04 +0200 Subject: [PATCH 8/9] Fix: beta and ga as valid levels --- code/go/internal/validator/folder_spec.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/go/internal/validator/folder_spec.go b/code/go/internal/validator/folder_spec.go index b8dce4e93..917ceb9c9 100644 --- a/code/go/internal/validator/folder_spec.go +++ b/code/go/internal/validator/folder_spec.go @@ -87,7 +87,9 @@ func (s *folderSpec) validate(pkg *Package, path string) ve.ValidationErrors { } // Don't enable beta features for packages marked as GA. - if s.Release == "beta" && pkg.Version.Prerelease() == "" { + if s.Release != "" && s.Release != "beta" { + errs = append(errs, errors.Errorf("unsupport release level, supported values: beta, ga")) + } else if s.Release == "beta" && pkg.Version.Prerelease() == "" { errs = append(errs, errors.Errorf("spec for [%s] defines beta features which can't be enabled for packages with a stable semantic version", pkg.Path(path))) } else if s.Release == "beta" && pkg.Version.Prerelease() != "" { log.Printf("Warning: package with non-stable semantic version and active beta features (enabled in [%s]) can't be released as stable version.q", pkg.Path(path)) From 8204c4d933cf49d658b26fe4f8bc92e1208e50ef Mon Sep 17 00:00:00 2001 From: mtojek Date: Tue, 24 May 2022 14:39:38 +0200 Subject: [PATCH 9/9] Use switch --- code/go/internal/validator/folder_spec.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/code/go/internal/validator/folder_spec.go b/code/go/internal/validator/folder_spec.go index 917ceb9c9..0689a43bc 100644 --- a/code/go/internal/validator/folder_spec.go +++ b/code/go/internal/validator/folder_spec.go @@ -87,12 +87,16 @@ func (s *folderSpec) validate(pkg *Package, path string) ve.ValidationErrors { } // Don't enable beta features for packages marked as GA. - if s.Release != "" && s.Release != "beta" { - errs = append(errs, errors.Errorf("unsupport release level, supported values: beta, ga")) - } else if s.Release == "beta" && pkg.Version.Prerelease() == "" { - errs = append(errs, errors.Errorf("spec for [%s] defines beta features which can't be enabled for packages with a stable semantic version", pkg.Path(path))) - } else if s.Release == "beta" && pkg.Version.Prerelease() != "" { - log.Printf("Warning: package with non-stable semantic version and active beta features (enabled in [%s]) can't be released as stable version.q", pkg.Path(path)) + switch s.Release { + case "", "ga": // do nothing + case "beta": + if pkg.Version.Prerelease() == "" { + errs = append(errs, errors.Errorf("spec for [%s] defines beta features which can't be enabled for packages with a stable semantic version", pkg.Path(path))) + } else { + log.Printf("Warning: package with non-stable semantic version and active beta features (enabled in [%s]) can't be released as stable version.q", pkg.Path(path)) + } + default: + errs = append(errs, errors.Errorf("unsupport release level, supported values: beta, ga")) } for _, file := range files {