Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore deprecated release tag from manifests #647

Merged
merged 11 commits into from
Feb 11, 2022
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.17.3
1.17.6
11 changes: 0 additions & 11 deletions cmd/create_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type newPackageAnswers struct {
Title string
Description string
Categories []string
Release string
KibanaVersion string `survey:"kibana_version"`
GithubOwner string `survey:"github_owner"`
}
Expand Down Expand Up @@ -78,15 +77,6 @@ func createPackageCommandAction(cmd *cobra.Command, args []string) error {
},
Validate: survey.Required,
},
{
Name: "release",
Prompt: &survey.Select{
Message: "Release:",
Options: []string{"experimental", "beta", "ga"},
Default: "experimental",
},
Validate: survey.Required,
},
{
Name: "kibana_version",
Prompt: &survey.Input{
Expand Down Expand Up @@ -136,7 +126,6 @@ func createPackageDescriptorFromAnswers(answers newPackageAnswers) archetype.Pac
Owner: packages.Owner{
Github: answers.GithubOwner,
},
Release: answers.Release,
Description: answers.Description,
License: "basic",
Categories: answers.Categories,
Expand Down
55 changes: 52 additions & 3 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strings"

"github.com/Masterminds/semver"
"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
Expand Down Expand Up @@ -60,7 +61,10 @@ func statusCommandAction(cmd *cobra.Command, args []string) error {
options := registry.SearchOptions{
All: showAll,
KibanaVersion: kibanaVersion,
Experimental: true,
Prerelease: true,

// Deprecated, keeping for compatibility with older versions of the registry.
Experimental: true,
}
packageStatus, err := getPackageStatus(packageName, options)
if err != nil {
Expand Down Expand Up @@ -127,7 +131,7 @@ func print(p *status.PackageStatus, w io.Writer) error {
}

bold.Fprintln(w, "Package Versions:")
table := tablewriter.NewWriter(os.Stdout)
table := tablewriter.NewWriter(w)
table.SetHeader([]string{"Environment", "Version", "Release", "Title", "Description"})
table.SetHeaderColor(
twColor(tablewriter.Colors{tablewriter.Bold}),
Expand Down Expand Up @@ -182,7 +186,7 @@ func formatManifest(environment string, manifest packages.PackageManifest, extra
if len(extraVersions) > 0 {
version = fmt.Sprintf("%s (%s)", version, strings.Join(extraVersions, ", "))
}
return []string{environment, version, manifest.Release, manifest.Title, manifest.Description}
return []string{environment, version, releaseFromVersion(manifest.Version), manifest.Title, manifest.Description}
}

// twColor no-ops the color setting if we don't want to colorize the output
Expand All @@ -192,3 +196,48 @@ func twColor(colors tablewriter.Colors) tablewriter.Colors {
}
return colors
}

// releaseFromVersion returns the human-friendly release level based on semantic versioning conventions.
// It does a best-effort mapping, it doesn't do validation.
func releaseFromVersion(version string) string {
const (
previewVersionText = "Technical Preview"
betaVersionText = "Beta"
releaseCandidateText = "Release Candidate"
gaVersion = "GA"
defaultText = betaVersionText
)

conventionPrereleasePrefixes := []struct {
prefix string
text string
}{
{"beta", betaVersionText},
{"rc", releaseCandidateText},
{"preview", previewVersionText},
}

sv, err := semver.NewVersion(version)
if err != nil {
// Ignoring errors on version parsing here, use best-effort defaults.
if strings.HasPrefix(version, "0.") {
return previewVersionText
}
return defaultText
}

if sv.Major() == 0 {
return previewVersionText
}
if sv.Prerelease() == "" {
return gaVersion
}

for _, convention := range conventionPrereleasePrefixes {
if strings.HasPrefix(sv.Prerelease(), convention.prefix) {
return convention.text
}
}

return defaultText
}
132 changes: 132 additions & 0 deletions cmd/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// 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 cmd

import (
"bytes"
"flag"
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/elastic-package/internal/packages"
"github.com/elastic/elastic-package/internal/packages/status"
)

var generateFlag = flag.Bool("generate", false, "Write golden files")

func fooPackage(version string) packages.PackageManifest {
return packages.PackageManifest{
Name: "foo",
Version: version,
Title: "Foo",
Description: "Foo integration",
}
}

func TestStatusFormatAndPrint(t *testing.T) {
cases := []struct {
title string
pkgStatus *status.PackageStatus
expected string
}{
{
title: "no versions",
pkgStatus: &status.PackageStatus{Name: "foo"},
expected: "./testdata/status-no-versions",
},
{
title: "version-one-stage",
pkgStatus: &status.PackageStatus{
Name: "foo",
Production: []packages.PackageManifest{
fooPackage("1.0.0"),
},
},
expected: "./testdata/status-version-one-stage",
},
{
title: "some versions",
pkgStatus: &status.PackageStatus{
Name: "foo",
Production: []packages.PackageManifest{
fooPackage("1.0.0"),
},
Staging: []packages.PackageManifest{
fooPackage("1.1.0-beta1"),
},
Snapshot: []packages.PackageManifest{
fooPackage("2.0.0-rc1"),
},
},
expected: "./testdata/status-some-versions",
},
{
title: "preview versions",
pkgStatus: &status.PackageStatus{
Name: "foo",
Production: []packages.PackageManifest{
fooPackage("0.9.0"),
},
Staging: []packages.PackageManifest{
fooPackage("1.0.0-preview1"),
},
Snapshot: []packages.PackageManifest{
fooPackage("1.0.0-preview5"),
},
},
expected: "./testdata/status-preview-versions",
},
{
title: "multiple versions in stage",
pkgStatus: &status.PackageStatus{
Name: "foo",
Production: []packages.PackageManifest{
fooPackage("1.0.0"),
fooPackage("1.0.1"),
fooPackage("1.0.2"),
},
Staging: []packages.PackageManifest{
fooPackage("1.0.0"),
fooPackage("1.0.1"),
fooPackage("1.0.2"),
fooPackage("1.1.0-beta1"),
},
Snapshot: []packages.PackageManifest{
fooPackage("1.0.0"),
fooPackage("1.0.1"),
fooPackage("1.0.2"),
fooPackage("1.1.0-beta1"),
fooPackage("2.0.0-rc1"),
},
},
expected: "./testdata/status-multiple-versions-in-stage",
},
}

for _, c := range cases {
t.Run(c.title, func(t *testing.T) {
var buf bytes.Buffer
err := print(c.pkgStatus, &buf)
require.NoError(t, err)

assertOutputWithFile(t, c.expected, buf.String())
})
}
}

func assertOutputWithFile(t *testing.T, path string, out string) {
if *generateFlag {
err := ioutil.WriteFile(path, []byte(out), 0644)
require.NoError(t, err)
}

d, err := ioutil.ReadFile(path)
require.NoError(t, err)

assert.Equal(t, string(d), out)
}
13 changes: 13 additions & 0 deletions cmd/testdata/status-multiple-versions-in-stage
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Package: foo
Package Versions:
+-------------+--------------------------------+-------------------+-------+-----------------+
| ENVIRONMENT | VERSION | RELEASE | TITLE | DESCRIPTION |
+-------------+--------------------------------+-------------------+-------+-----------------+
| Snapshot | 2.0.0-rc1 (1.0.0, 1.0.1, | Release Candidate | Foo | Foo integration |
| | 1.0.2, 1.1.0-beta1) | | | |
+-------------+--------------------------------+-------------------+-------+-----------------+
| Staging | 1.1.0-beta1 (1.0.0, 1.0.1, | Beta | Foo | Foo integration |
| | 1.0.2) | | | |
+-------------+--------------------------------+-------------------+-------+-----------------+
| Production | 1.0.2 (1.0.0, 1.0.1) | GA | Foo | Foo integration |
+-------------+--------------------------------+-------------------+-------+-----------------+
11 changes: 11 additions & 0 deletions cmd/testdata/status-no-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: foo
Package Versions:
+-------------+---------+---------+-------+-------------+
| ENVIRONMENT | VERSION | RELEASE | TITLE | DESCRIPTION |
+-------------+---------+---------+-------+-------------+
| Snapshot | - | - | - | - |
+-------------+---------+---------+-------+-------------+
| Staging | - | - | - | - |
+-------------+---------+---------+-------+-------------+
| Production | - | - | - | - |
+-------------+---------+---------+-------+-------------+
11 changes: 11 additions & 0 deletions cmd/testdata/status-preview-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: foo
Package Versions:
+-------------+----------------+-------------------+-------+-----------------+
| ENVIRONMENT | VERSION | RELEASE | TITLE | DESCRIPTION |
+-------------+----------------+-------------------+-------+-----------------+
| Snapshot | 1.0.0-preview5 | Technical Preview | Foo | Foo integration |
+-------------+----------------+-------------------+-------+-----------------+
| Staging | 1.0.0-preview1 | Technical Preview | Foo | Foo integration |
+-------------+----------------+-------------------+-------+-----------------+
| Production | 0.9.0 | Technical Preview | Foo | Foo integration |
+-------------+----------------+-------------------+-------+-----------------+
11 changes: 11 additions & 0 deletions cmd/testdata/status-some-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: foo
Package Versions:
+-------------+-------------+-------------------+-------+-----------------+
| ENVIRONMENT | VERSION | RELEASE | TITLE | DESCRIPTION |
+-------------+-------------+-------------------+-------+-----------------+
| Snapshot | 2.0.0-rc1 | Release Candidate | Foo | Foo integration |
+-------------+-------------+-------------------+-------+-----------------+
| Staging | 1.1.0-beta1 | Beta | Foo | Foo integration |
+-------------+-------------+-------------------+-------+-----------------+
| Production | 1.0.0 | GA | Foo | Foo integration |
+-------------+-------------+-------------------+-------+-----------------+
11 changes: 11 additions & 0 deletions cmd/testdata/status-version-one-stage
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: foo
Package Versions:
+-------------+---------+---------+-------+-----------------+
| ENVIRONMENT | VERSION | RELEASE | TITLE | DESCRIPTION |
+-------------+---------+---------+-------+-----------------+
| Snapshot | - | - | - | - |
+-------------+---------+---------+-------+-----------------+
| Staging | - | - | - | - |
+-------------+---------+---------+-------+-----------------+
| Production | 1.0.0 | GA | Foo | Foo integration |
+-------------+---------+---------+-------+-----------------+
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/elastic/go-elasticsearch/v7 v7.17.0
github.com/elastic/go-licenser v0.4.0
github.com/elastic/go-ucfg v0.8.4
github.com/elastic/package-spec v1.3.0
github.com/elastic/package-spec v1.4.1
github.com/fatih/color v1.13.0
github.com/go-git/go-billy/v5 v5.3.1
github.com/go-git/go-git/v5 v5.4.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ github.com/elastic/go-licenser v0.4.0 h1:jLq6A5SilDS/Iz1ABRkO6BHy91B9jBora8FwGRs
github.com/elastic/go-licenser v0.4.0/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU=
github.com/elastic/go-ucfg v0.8.4 h1:OAHTnubzXKsYYYWVzl8psLcS5mCbNKjXxtMY41itthk=
github.com/elastic/go-ucfg v0.8.4/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA=
github.com/elastic/package-spec v1.3.0 h1:ntd8EfZ0heZqaZdZpyHJPBFUml9LMlSSZTp04dLZyAg=
github.com/elastic/package-spec v1.3.0/go.mod h1:KzGTSDqCkdhmL1IFpOH2ZQNSSE9JEhNtndxU3ZrQilA=
github.com/elastic/package-spec v1.4.1 h1:lF+EoD3aif5FI4xPbdtT+0ShEkUGj0D6boelCAQVzoI=
github.com/elastic/package-spec v1.4.1/go.mod h1:KzGTSDqCkdhmL1IFpOH2ZQNSSE9JEhNtndxU3ZrQilA=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
Expand Down
1 change: 0 additions & 1 deletion internal/packages/archetype/package_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type: {{.Manifest.Type}}
categories:{{range $category := .Manifest.Categories}}
- {{$category}}
{{- end}}
release: {{.Manifest.Release}}
conditions:
kibana.version: "{{.Manifest.Conditions.Kibana.Version}}"
screenshots:
Expand Down
8 changes: 0 additions & 8 deletions internal/packages/archetype/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ func TestPackage(t *testing.T) {
pd := createPackageDescriptorForTest()
pd.Manifest.Version = ""

err := createAndCheckPackage(t, pd)
require.Error(t, err)
})
t.Run("missing-release", func(t *testing.T) {
pd := createPackageDescriptorForTest()
pd.Manifest.Release = ""

err := createAndCheckPackage(t, pd)
require.Error(t, err)
})
Expand Down Expand Up @@ -74,7 +67,6 @@ func createPackageDescriptorForTest() PackageDescriptor {
Owner: packages.Owner{
Github: "mtojek",
},
Release: "experimental",
Description: "This package has been generated by a Go unit test.",
License: "basic",
Categories: []string{"aws", "custom"},
Expand Down
1 change: 0 additions & 1 deletion internal/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ type PackageManifest struct {
PolicyTemplates []PolicyTemplate `config:"policy_templates" json:"policy_templates" yaml:"policy_templates"`
Vars []Variable `config:"vars" json:"vars" yaml:"vars"`
Owner Owner `config:"owner" json:"owner" yaml:"owner"`
Release string `config:"release" json:"release" yaml:"release"`
Description string `config:"description" json:"description" yaml:"description"`
License string `config:"license" json:"license" yaml:"license"`
Categories []string `config:"categories" json:"categories" yaml:"categories"`
Expand Down
5 changes: 4 additions & 1 deletion internal/registry/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import (

// SearchOptions specify the query parameters without the package name for the search API
type SearchOptions struct {
Experimental bool `url:"experimental"`
Prerelease bool `url:"prerelease"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... oh, and on the EPR release.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this will be the last piece to merge.

All bool `url:"all"`
KibanaVersion string `url:"kibana.version,omitempty"`

// Deprecated
Experimental bool `url:"experimental"`
}

// searchQuery specify the package and query parameters for the search API
Expand Down