Skip to content

Commit

Permalink
add support for new version lock (#693)
Browse files Browse the repository at this point in the history
* add support for new version lock

* fix steplib update registration

* test activateStepLibStep

* store original and evaluated versions in the step info model

* switch to OriginalStep version

* update print test

* Adding test for unsupported version lock format.

* Fixing ignored workflow defined step title.

* Changing stepInfoPtr caused a too large env var for the analytics plugin (over the 20 Kb limit), reverting original functionality.

Co-authored-by: lpusok <7979773+lpusok@users.noreply.github.com>
  • Loading branch information
godrei and lpusok committed Jan 24, 2020
1 parent 93419bc commit a386b6e
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 76 deletions.
14 changes: 8 additions & 6 deletions Gopkg.lock

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

4 changes: 2 additions & 2 deletions bitrise/print.go
Expand Up @@ -354,8 +354,8 @@ func getRow(str string) string {

func getUpdateRow(stepInfo stepmanModels.StepInfoModel, width int) string {
vstr := fmt.Sprintf("%s -> %s", stepInfo.Version, stepInfo.LatestVersion)
if stepInfo.Version != stepInfo.EvaluatedVersion {
vstr = fmt.Sprintf("%s (%s) -> %s", stepInfo.Version, stepInfo.EvaluatedVersion, stepInfo.LatestVersion)
if stepInfo.Version != stepInfo.OriginalVersion {
vstr = fmt.Sprintf("%s (%s) -> %s", stepInfo.OriginalVersion, stepInfo.Version, stepInfo.LatestVersion)
}

updateRow := fmt.Sprintf("| Update available: %s |", vstr)
Expand Down
38 changes: 19 additions & 19 deletions bitrise/print_test.go
Expand Up @@ -238,9 +238,9 @@ func TestGetRunningStepFooterSubSection(t *testing.T) {
Step: stepmanModels.StepModel{
Title: pointers.NewStringPtr(longStr),
},
Version: "1.0.0",
LatestVersion: "1.1.0",
EvaluatedVersion: "1.0.0",
Version: "1.0.0",
LatestVersion: "1.1.0",
OriginalVersion: "1.0.0",
}

result := models.StepRunResultsModel{
Expand All @@ -266,9 +266,9 @@ func TestGetRunningStepFooterSubSection(t *testing.T) {
Title: pointers.NewStringPtr(longStr),
SourceCodeURL: pointers.NewStringPtr("https://github.com/test-organization/very-long-test-repository-name-exceeding-max-width"),
},
Version: "1",
LatestVersion: "2.1.0",
EvaluatedVersion: "1.0.1",
OriginalVersion: "1",
LatestVersion: "2.1.0",
Version: "1.0.1",
}

result := models.StepRunResultsModel{
Expand All @@ -285,23 +285,23 @@ func TestGetRunningStepFooterSubSection(t *testing.T) {
"| ...-organization/very-long-test-repository-name-exceeding-max-width/releases |"
require.Equal(t, expected, actual)

result.StepInfo.Version = "1.x.x"
result.StepInfo.OriginalVersion = "1.x.x"
actual = getRunningStepFooterSubSection(result)
expected = "| Update available: 1.x.x (1.0.1) -> 2.1.0 |" + "\n" +
"| |" + "\n" +
"| Release notes are available below |" + "\n" +
"| ...-organization/very-long-test-repository-name-exceeding-max-width/releases |"
require.Equal(t, expected, actual)

result.StepInfo.Version = "1.0"
result.StepInfo.OriginalVersion = "1.0"
actual = getRunningStepFooterSubSection(result)
expected = "| Update available: 1.0 (1.0.1) -> 2.1.0 |" + "\n" +
"| |" + "\n" +
"| Release notes are available below |" + "\n" +
"| ...-organization/very-long-test-repository-name-exceeding-max-width/releases |"
require.Equal(t, expected, actual)

result.StepInfo.Version = "1.0.x"
result.StepInfo.OriginalVersion = "1.0.x"
actual = getRunningStepFooterSubSection(result)
expected = "| Update available: 1.0.x (1.0.1) -> 2.1.0 |" + "\n" +
"| |" + "\n" +
Expand All @@ -318,9 +318,9 @@ func TestGetRunningStepFooterSubSection(t *testing.T) {
Title: pointers.NewStringPtr(longStr),
SourceCodeURL: pointers.NewStringPtr("https://github.com/bitrise-steplib/steps-script"),
},
Version: "1",
LatestVersion: "2.1.0",
EvaluatedVersion: "1.0.1",
OriginalVersion: "1",
LatestVersion: "2.1.0",
Version: "1.0.1",
}

result := models.StepRunResultsModel{
Expand All @@ -337,23 +337,23 @@ func TestGetRunningStepFooterSubSection(t *testing.T) {
"| https://github.com/bitrise-steplib/steps-script/releases |"
require.Equal(t, expected, actual)

result.StepInfo.Version = "1.x.x"
result.StepInfo.OriginalVersion = "1.x.x"
actual = getRunningStepFooterSubSection(result)
expected = "| Update available: 1.x.x (1.0.1) -> 2.1.0 |" + "\n" +
"| |" + "\n" +
"| Release notes are available below |" + "\n" +
"| https://github.com/bitrise-steplib/steps-script/releases |"
require.Equal(t, expected, actual)

result.StepInfo.Version = "1.0"
result.StepInfo.OriginalVersion = "1.0"
actual = getRunningStepFooterSubSection(result)
expected = "| Update available: 1.0 (1.0.1) -> 2.1.0 |" + "\n" +
"| |" + "\n" +
"| Release notes are available below |" + "\n" +
"| https://github.com/bitrise-steplib/steps-script/releases |"
require.Equal(t, expected, actual)

result.StepInfo.Version = "1.0.x"
result.StepInfo.OriginalVersion = "1.0.x"
actual = getRunningStepFooterSubSection(result)
expected = "| Update available: 1.0.x (1.0.1) -> 2.1.0 |" + "\n" +
"| |" + "\n" +
Expand All @@ -370,9 +370,9 @@ func TestGetRunningStepFooterSubSection(t *testing.T) {
Title: pointers.NewStringPtr(longStr),
SourceCodeURL: pointers.NewStringPtr("https://github.com/bitrise-steplib/steps-script"),
},
Version: "1",
LatestVersion: "1.0.1",
EvaluatedVersion: "1.0.1",
OriginalVersion: "1",
LatestVersion: "1.0.1",
Version: "1.0.1",
}

result := models.StepRunResultsModel{
Expand All @@ -386,7 +386,7 @@ func TestGetRunningStepFooterSubSection(t *testing.T) {
expected := ""
require.Equal(t, expected, actual)

result.StepInfo.Version = "1.0"
result.StepInfo.OriginalVersion = "1.0"
actual = getRunningStepFooterSubSection(result)
expected = ""
require.Equal(t, expected, actual)
Expand Down
57 changes: 34 additions & 23 deletions cli/run_util.go
Expand Up @@ -30,7 +30,9 @@ import (
"github.com/bitrise-io/go-utils/pointers"
"github.com/bitrise-io/go-utils/retry"
"github.com/bitrise-io/go-utils/versions"
stepmanCLI "github.com/bitrise-io/stepman/cli"
stepmanModels "github.com/bitrise-io/stepman/models"
"github.com/bitrise-io/stepman/stepman"
)

func isPRMode(prGlobalFlagPtr *bool, inventoryEnvironments []envmanModels.EnvironmentItemModel) (bool, error) {
Expand Down Expand Up @@ -519,52 +521,52 @@ func activateStepLibStep(stepIDData models.StepIDData, destination, stepYMLCopyP
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 {
if err := stepman.SetupLibrary(stepIDData.SteplibSource); err != nil {
return stepmanModels.StepInfoModel{}, false, err

}

isLatestVersionOfStep := (stepIDData.Version == "")
if isLatestVersionOfStep && !isStepLibUpdated {
log.Infof("Step uses latest version -- Updating StepLib ...")
if err := tools.StepmanUpdate(stepIDData.SteplibSource); err != nil {
if _, err := stepman.UpdateLibrary(stepIDData.SteplibSource); err != nil {
log.Warnf("Step uses latest version, but failed to update StepLib, err: %s", err)
} else {
didStepLibUpdate = true
}
}

outStr, err := tools.StepmanJSONStepLibStepInfo(stepIDData.SteplibSource, stepIDData.IDorURI, stepIDData.Version)
info, err := stepmanCLI.QueryStepInfoFromLibrary(stepIDData.SteplibSource, stepIDData.IDorURI, stepIDData.Version)
if err != nil {
if isStepLibUpdated {
return stepmanModels.StepInfoModel{}, false, fmt.Errorf("StepmanJSONStepLibStepInfo failed, err: %s", err)
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 {
if _, err := stepman.UpdateLibrary(stepIDData.SteplibSource); err != nil {
return stepmanModels.StepInfoModel{}, didStepLibUpdate, err
}

didStepLibUpdate = true

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

stepInfo, err := stepmanModels.StepInfoModel{}.CreateFromJSON(outStr)
if err != nil {
return stepmanModels.StepInfoModel{}, didStepLibUpdate, fmt.Errorf("CreateFromJSON failed, err: %s", err)
}
if stepInfo.Step.Title == nil || *stepInfo.Step.Title == "" {
stepInfo.Step.Title = pointers.NewStringPtr(stepInfo.ID)
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, stepIDData.Version, destination, stepYMLCopyPth); err != nil {
if err := stepmanCLI.Activate(stepIDData.SteplibSource, stepIDData.IDorURI, info.Version, destination, stepYMLCopyPth, false); err != nil {
return stepmanModels.StepInfoModel{}, didStepLibUpdate, err
}
log.Debugf("[BITRISE_CLI] - Step activated: (ID:%s) (version:%s)", stepIDData.IDorURI, stepIDData.Version)

return stepInfo, didStepLibUpdate, nil
return info, didStepLibUpdate, nil
}

func activateAndRunSteps(
Expand All @@ -589,13 +591,14 @@ func activateAndRunSteps(
}

stepInfoCopy := stepmanModels.StepInfoModel{
Library: stepInfoPtr.Library,
ID: stepInfoPtr.ID,
Version: stepInfoPtr.Version,
LatestVersion: stepInfoPtr.LatestVersion,
GroupInfo: stepInfoPtr.GroupInfo,
Step: stepInfoPtr.Step,
DefinitionPth: stepInfoPtr.DefinitionPth,
Library: stepInfoPtr.Library,
ID: stepInfoPtr.ID,
Version: stepInfoPtr.Version,
OriginalVersion: stepInfoPtr.OriginalVersion,
LatestVersion: stepInfoPtr.LatestVersion,
GroupInfo: stepInfoPtr.GroupInfo,
Step: stepInfoPtr.Step,
DefinitionPth: stepInfoPtr.DefinitionPth,
}

errStr := ""
Expand Down Expand Up @@ -800,7 +803,15 @@ func activateAndRunSteps(
if didUpdate {
buildRunResults.StepmanUpdates[stepIDData.SteplibSource]++
}
stepInfoPtr = stepInfo

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.GroupInfo = stepInfo.GroupInfo

if err != nil {
registerStepRunResults(stepmanModels.StepModel{}, stepInfoPtr, stepIdxPtr,
"", models.StepRunStatusCodeFailed, 1, err, isLastStep, true)
Expand Down

0 comments on commit a386b6e

Please sign in to comment.