Skip to content

Commit

Permalink
Move steplib step activator from CLI to stepman
Browse files Browse the repository at this point in the history
  • Loading branch information
ofalvai committed Jun 28, 2024
1 parent 86270fe commit c5b687c
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 112 deletions.
91 changes: 13 additions & 78 deletions cli/step_activator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"path/filepath"

"github.com/bitrise-io/bitrise/log"
"github.com/bitrise-io/bitrise/tools"
"github.com/bitrise-io/go-utils/command/git"
"github.com/bitrise-io/go-utils/pointers"
"github.com/bitrise-io/stepman/activator"
stepmanModels "github.com/bitrise-io/stepman/models"
"github.com/bitrise-io/stepman/stepid"
Expand Down Expand Up @@ -79,87 +77,24 @@ func (a stepActivator) activateStep(
return "", "", false, err
}
} else if stepIDData.SteplibSource != "" {
stepInfo, didUpdate, err := activateStepLibStep(stepIDData, stepDir, stepYMLPth, isStepLibUpdated, isSteplibOfflineMode)
didStepLibUpdate = didUpdate

stepInfoPtr.ID = stepInfo.ID
if stepInfoPtr.Step.Title == nil || *stepInfoPtr.Step.Title == "" {
stepInfoPtr.Step.Title = pointers.NewStringPtr(stepInfo.ID)
}
stepInfoPtr.Version = stepInfo.Version
stepInfoPtr.LatestVersion = stepInfo.LatestVersion
stepInfoPtr.OriginalVersion = stepInfo.OriginalVersion
stepInfoPtr.GroupInfo = stepInfo.GroupInfo

activatedStep, err := activator.ActivateSteplibRefStep(
stepmanLogger,
stepIDData,
stepDir,
workDir,
isStepLibUpdated,
isSteplibOfflineMode,
stepInfoPtr,
)
if err != nil {
return "", "", didStepLibUpdate, err
return "", "", false, fmt.Errorf("activate steplib step reference: %w", err)
}

stepYMLPth = activatedStep.StepYMLPath
origStepYMLPth = activatedStep.OrigStepYMLPath
} else {
return "", "", didStepLibUpdate, fmt.Errorf("invalid stepIDData: no SteplibSource or LocalPath defined (%v)", stepIDData)
}

return stepYMLPth, origStepYMLPth, didStepLibUpdate, nil
}

func activateStepLibStep(stepIDData stepid.CanonicalID, destination, stepYMLCopyPth string, isStepLibUpdated bool, isOfflineMode bool) (stepmanModels.StepInfoModel, bool, error) {
didStepLibUpdate := false

log.Debugf("[BITRISE_CLI] - Steplib (%s) step (id:%s) (version:%s) found, activating step", stepIDData.SteplibSource, stepIDData.IDorURI, stepIDData.Version)
if err := tools.StepmanSetup(stepIDData.SteplibSource); err != nil {
return stepmanModels.StepInfoModel{}, false, err
}

versionConstraint, err := stepmanModels.ParseRequiredVersion(stepIDData.Version)
if err != nil {
return stepmanModels.StepInfoModel{}, false,
fmt.Errorf("activating step (%s) from source (%s) failed, invalid version specified: %s", stepIDData.IDorURI, stepIDData.SteplibSource, err)
}
if versionConstraint.VersionLockType == stepmanModels.InvalidVersionConstraint {
return stepmanModels.StepInfoModel{}, false,
fmt.Errorf("activating step (%s) from source (%s) failed, version constraint is invalid", stepIDData.IDorURI, stepIDData.SteplibSource)
}

isStepLibUpdateNeeded := (versionConstraint.VersionLockType == stepmanModels.Latest) ||
(versionConstraint.VersionLockType == stepmanModels.MinorLocked) ||
(versionConstraint.VersionLockType == stepmanModels.MajorLocked)
if !isStepLibUpdated && isStepLibUpdateNeeded && !isOfflineMode {
log.Print("Step uses latest version, updating StepLib...")
if err := tools.StepmanUpdate(stepIDData.SteplibSource); err != nil {
log.Warnf("Step version constraint is latest or version locked, but failed to update StepLib, err: %s", err)
} else {
didStepLibUpdate = true
}
}

info, err := tools.StepmanStepInfo(stepIDData.SteplibSource, stepIDData.IDorURI, stepIDData.Version)
if err != nil {
if isStepLibUpdated || isOfflineMode {
return stepmanModels.StepInfoModel{}, didStepLibUpdate, fmt.Errorf("stepman JSON steplib step info failed: %s", err)
}

// May StepLib should be updated
log.Infof("Step info not found in StepLib (%s) -- Updating ...", stepIDData.SteplibSource)
if err := tools.StepmanUpdate(stepIDData.SteplibSource); err != nil {
return stepmanModels.StepInfoModel{}, didStepLibUpdate, err
}

didStepLibUpdate = true

info, err = tools.StepmanStepInfo(stepIDData.SteplibSource, stepIDData.IDorURI, stepIDData.Version)
if err != nil {
return stepmanModels.StepInfoModel{}, didStepLibUpdate, fmt.Errorf("stepman JSON steplib step info failed: %s", err)
}
}

if info.Step.Title == nil || *info.Step.Title == "" {
info.Step.Title = pointers.NewStringPtr(info.ID)
}
info.OriginalVersion = stepIDData.Version

if err := tools.StepmanActivate(stepIDData.SteplibSource, stepIDData.IDorURI, info.Version, destination, stepYMLCopyPth, isOfflineMode); err != nil {
return stepmanModels.StepInfoModel{}, didStepLibUpdate, err
}
log.Debugf("[BITRISE_CLI] - Step activated: (ID:%s) (version:%s)", stepIDData.IDorURI, stepIDData.Version)

return info, didStepLibUpdate, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/bitrise-io/go-utils v1.0.13
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.21
github.com/bitrise-io/goinp v0.0.0-20240103152431-054ed78518ef
github.com/bitrise-io/stepman v0.0.0-20240628113544-1818e03ce8d2
github.com/bitrise-io/stepman v0.0.0-20240628133621-c164db9c80d6
github.com/gofrs/uuid v4.3.1+incompatible
github.com/hashicorp/go-version v1.4.0
github.com/ryanuber/go-glob v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.21 h1:iwNnwOGg8VP8eqhse68Fxt5ZnfE
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.21/go.mod h1:Laih4ji980SQkRgdnMCH0g4u2GZI/5nnbqmYT9UfKFQ=
github.com/bitrise-io/goinp v0.0.0-20240103152431-054ed78518ef h1:R5FOa8RHjqZwMN9g1FQ8W7nXxQAG7iwq1Cw+mUk5S9A=
github.com/bitrise-io/goinp v0.0.0-20240103152431-054ed78518ef/go.mod h1:27ldH2bkCdYN5CEJ6x92EK+gkd5EcDBkA7dMrSKQFYU=
github.com/bitrise-io/stepman v0.0.0-20240628113544-1818e03ce8d2 h1:Qi2Ak2p0ubQzlQqplL6hRXKZ1LnhpBabfrBj9KN44bo=
github.com/bitrise-io/stepman v0.0.0-20240628113544-1818e03ce8d2/go.mod h1:netRLDQD95IzWZbzmn7CBolzNqH1tErRKS31BrZKt9s=
github.com/bitrise-io/stepman v0.0.0-20240628133621-c164db9c80d6 h1:vE/XI/1v5l0jthEIFoBksa84cGsXsZGVI6Lh7ZUgyAs=
github.com/bitrise-io/stepman v0.0.0-20240628133621-c164db9c80d6/go.mod h1:netRLDQD95IzWZbzmn7CBolzNqH1tErRKS31BrZKt9s=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c5b687c

Please sign in to comment.