Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 4579092

Browse files
authored
avoid aliases if no major.minor format (#2501)
* Use alias only if two digits release * fix regex
1 parent 66ccdec commit 4579092

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

internal/common/defaults.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package common
66

77
import (
8+
"regexp"
9+
810
"github.com/elastic/e2e-testing/internal/shell"
911
"github.com/elastic/e2e-testing/pkg/downloads"
1012
log "github.com/sirupsen/logrus"
@@ -64,6 +66,10 @@ var Provider = "docker"
6466
// It can be overriden by STACK_VERSION env var
6567
var StackVersion = BeatVersionBase
6668

69+
// The compiled version of the regex created at init() is cached here so it
70+
// only needs to be created once.
71+
var versionRegex *regexp.Regexp
72+
6773
func init() {
6874
DeveloperMode = shell.GetEnvBool("DEVELOPER_MODE")
6975
if DeveloperMode {
@@ -79,6 +85,8 @@ func init() {
7985
"apm-environment": shell.GetEnv("ELASTIC_APM_ENVIRONMENT", "local"),
8086
}).Info("Current execution will be instrumented 🛠")
8187
}
88+
89+
versionRegex = regexp.MustCompile(`^([0-9]+)(\.[0-9]+)(-SNAPSHOT)?$`)
8290
}
8391

8492
// InitVersions initialise default versions. We do not want to do it in the init phase
@@ -96,15 +104,23 @@ func InitVersions() {
96104

97105
BeatVersion = shell.GetEnv("BEAT_VERSION", BeatVersionBase)
98106

99-
// check if version is an alias
100-
v, err = downloads.GetElasticArtifactVersion(BeatVersion)
101-
if err != nil {
107+
// check if version is an alias. For compatibility versions let's
108+
// support aliases in the format major.minor
109+
m := versionRegex.FindStringSubmatch(BeatVersion)
110+
if m != nil {
111+
v, err = downloads.GetElasticArtifactVersion(BeatVersion)
112+
if err != nil {
113+
log.WithFields(log.Fields{
114+
"error": err,
115+
"version": BeatVersion,
116+
}).Fatal("Failed to get Beat version, aborting")
117+
}
118+
BeatVersion = v
119+
} else {
102120
log.WithFields(log.Fields{
103-
"error": err,
104121
"version": BeatVersion,
105-
}).Fatal("Failed to get Beat version, aborting")
122+
}).Trace("Version is not an alias.")
106123
}
107-
BeatVersion = v
108124

109125
// detects if the BeatVersion is set by the GITHUB_CHECK_SHA1 variable
110126
fallbackVersion := BeatVersionBase

0 commit comments

Comments
 (0)