Skip to content

Commit

Permalink
Add more logging (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
tothszabi authored Apr 30, 2024
1 parent bc98277 commit 84a6897
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ workflows:
- build_version: 9994
- build_version_offset: 5
- build_short_version_string: 9.99.9
- verbose: "true"
- script:
title: Build app
inputs:
Expand Down
10 changes: 10 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ inputs:
If it is empty then the step will not modify the existing value.
- verbose: "false"
opts:
category: Debug
title: Enable verbose logging
summary: Enable logging additional information for debugging.
is_required: true
value_options:
- "true"
- "false"

outputs:
- XCODE_BUNDLE_VERSION:
opts:
Expand Down
1 change: 1 addition & 0 deletions step/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Input struct {
BuildVersion int64 `env:"build_version,required"`
BuildVersionOffset int64 `env:"build_version_offset"`
BuildShortVersionString string `env:"build_short_version_string"`
Verbose bool `env:"verbose,required"`
}

type Config struct {
Expand Down
36 changes: 31 additions & 5 deletions step/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ func (u Updater) ProcessConfig() (Config, error) {
return Config{}, fmt.Errorf("build version offset cannot be a negative value (%d)", input.BuildVersionOffset)
}

u.logger.EnableDebugLog(input.Verbose)

stepconf.Print(input)
u.logger.Println()

// golangci told me that I should do this instead of creating a Config struct.
return Config(input), nil
return Config{
ProjectPath: input.ProjectPath,
Scheme: input.Scheme,
Target: input.Target,
Configuration: input.Configuration,
BuildVersion: input.BuildVersion,
BuildVersionOffset: input.BuildVersionOffset,
BuildShortVersionString: input.BuildShortVersionString,
}, nil
}

func (u Updater) Run(config Config) (Result, error) {
Expand All @@ -70,7 +79,7 @@ func (u Updater) Run(config Config) (Result, error) {
if generated {
u.logger.Printf("The version numbers are stored in the project file.")

err := updateVersionNumbersInProject(helper, config.Target, config.Configuration, buildVersion, config.BuildShortVersionString)
err := u.updateVersionNumbersInProject(helper, config.Target, config.Configuration, buildVersion, config.BuildShortVersionString)
if err != nil {
return Result{}, err
}
Expand Down Expand Up @@ -103,7 +112,7 @@ func generatesInfoPlist(helper *projectmanager.ProjectHelper, targetName, config
return generatesInfoPlist, err
}

func updateVersionNumbersInProject(helper *projectmanager.ProjectHelper, targetName, configuration string, bundleVersion int64, shortVersion string) error {
func (u Updater) updateVersionNumbersInProject(helper *projectmanager.ProjectHelper, targetName, configuration string, bundleVersion int64, shortVersion string) error {
if targetName == "" {
targetName = helper.MainTarget.Name
}
Expand All @@ -118,10 +127,18 @@ func updateVersionNumbersInProject(helper *projectmanager.ProjectHelper, targetN
continue
}

u.logger.Printf("Updating build settings for the %s target", target.Name)

oldProjectVersion := buildConfig.BuildSettings["CURRENT_PROJECT_VERSION"]
buildConfig.BuildSettings["CURRENT_PROJECT_VERSION"] = bundleVersion

u.logger.Debugf("CURRENT_PROJECT_VERSION %s -> %d", oldProjectVersion, bundleVersion)

if shortVersion != "" {
oldMarketingVersion := buildConfig.BuildSettings["MARKETING_VERSION"]
buildConfig.BuildSettings["MARKETING_VERSION"] = shortVersion

u.logger.Debugf("MARKETING_VERSION %s -> %s", oldMarketingVersion, shortVersion)
}
}
}
Expand Down Expand Up @@ -168,11 +185,20 @@ func (u Updater) updateVersionNumbersInInfoPlist(helper *projectmanager.ProjectH
infoPlistPath = filepath.Join(filepath.Dir(helper.XcProj.Path), infoPlistPath)
}

u.logger.Printf("Updating Info.plist at %s", infoPlistPath)

infoPlist, format, _ := xcodeproj.ReadPlistFile(infoPlistPath)
infoPlist["CFBundleVersion"] = strconv.FormatInt(bundleVersion, 10)
oldVersion := infoPlist["CFBundleVersion"]
newVersion := strconv.FormatInt(bundleVersion, 10)
infoPlist["CFBundleVersion"] = newVersion

u.logger.Debugf("CFBundleVersion %s -> %s", oldVersion, newVersion)

if shortVersion != "" {
oldVersionString := infoPlist["CFBundleShortVersionString"]
infoPlist["CFBundleShortVersionString"] = shortVersion

u.logger.Debugf("CFBundleShortVersionString %s -> %s", oldVersionString, shortVersion)
}

err = xcodeproj.WritePlistFile(infoPlistPath, infoPlist, format)
Expand Down

0 comments on commit 84a6897

Please sign in to comment.