From f17eeee525bc580f58beb003cbf8ad5b43d58b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Mik=C3=B3?= Date: Mon, 14 Oct 2024 06:43:43 +0200 Subject: [PATCH] feat: convert magento2 version to semver (fixes #71) --- CHANGELOG.md | 6 ++++++ VERSION.txt | 2 +- internal/logic/bootstrapMagento2.go | 33 +++++++++++++++++++++-------- sonar-project.properties | 2 +- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80d3dc6e..3f11dc95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.6.11] - 2024-09-26 + +### Changed + +- Convert Magento version to semver before comparison (#71) + ## [0.6.10] - 2024-09-26 ### Changed diff --git a/VERSION.txt b/VERSION.txt index f50dea79..882307cc 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -v0.6.10 +v0.6.11 diff --git a/internal/logic/bootstrapMagento2.go b/internal/logic/bootstrapMagento2.go index 0722cebf..88addd8e 100644 --- a/internal/logic/bootstrapMagento2.go +++ b/internal/logic/bootstrapMagento2.go @@ -2,6 +2,7 @@ package logic import ( "fmt" + "regexp" "strings" "github.com/hashicorp/go-version" @@ -69,6 +70,21 @@ func (c *bootstrapper) magento2Version() *version.Version { return v } +func (c *bootstrapper) magento2SemVer() *version.Version { + v := c.magento2Version() + + // Check if the prerelease part contains "-px" where x is a number + // In that case modify the version to be "+p.x" to match semver spec + re := regexp.MustCompile(`p(\d+)`) + if re.MatchString(v.Prerelease()) { + v2 := version.Must(version.NewVersion(fmt.Sprintf("%s+p%s", v.Core(), re.FindStringSubmatch(v.Prerelease())[1]))) + + return v2 + } + + return v +} + func (c *bootstrapper) magento2VerbosityFlag() string { magentoVerbosityFlag := "-v" @@ -234,16 +250,15 @@ func (c *bootstrapper) installMagento2ConfigureAdminUser() (string, error) { } func (c *bootstrapper) installMagento2ConfigureTFA() error { - minimumMagentoVersionForMFA := version.Must(version.NewVersion("2.3.99")) - + mfaConstraints := version.MustConstraints(version.NewConstraint(">=2.4")) // For Magento 2.4.6 and above, we need to disable the Adobe IMS module as well - minimumMagentoVersionForMFAAdminAdobeImsTwoFactorAuth := version.Must(version.NewVersion("2.4.5.99")) + adobeImsConstraints := version.MustConstraints(version.NewConstraint(">=2.4.6")) - if c.magento2Version().GreaterThan(minimumMagentoVersionForMFA) && c.MagentoDisableTFA() { + if mfaConstraints.Check(c.magento2SemVer()) && c.MagentoDisableTFA() { log.Println("Disabling TFA for local development...") modules := "Magento_TwoFactorAuth" - if c.magento2Version().GreaterThan(minimumMagentoVersionForMFAAdminAdobeImsTwoFactorAuth) { + if adobeImsConstraints.Check(c.magento2SemVer()) { modules = "{Magento_AdminAdobeImsTwoFactorAuth,Magento_TwoFactorAuth}" } @@ -304,7 +319,7 @@ func (c *bootstrapper) installMagento2ConfigureSearch() error { // Above Magento 2.4 the search engine must be configured constraints := version.MustConstraints(version.NewConstraint(">=2.4")) - if constraints.Check(c.magento2Version()) { + if constraints.Check(c.magento2SemVer()) { if err := c.RunCmdEnvExec( fmt.Sprintf( "bin/magento config:set --lock-env catalog/search/engine %s", @@ -524,7 +539,7 @@ func (c *bootstrapper) buildMagento2InstallCommand() []string { // --consumers-wait-for-messages option is only available above Magento 2.4 constraints := version.MustConstraints(version.NewConstraint(">=2.4")) - if constraints.Check(c.magento2Version()) { + if constraints.Check(c.magento2SemVer()) { magentoCmdParams = append(magentoCmdParams, "--consumers-wait-for-messages=0") } } @@ -537,7 +552,7 @@ func (c *bootstrapper) buildMagento2InstallCommand() []string { } constraints := version.MustConstraints(version.NewConstraint(">=2.4")) - if c.ServiceEnabled("elasticsearch") || c.ServiceEnabled("opensearch") && constraints.Check(c.magento2Version()) { + if c.ServiceEnabled("elasticsearch") || c.ServiceEnabled("opensearch") && constraints.Check(c.magento2SemVer()) { magentoCmdParams = append( magentoCmdParams, fmt.Sprintf("--search-engine=%s", searchEngine), @@ -563,7 +578,7 @@ func (c *bootstrapper) buildMagentoSearchHost() (string, string) { // Need to specify elasticsearch7 for opensearch as Magento 2.4.6 and below // https://devdocs.magento.com/guides/v2.4/install-gde/install/cli/install-cli.html constraints := version.MustConstraints(version.NewConstraint(">=2.4.7")) - if constraints.Check(c.magento2Version()) { + if constraints.Check(c.magento2SemVer()) { log.Println("Setting search engine to openSearch") searchEngine = "opensearch" } else { diff --git a/sonar-project.properties b/sonar-project.properties index 1ac20326..c0446b40 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=rewardenv_reward sonar.organization=rewardenv # This is the name and version displayed in the SonarCloud UI. sonar.projectName=reward -sonar.projectVersion=0.6.9 +sonar.projectVersion=0.6.11 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. #sonar.sources=. # Encoding of the source code. Default is default system encoding