diff --git a/cli/run_util.go b/cli/run_util.go index caec9410..52e4f038 100644 --- a/cli/run_util.go +++ b/cli/run_util.go @@ -278,11 +278,9 @@ func (r WorkflowRunner) activateStep( stepInfoPtr := stepmanModels.StepInfoModel{} compositeStepIDStr := stepID - workflowStep := step - stepInfoPtr.ID = compositeStepIDStr - if workflowStep.Title != nil && *workflowStep.Title != "" { - stepInfoPtr.Step.Title = pointers.NewStringPtr(*workflowStep.Title) + if step.Title != nil && *step.Title != "" { + stepInfoPtr.Step.Title = pointers.NewStringPtr(*step.Title) } else { stepInfoPtr.Step.Title = pointers.NewStringPtr(compositeStepIDStr) } @@ -312,7 +310,7 @@ func (r WorkflowRunner) activateStep( } activator := newStepActivator() - stepYMLPth, origStepYMLPth, didStepLibUpdate, err := activator.activateStep(stepIDData, isStepLibUpdated, stepDir, configs.BitriseWorkDirPath, &workflowStep, &stepInfoPtr, isStepLibOfflineMode) + stepYMLPth, origStepYMLPth, didStepLibUpdate, err := activator.activateStep(stepIDData, isStepLibUpdated, stepDir, configs.BitriseWorkDirPath, &stepInfoPtr, isStepLibOfflineMode) if didStepLibUpdate { buildRunResults.StepmanUpdates[stepIDData.SteplibSource]++ } @@ -321,7 +319,7 @@ func (r WorkflowRunner) activateStep( } // Fill step info with default step info, if exist - mergedStep := workflowStep + mergedStep := step if stepYMLPth != "" { specStep, err := bitrise.ReadSpecStep(stepYMLPth) log.Debugf("Spec read from YML: %#v", specStep) @@ -336,7 +334,7 @@ func (r WorkflowRunner) activateStep( return newActivateStepResult(stepmanModels.StepModel{}, stepInfoPtr, stepIDData, stepDir, err) } - mergedStep, err = models.MergeStepWith(specStep, workflowStep) + mergedStep, err = models.MergeStepWith(specStep, step) if err != nil { return newActivateStepResult(stepmanModels.StepModel{}, stepInfoPtr, stepIDData, stepDir, err) } diff --git a/cli/step_activator.go b/cli/step_activator.go index 42889fce..2a0b79f7 100644 --- a/cli/step_activator.go +++ b/cli/step_activator.go @@ -6,7 +6,6 @@ import ( "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" @@ -25,7 +24,6 @@ func (a stepActivator) activateStep( isStepLibUpdated bool, stepDir string, // $TMPDIR/bitrise/step_src workDir string, // $TMPDIR/bitrise - workflowStep *stepmanModels.StepModel, stepInfoPtr *stepmanModels.StepInfoModel, isSteplibOfflineMode bool, ) (stepYMLPth string, origStepYMLPth string, didStepLibUpdate bool, err error) { @@ -62,22 +60,6 @@ func (a stepActivator) activateStep( stepYMLPth = activatedStep.StepYMLPath origStepYMLPth = activatedStep.OrigStepYMLPath - } else if stepIDData.SteplibSource == "_" { - log.Debugf("[BITRISE_CLI] - Steplib independent step, with direct git uri: (uri:%s) (tag-or-branch:%s)", stepIDData.IDorURI, stepIDData.Version) - - // StepLib independent steps are completely defined in the workflow - stepYMLPth = "" - if err := workflowStep.FillMissingDefaults(); err != nil { - return "", "", false, err - } - - repo, err := git.New(stepDir) - if err != nil { - return "", "", false, err - } - if err := repo.CloneTagOrBranch(stepIDData.IDorURI, stepIDData.Version).Run(); err != nil { - return "", "", false, err - } } else if stepIDData.SteplibSource != "" { stepInfo, didUpdate, err := activateStepLibStep(stepIDData, stepDir, stepYMLPth, isStepLibUpdated, isSteplibOfflineMode) didStepLibUpdate = didUpdate diff --git a/go.mod b/go.mod index c295cefa..dc68bcbf 100644 --- a/go.mod +++ b/go.mod @@ -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-20240628133929-e1775d705289 + github.com/bitrise-io/stepman v0.0.0-20240628140527-5e941cdb67a1 github.com/gofrs/uuid v4.3.1+incompatible github.com/hashicorp/go-version v1.4.0 github.com/ryanuber/go-glob v1.0.0 diff --git a/go.sum b/go.sum index 290da972..49674630 100644 --- a/go.sum +++ b/go.sum @@ -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-20240628133929-e1775d705289 h1:XOD5XCMKz0l6ScKLOVHknrXxiPV4GTD6Vd4w6viaYJk= -github.com/bitrise-io/stepman v0.0.0-20240628133929-e1775d705289/go.mod h1:netRLDQD95IzWZbzmn7CBolzNqH1tErRKS31BrZKt9s= +github.com/bitrise-io/stepman v0.0.0-20240628140527-5e941cdb67a1 h1:/hVIftPENx0k6JuXDgPbpWXCx1Lm4GbvsUVfgr6618A= +github.com/bitrise-io/stepman v0.0.0-20240628140527-5e941cdb67a1/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= diff --git a/vendor/github.com/bitrise-io/stepman/activator/activator.go b/vendor/github.com/bitrise-io/stepman/activator/activator.go index e8ea6420..dbfe5720 100644 --- a/vendor/github.com/bitrise-io/stepman/activator/activator.go +++ b/vendor/github.com/bitrise-io/stepman/activator/activator.go @@ -8,5 +8,9 @@ type ActivatedStep struct { // but I don't want to blow up my PR with that change. OrigStepYMLPath string + // TODO: is this always the same as the `activatedStepDir` function param in all activations? Can we clean this up? WorkDir string + + // DidStepLibUpdate indicates that the local steplib cache was updated while resolving the exact step version. + DidStepLibUpdate bool } diff --git a/vendor/github.com/bitrise-io/stepman/activator/steplib_ref.go b/vendor/github.com/bitrise-io/stepman/activator/steplib_ref.go new file mode 100644 index 00000000..69cb41ce --- /dev/null +++ b/vendor/github.com/bitrise-io/stepman/activator/steplib_ref.go @@ -0,0 +1,94 @@ +package activator + +import ( + "fmt" + "path/filepath" + + "github.com/bitrise-io/go-utils/pointers" + "github.com/bitrise-io/stepman/cli" + "github.com/bitrise-io/stepman/models" + "github.com/bitrise-io/stepman/stepid" + "github.com/bitrise-io/stepman/stepman" +) + +func ActivateSteplibRefStep( + log stepman.Logger, + id stepid.CanonicalID, + activatedStepDir string, + workDir string, + didStepLibUpdateInWorkflow bool, + isOfflineMode bool, + stepInfoPtr *models.StepInfoModel, +) (ActivatedStep, error) { + stepYMLPath := filepath.Join(workDir, "current_step.yml") + activationResult := ActivatedStep{ + StepYMLPath: stepYMLPath, + OrigStepYMLPath: "", // TODO: temporary during refactors, see definition + WorkDir: activatedStepDir, + DidStepLibUpdate: false, + } + + err := cli.Setup(id.SteplibSource, "", log) + if err != nil { + return activationResult, fmt.Errorf("setup %s: %s", id.SteplibSource, err) + } + + versionConstraint, err := models.ParseRequiredVersion(id.Version) + if err != nil { + return activationResult, err + } + if versionConstraint.VersionLockType == models.InvalidVersionConstraint { + return activationResult, fmt.Errorf("version constraint is invalid: %s %s", id.IDorURI, id.Version) + } + + if shouldUpdateStepLibForStep(versionConstraint, isOfflineMode, didStepLibUpdateInWorkflow) { + log.Infof("Step uses latest version, updating StepLib...") + _, err = stepman.UpdateLibrary(id.SteplibSource, log) + if err != nil { + log.Warnf("Step version constraint is latest or version locked, but failed to update StepLib, err: %s", err) + } else { + activationResult.DidStepLibUpdate = true + } + } + + stepInfo, err := cli.QueryStepInfoFromLibrary(id.SteplibSource, id.IDorURI, id.Version, log) + if err != nil { + return activationResult, err + } + + if stepInfo.Step.Title == nil || *stepInfo.Step.Title == "" { + stepInfo.Step.Title = pointers.NewStringPtr(stepInfo.ID) + } + stepInfo.OriginalVersion = id.Version + + err = cli.Activate(id.SteplibSource, id.IDorURI, stepInfo.Version, activatedStepDir, stepYMLPath, false, log, isOfflineMode) + if err != nil { + return activationResult, err + } + + // TODO: this is sketchy, we should clean this up, but this pointer originates in the CLI codebase + 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 + + return activationResult, nil +} + +func shouldUpdateStepLibForStep(constraint models.VersionConstraint, isOfflineMode bool, didStepLibUpdateInWorkflow bool) bool { + if isOfflineMode { + return false + } + + if didStepLibUpdateInWorkflow { + return false + } + + return (constraint.VersionLockType == models.Latest) || + (constraint.VersionLockType == models.MinorLocked) || + (constraint.VersionLockType == models.MajorLocked) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index ae95798b..b61a20cb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -45,7 +45,7 @@ github.com/bitrise-io/go-utils/v2/retryhttp # github.com/bitrise-io/goinp v0.0.0-20240103152431-054ed78518ef ## explicit; go 1.18 github.com/bitrise-io/goinp/goinp -# github.com/bitrise-io/stepman v0.0.0-20240628133929-e1775d705289 +# github.com/bitrise-io/stepman v0.0.0-20240628140527-5e941cdb67a1 ## explicit; go 1.18 github.com/bitrise-io/stepman/activator github.com/bitrise-io/stepman/cli