diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index a5f1b75d4e2..4209610e727 100755 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -11,6 +11,8 @@ git config --global core.pager 'cat' export UPLOAD_SAFE_LOGS=${UPLOAD_SAFE_LOGS:-"0"} export SERVERLESS=${SERVERLESS:-"false"} export STACK_VERSION=${STACK_VERSION:-""} +export ELASTIC_SUBSCRIPTION=${ELASTIC_SUBSCRIPTION:-""} +export STACK_LOGSDB_ENABLED=${STACK_LOGSDB_ENABLED:-"false"} export FORCE_CHECK_ALL=${FORCE_CHECK_ALL:-"false"} export PUBLISH_COVERAGE_REPORTS=${PUBLISH_COVERAGE_REPORTS:-"false"} diff --git a/.buildkite/scripts/common.sh b/.buildkite/scripts/common.sh index 1384cfb02bc..1e941a5823e 100755 --- a/.buildkite/scripts/common.sh +++ b/.buildkite/scripts/common.sh @@ -18,6 +18,8 @@ API_BUILDKITE_PIPELINES_URL="https://api.buildkite.com/v2/organizations/elastic/ COVERAGE_FORMAT="generic" COVERAGE_OPTIONS="--test-coverage --coverage-format=${COVERAGE_FORMAT}" +FATAL_ERROR="Fatal Error" + running_on_buildkite() { if [[ "${BUILDKITE:-"false"}" == "true" ]]; then return 0 @@ -509,9 +511,15 @@ prepare_stack() { fi if [ "${STACK_LOGSDB_ENABLED:-false}" == "true" ]; then + echoerr "- Enable LogsDB" args="${args} -U stack.logsdb_enabled=true" fi + if [ "${ELASTIC_SUBSCRIPTION:-""}" != "" ]; then + echoerr "- Set Subscription ${ELASTIC_SUBSCRIPTION}" + args="${args} -U stack.elastic_subscription=${ELASTIC_SUBSCRIPTION}" + fi + if [[ "${STACK_VERSION}" =~ ^7\.17 ]]; then # Required starting with STACK_VERSION 7.17.21 export ELASTIC_AGENT_IMAGE_REF_OVERRIDE="docker.elastic.co/beats/elastic-agent-complete:${STACK_VERSION}-amd64" @@ -668,6 +676,16 @@ get_to_changeset() { echo "${to}" } +is_subscription_compatible() { + local reason="" + + if ! reason=$(mage -d "${WORKSPACE}" -w . isSubscriptionCompatible) ; then + return 1 + fi + echo "${reason}" + return 0 +} + is_pr_affected() { local package="${1}" local from="${2}" @@ -698,6 +716,15 @@ is_pr_affected() { return 1 fi fi + local compatible="" + if ! compatible=$(is_subscription_compatible); then + echo "${FATAL_ERROR}" + return 1 + fi + if [[ "${compatible}" == "false" ]]; then + echo "[${package}] PR is not affected: subscription not compatible with ${ELASTIC_SUBSCRIPTION}" + return 1 + fi if [[ "${FORCE_CHECK_ALL}" == "true" ]];then echo "[${package}] PR is affected: \"force_check_all\" parameter enabled" diff --git a/.buildkite/scripts/test_integrations_with_serverless.sh b/.buildkite/scripts/test_integrations_with_serverless.sh index 85201af08b0..a87ba5be21f 100755 --- a/.buildkite/scripts/test_integrations_with_serverless.sh +++ b/.buildkite/scripts/test_integrations_with_serverless.sh @@ -43,6 +43,7 @@ if [ ! -d packages ]; then exit 1 fi +echo "--- Install requirements" add_bin_path with_yq @@ -60,6 +61,7 @@ sleep 120 echo "Done." # setting range of changesets to check differences +echo "--- Get from and to changesets" from="$(get_from_changeset)" if [[ "${from}" == "" ]]; then echo "Missing \"from\" changset". @@ -76,15 +78,28 @@ any_package_failing=0 pushd packages > /dev/null for package in $(list_all_directories); do + echo "--- [$package] check if it is required to be tested" pushd "${package}" > /dev/null + skip_package=false + failure=false if ! reason=$(is_pr_affected "${package}" "${from}" "${to}") ; then - echo "${reason}" + skip_package=true + if [[ "${reason}" == "${FATAL_ERROR}" ]]; then + failure=true + fi + fi + popd > /dev/null + if [[ "${failure}" == "true" ]]; then + echo "Unexpected failure checking ${package}" + exit 1 + fi + + echo "${reason}" + + if [[ "${skip_package}" == "true" ]]; then echo "- ${reason}" >> "${SKIPPED_PACKAGES_FILE_PATH}" - popd > /dev/null continue fi - echo "${reason}" - popd > /dev/null if ! process_package "${package}" "${FAILED_PACKAGES_FILE_PATH}" ; then any_package_failing=1 @@ -94,10 +109,12 @@ popd > /dev/null if running_on_buildkite ; then if [ -f "${SKIPPED_PACKAGES_FILE_PATH}" ]; then + echo "--- Create Skip Buildkite annotation" create_collapsed_annotation "Skipped packages in ${SERVERLESS_PROJECT}" "${SKIPPED_PACKAGES_FILE_PATH}" "info" "ctx-skipped-packages-${SERVERLESS_PROJECT}" fi if [ -f "${FAILED_PACKAGES_FILE_PATH}" ]; then + echo "--- Create Failed Buildkite annotation" create_collapsed_annotation "Failed packages in ${SERVERLESS_PROJECT}" "${FAILED_PACKAGES_FILE_PATH}" "error" "ctx-failed-packages-${SERVERLESS_PROJECT}" fi fi diff --git a/.buildkite/scripts/trigger_integrations_in_parallel.sh b/.buildkite/scripts/trigger_integrations_in_parallel.sh index 09372ec11f8..acb1a389a4c 100755 --- a/.buildkite/scripts/trigger_integrations_in_parallel.sh +++ b/.buildkite/scripts/trigger_integrations_in_parallel.sh @@ -4,8 +4,10 @@ source .buildkite/scripts/common.sh set -euo pipefail +echo "--- Install requirements" add_bin_path with_yq +with_mage pushd packages > /dev/null PACKAGE_LIST=$(list_all_directories) @@ -22,8 +24,8 @@ steps: EOF # Get from and to changesets to avoid repeating the same queries for each package - # setting range of changesets to check differences +echo "--- Get from and to changesets" from="$(get_from_changeset)" if [[ "${from}" == "" ]]; then echo "Missing \"from\" changset". @@ -51,15 +53,24 @@ packages_to_test=0 for package in ${PACKAGE_LIST}; do # check if needed to create an step for this package + echo "--- [$package] check if it is required to be tested" pushd "packages/${package}" > /dev/null skip_package="false" + failure="false" if ! reason=$(is_pr_affected "${package}" "${from}" "${to}") ; then skip_package="true" + if [[ "${reason}" == "${FATAL_ERROR}" ]]; then + failure=true + fi fi - echoerr "${reason}" popd > /dev/null + if [[ "${failure}" == "true" ]]; then + echo "Unexpected failure checking ${package}" + exit 1 + fi - if [[ "$skip_package" == "true" ]] ; then + echoerr "${reason}" + if [[ "${skip_package}" == "true" ]] ; then continue fi @@ -87,8 +98,10 @@ EOF done if [ ${packages_to_test} -eq 0 ]; then + echo "--- Create Buildkite annotation no packages to be tested" buildkite-agent annotate "No packages to be tested" --context "ctx-no-packages" --style "warning" exit 0 fi +echo "--- Upload Buildkite pipeline" cat ${PIPELINE_FILE} | buildkite-agent pipeline upload diff --git a/dev/citools/packagemanifest.go b/dev/citools/packagemanifest.go new file mode 100644 index 00000000000..7c2c61ca9e2 --- /dev/null +++ b/dev/citools/packagemanifest.go @@ -0,0 +1,48 @@ +// 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 citools + +import ( + "fmt" + + "github.com/elastic/go-ucfg" + "github.com/elastic/go-ucfg/yaml" +) + +// kibanaConditions defines conditions for Kibana (e.g. required version). +type kibanaConditions struct { + Version string `config:"version" json:"version" yaml:"version"` +} + +// elasticConditions defines conditions related to Elastic subscriptions or partnerships. +type elasticConditions struct { + Subscription string `config:"subscription" json:"subscription" yaml:"subscription"` +} + +// conditions define requirements for different parts of the Elastic stack. +type conditions struct { + Kibana kibanaConditions `config:"kibana" json:"kibana" yaml:"kibana"` + Elastic elasticConditions `config:"elastic" json:"elastic" yaml:"elastic"` +} + +type packageManifest struct { + Name string `config:"name" json:"name" yaml:"name"` + License string `config:"license" json:"license" yaml:"license"` + Conditions conditions `config:"conditions" json:"conditions" yaml:"conditions"` +} + +func readPackageManifest(path string) (*packageManifest, error) { + cfg, err := yaml.NewConfigWithFile(path, ucfg.PathSep(".")) + if err != nil { + return nil, fmt.Errorf("reading file failed (path: %s): %w", path, err) + } + + var manifest packageManifest + err = cfg.Unpack(&manifest) + if err != nil { + return nil, fmt.Errorf("unpacking package manifest failed (path: %s): %w", path, err) + } + return &manifest, nil +} diff --git a/dev/citools/subscription.go b/dev/citools/subscription.go new file mode 100644 index 00000000000..a14169df68d --- /dev/null +++ b/dev/citools/subscription.go @@ -0,0 +1,47 @@ +// 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 citools + +import ( + "fmt" +) + +func packageSubscription(path string) (string, error) { + manifest, err := readPackageManifest(path) + if err != nil { + return "", err + } + + packageSubscription := manifest.Conditions.Elastic.Subscription + if packageSubscription == "" { + packageSubscription = manifest.License + } + if packageSubscription == "" { + packageSubscription = "basic" + } + + return packageSubscription, nil +} + +func IsSubscriptionCompatible(stackSubscription, path string) (bool, error) { + pkgSubscription, err := packageSubscription(path) + if err != nil { + return false, fmt.Errorf("failed to read subscription from manifest: %w", err) + } + + if stackSubscription == "trial" { + // All subscriptions supported + return true, nil + } + + if stackSubscription == "basic" { + if pkgSubscription != "basic" { + return false, nil + } + return true, nil + } + + return false, fmt.Errorf("unknown subscription %s", stackSubscription) +} diff --git a/dev/citools/subscription_test.go b/dev/citools/subscription_test.go new file mode 100644 index 00000000000..08d86754513 --- /dev/null +++ b/dev/citools/subscription_test.go @@ -0,0 +1,180 @@ +// 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 citools + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestPackageSubscription(t *testing.T) { + cases := []struct { + title string + contents string + expected string + }{ + { + title: "Subscription field", + contents: `name: "subscription" +conditions: + elastic: + subscription: foo +`, + expected: "foo", + }, + { + title: "Dotted Subscription field", + contents: `name: "subscription" +conditions: + elastic.subscription: dotted +`, + expected: "dotted", + }, + { + title: "Deprecated Subscription field", + contents: `name: "subscription" +license: deprecated +`, + expected: "deprecated", + }, + { + title: "No Subscription field", + contents: `name: "subscription" +`, + expected: "basic", + }, + } + + for _, c := range cases { + t.Run(c.title, func(t *testing.T) { + directory := t.TempDir() + pkgManifestPath := filepath.Join(directory, "manifest.yml") + err := os.WriteFile(pkgManifestPath, []byte(c.contents), 0o644) + require.NoError(t, err) + pkgSubscription, err := packageSubscription(pkgManifestPath) + require.NoError(t, err) + assert.Equal(t, c.expected, pkgSubscription) + }) + } +} + +func TestIsSubscriptionCompatible(t *testing.T) { + cases := []struct { + title string + contents string + stackSubscription string + expectedError bool + supported bool + }{ + { + title: "Trial with Basic Subscription field", + stackSubscription: "trial", + contents: `name: "subscription" +conditions: + elastic: + subscription: basic +`, + expectedError: false, + supported: true, + }, + { + title: "Trial with Enterprise Subscription", + stackSubscription: "trial", + contents: `name: "subscription" +conditions: + elastic: + subscription: enterprise +`, + expectedError: false, + supported: true, + }, + { + title: "Trial with Platinum Subscription", + stackSubscription: "trial", + contents: `name: "subscription" +conditions: + elastic: + subscription: platinum +`, + expectedError: false, + supported: true, + }, + { + title: "Trial with Platinum Subscription", + stackSubscription: "trial", + contents: `name: "subscription" +conditions: + elastic: + subscription: platinum +`, + expectedError: false, + supported: true, + }, + { + title: "Basic with Basic Subscription field", + stackSubscription: "basic", + contents: `name: "subscription" +conditions: + elastic: + subscription: basic +`, + expectedError: false, + supported: true, + }, + { + title: "Basic with Enterprise Subscription", + stackSubscription: "basic", + contents: `name: "subscription" +conditions: + elastic: + subscription: enterprise +`, + expectedError: false, + supported: false, + }, + { + title: "Basic with Platinum Subscription", + stackSubscription: "basic", + contents: `name: "subscription" +conditions: + elastic: + subscription: platinum +`, + expectedError: false, + supported: false, + }, + { + title: "Unknown Stack Subscription", + stackSubscription: "other", + contents: `name: "subscription" +conditions: + elastic: + subscription: platinum +`, + expectedError: true, + supported: false, + }, + } + + for _, c := range cases { + t.Run(c.title, func(t *testing.T) { + directory := t.TempDir() + pkgManifestPath := filepath.Join(directory, "manifest.yml") + err := os.WriteFile(pkgManifestPath, []byte(c.contents), 0o644) + require.NoError(t, err) + supported, err := IsSubscriptionCompatible(c.stackSubscription, pkgManifestPath) + if c.expectedError { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, c.supported, supported) + } + }) + } +} diff --git a/dev/testsreporter/_static/summary.tmpl b/dev/testsreporter/_static/summary.tmpl index e2dbeca3453..8eaff258350 100644 --- a/dev/testsreporter/_static/summary.tmpl +++ b/dev/testsreporter/_static/summary.tmpl @@ -1,5 +1,7 @@ {{ if ne .stackVersion "" -}} - Stack version: {{ .stackVersion }} +{{ else -}} +- Stack version: Same as in Pull Request builds {{ end -}} {{ if .serverless -}} - Serverless: {{ .serverlessProject}} @@ -7,6 +9,9 @@ {{ if .logsDB -}} - LogsDB: enabled {{ end -}} +{{ if ne .subscription "" -}} +- Subscription: {{ .subscription }} +{{ end -}} {{ if and (ne .packageName "") (ne .packageName nil) -}} - Package: {{ .packageName }} - Failing test: {{ .testName }} diff --git a/dev/testsreporter/builderror.go b/dev/testsreporter/builderror.go index c815dd578a2..ca97b1fc5d2 100644 --- a/dev/testsreporter/builderror.go +++ b/dev/testsreporter/builderror.go @@ -24,6 +24,7 @@ type buildErrorOptions struct { ServerlessProject string LogsDB bool StackVersion string + Subscription string Packages []string BuildURL string PreviousBuilds []string @@ -40,6 +41,7 @@ func newBuildError(options buildErrorOptions) (*buildError, error) { serverlessProject: options.ServerlessProject, logsDB: options.LogsDB, stackVersion: options.StackVersion, + subscription: options.Subscription, errorLinks: errorLinks{ firstBuild: options.BuildURL, closedIssueURL: options.ClosedIssueURL, @@ -82,7 +84,11 @@ func (b *buildError) SummaryData() map[string]any { } func (b *buildError) DescriptionData() map[string]any { - return b.errorLinks.Data() + data := b.SummaryData() + for key, value := range b.errorLinks.Data() { + data[key] = value + } + return data } func (b *buildError) Labels() []string { diff --git a/dev/testsreporter/dataerror.go b/dev/testsreporter/dataerror.go index d14e525c78c..b9b82c5312b 100644 --- a/dev/testsreporter/dataerror.go +++ b/dev/testsreporter/dataerror.go @@ -15,6 +15,7 @@ type dataError struct { serverlessProject string logsDB bool stackVersion string + subscription string } func (d *dataError) String() string { @@ -31,6 +32,11 @@ func (d *dataError) String() string { sb.WriteString(d.stackVersion) sb.WriteString("] ") } + if d.subscription != "" { + sb.WriteString("[Subscription ") + sb.WriteString(d.subscription) + sb.WriteString("] ") + } return sb.String() } @@ -40,5 +46,6 @@ func (d *dataError) Data() map[string]any { "serverless": d.serverless, "serverlessProject": d.serverlessProject, "logsDB": d.logsDB, + "subscription": d.subscription, } } diff --git a/dev/testsreporter/format_test.go b/dev/testsreporter/format_test.go index 71fdddeaa2d..88b0ded576b 100644 --- a/dev/testsreporter/format_test.go +++ b/dev/testsreporter/format_test.go @@ -91,7 +91,8 @@ func TestSummary(t *testing.T) { }, teams: []string{"team1", "team2"}, }, - expected: `- Serverless: observability + expected: `- Stack version: Same as in Pull Request builds +- Serverless: observability - Package: foo - Failing test: mytest - DataStream: data @@ -113,7 +114,8 @@ func TestSummary(t *testing.T) { }, teams: []string{"team1", "team2"}, }, - expected: `- Serverless: observability + expected: `- Stack version: Same as in Pull Request builds +- Serverless: observability - Package: foo - Failing test: mytest - Owners: @@ -133,7 +135,8 @@ func TestSummary(t *testing.T) { }, teams: []string{"team1", "team2"}, }, - expected: `- LogsDB: enabled + expected: `- Stack version: Same as in Pull Request builds +- LogsDB: enabled - Package: foo - Failing test: mytest - Owners: @@ -156,6 +159,53 @@ func TestSummary(t *testing.T) { teams: []string{"team1"}, }, expected: `- Stack version: 8.16 +- Packages: + - foo + - bar +- Owners: + - team1 +`, + }, + { + title: "summary with basic license", + resultError: &buildError{ + dataError: dataError{ + logsDB: false, + serverless: false, + subscription: "basic", + stackVersion: "8.16", + }, + packages: []string{ + "foo", + "bar", + }, + teams: []string{"team1"}, + }, + expected: `- Stack version: 8.16 +- Subscription: basic +- Packages: + - foo + - bar +- Owners: + - team1 +`, + }, + { + title: "summary with basic license no stack", + resultError: &buildError{ + dataError: dataError{ + logsDB: false, + serverless: false, + subscription: "basic", + }, + packages: []string{ + "foo", + "bar", + }, + teams: []string{"team1"}, + }, + expected: `- Stack version: Same as in Pull Request builds +- Subscription: basic - Packages: - foo - bar @@ -363,6 +413,47 @@ Latest 2 failed builds: +Latest issue closed for the same test: http://issue.link/1 + +First build failed: http://link/1 + +Latest failed builds: +- http://link/2 +- http://link/3 +`, + }, + { + title: "description basic license no stack", + resultError: &buildError{ + dataError: dataError{ + logsDB: false, + serverless: false, + subscription: "basic", + errorLinks: errorLinks{ + firstBuild: "http://link/1", + previousBuilds: []string{ + "http://link/2", + "http://link/3", + }, + closedIssueURL: "http://issue.link/1", + }, + }, + packages: []string{ + "foo", + "bar", + }, + teams: []string{"team1"}, + }, + expected: `- Stack version: Same as in Pull Request builds +- Subscription: basic +- Packages: + - foo + - bar +- Owners: + - team1 + + + Latest issue closed for the same test: http://issue.link/1 First build failed: http://link/1 diff --git a/dev/testsreporter/packageerror.go b/dev/testsreporter/packageerror.go index 09f6e649f8f..dc6b873eeb5 100644 --- a/dev/testsreporter/packageerror.go +++ b/dev/testsreporter/packageerror.go @@ -24,6 +24,7 @@ type packageErrorOptions struct { ServerlessProject string LogsDB bool StackVersion string + Subscription string BuildURL string TestCase testCase CodeownersPath string @@ -42,6 +43,7 @@ func newPackageError(options packageErrorOptions) (*packageError, error) { serverlessProject: options.ServerlessProject, logsDB: options.LogsDB, stackVersion: options.StackVersion, + subscription: options.Subscription, errorLinks: errorLinks{ firstBuild: options.BuildURL, closedIssueURL: options.ClosedIssueURL, @@ -101,7 +103,10 @@ func (p *packageError) SummaryData() map[string]any { } func (p *packageError) DescriptionData() map[string]any { - data := p.errorLinks.Data() + data := p.SummaryData() + for key, value := range p.errorLinks.Data() { + data[key] = value + } data["failure"] = truncateText(p.Failure, defaultMaxLengthMessages) data["error"] = truncateText(p.Error, defaultMaxLengthMessages) return data diff --git a/dev/testsreporter/packageerror_test.go b/dev/testsreporter/packageerror_test.go index 55c0abdd3a9..8fc1b304803 100644 --- a/dev/testsreporter/packageerror_test.go +++ b/dev/testsreporter/packageerror_test.go @@ -25,6 +25,7 @@ func TestNewPackageError(t *testing.T) { ServerlessProject: "observability", LogsDB: false, StackVersion: "8.16.0-SNAPSHOT", + Subscription: "basic", BuildURL: "https://buildkite.com/elastic/integrations/build/1", TestCase: testCase{ Name: "failing test", @@ -40,6 +41,7 @@ func TestNewPackageError(t *testing.T) { serverlessProject: "observability", logsDB: false, stackVersion: "8.16.0-SNAPSHOT", + subscription: "basic", errorLinks: errorLinks{ firstBuild: "https://buildkite.com/elastic/integrations/build/1", }, diff --git a/dev/testsreporter/testsreporter.go b/dev/testsreporter/testsreporter.go index 8850b7459fc..aec29d7b52b 100644 --- a/dev/testsreporter/testsreporter.go +++ b/dev/testsreporter/testsreporter.go @@ -20,6 +20,7 @@ type CheckOptions struct { ServerlessProject string LogsDB bool StackVersion string + Subscription string BuildURL string CodeownersPath string @@ -67,6 +68,7 @@ func Check(ctx context.Context, resultsPath string, options CheckOptions) error ServerlessProject: options.ServerlessProject, LogsDB: options.LogsDB, StackVersion: options.StackVersion, + Subscription: options.Subscription, BuildURL: options.BuildURL, Packages: packages, }) @@ -122,6 +124,7 @@ func errorsFromTests(resultsPath string, options CheckOptions) ([]*packageError, ServerlessProject: options.ServerlessProject, LogsDB: options.LogsDB, StackVersion: options.StackVersion, + Subscription: options.Subscription, BuildURL: options.BuildURL, TestCase: c, CodeownersPath: options.CodeownersPath, diff --git a/go.mod b/go.mod index be2d2b0d9e8..04f871d9e34 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/cli/go-gh/v2 v2.12.0 github.com/elastic/elastic-package v0.110.2 github.com/elastic/go-licenser v0.4.2 + github.com/elastic/go-ucfg v0.8.8 github.com/elastic/package-registry v1.28.0 github.com/magefile/mage v1.15.0 github.com/pkg/errors v0.9.1 @@ -65,7 +66,6 @@ require ( github.com/elastic/go-elasticsearch/v7 v7.17.10 // indirect github.com/elastic/go-resource v0.2.0 // indirect github.com/elastic/go-sysinfo v1.9.0 // indirect - github.com/elastic/go-ucfg v0.8.8 // indirect github.com/elastic/go-windows v1.0.1 // indirect github.com/elastic/gojsonschema v1.2.1 // indirect github.com/elastic/kbncontent v0.1.4 // indirect diff --git a/magefile.go b/magefile.go index ad670bbea3d..0a0ef0e4839 100644 --- a/magefile.go +++ b/magefile.go @@ -18,6 +18,7 @@ import ( "github.com/magefile/mage/sh" "github.com/pkg/errors" + "github.com/elastic/integrations/dev/citools" "github.com/elastic/integrations/dev/codeowners" "github.com/elastic/integrations/dev/coverage" "github.com/elastic/integrations/dev/testsreporter" @@ -155,6 +156,7 @@ func ReportFailedTests(ctx context.Context, testResultsFolder string) error { dryRunEnv := os.Getenv("DRY_RUN") serverlessProjectEnv := os.Getenv("SERVERLESS_PROJECT") buildURL := os.Getenv("BUILDKITE_BUILD_URL") + subscription := os.Getenv("ELASTIC_SUBSCRIPTION") serverless := false if serverlessEnv != "" { @@ -202,6 +204,7 @@ func ReportFailedTests(ctx context.Context, testResultsFolder string) error { ServerlessProject: serverlessProjectEnv, LogsDB: logsDBEnabled, StackVersion: stackVersion, + Subscription: subscription, BuildURL: buildURL, MaxPreviousLinks: defaultPreviousLinksNumber, MaxTestsReported: maxIssues, @@ -210,3 +213,23 @@ func ReportFailedTests(ctx context.Context, testResultsFolder string) error { } return testsreporter.Check(ctx, testResultsFolder, options) } + +// IsSubscriptionCompatible checks whether or not the package in the current directory allows to run with the given subscription (ELASTIC_SUBSCRIPTION env var). +func IsSubscriptionCompatible() error { + subscription := os.Getenv("ELASTIC_SUBSCRIPTION") + if subscription == "" { + fmt.Println("true") + return nil + } + + supported, err := citools.IsSubscriptionCompatible(subscription, "manifest.yml") + if err != nil { + return err + } + if supported { + fmt.Println("true") + return nil + } + fmt.Println("false") + return nil +}