Skip to content

Commit

Permalink
feat: convert magento2 version to semver (fixes #71)
Browse files Browse the repository at this point in the history
  • Loading branch information
janosmiko committed Oct 14, 2024
1 parent e7055c3 commit f17eeee
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.6.10
v0.6.11
33 changes: 24 additions & 9 deletions internal/logic/bootstrapMagento2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logic

import (
"fmt"
"regexp"
"strings"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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}"
}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")
}
}
Expand All @@ -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),
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f17eeee

Please sign in to comment.