Skip to content

Commit

Permalink
Better logs when running implicit setup; do minimal setup only (#999)
Browse files Browse the repository at this point in the history
* Better logs when running implicit setup

* Fix tests, do minimal setup

* Change log level
  • Loading branch information
ofalvai authored Sep 24, 2024
1 parent 3956185 commit 0660c71
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
11 changes: 8 additions & 3 deletions bitrise/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ var PluginDependencyMap = map[string]PluginDependency{
}

func RunSetupIfNeeded(logger log.Logger) error {
if !configs.CheckIsSetupWasDoneForVersion(version.VERSION) {
log.Warnf("Setup was not performed for this version of bitrise, doing it now...")
return RunSetup(logger, version.VERSION, SetupModeDefault, false)
versionMatch, setupVersion := configs.CheckIsSetupWasDoneForVersion(version.VERSION)
if setupVersion == "" {
log.Infof("No setup was done yet, running setup now...")
return RunSetup(logger, version.VERSION, SetupModeMinimal, false)
}
if !versionMatch {
log.Infof("Setup was last performed for version %s, current version is %s. Re-running setup now...", setupVersion, version.VERSION)
return RunSetup(logger, version.VERSION, SetupModeMinimal, false)
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ func SavePluginUpdateCheck(plugin string) error {
return saveBitriseConfig(config)
}

func CheckIsSetupWasDoneForVersion(ver string) bool {
func CheckIsSetupWasDoneForVersion(ver string) (bool, string) {
config, err := loadBitriseConfig()
if err != nil {
return false
return false, ""
}
return (config.SetupVersion == ver)
return config.SetupVersion == ver, config.SetupVersion
}

func SaveSetupSuccessForVersion(ver string) error {
Expand Down
9 changes: 6 additions & 3 deletions configs/configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ func TestSetupForVersionChecks(t *testing.T) {

t.Setenv("HOME", fakeHomePth)

require.Equal(t, false, CheckIsSetupWasDoneForVersion("0.9.7"))
versionMatch, _ := CheckIsSetupWasDoneForVersion("0.9.7")
require.Equal(t, false, versionMatch)

require.Equal(t, nil, SaveSetupSuccessForVersion("0.9.7"))

require.Equal(t, true, CheckIsSetupWasDoneForVersion("0.9.7"))
versionMatch, _ = CheckIsSetupWasDoneForVersion("0.9.7")
require.Equal(t, true, versionMatch)

require.Equal(t, false, CheckIsSetupWasDoneForVersion("0.9.8"))
versionMatch, _ = CheckIsSetupWasDoneForVersion("0.9.8")
require.Equal(t, false, versionMatch)
}

0 comments on commit 0660c71

Please sign in to comment.