Skip to content

Commit

Permalink
Merge pull request #39 from jdouglas-nz/feature/xcode11-project-build…
Browse files Browse the repository at this point in the history
…-version-metadata

[Feature] - xcode11 project build / version number build setting support
  • Loading branch information
SiarheiFedartsou authored Oct 30, 2019
2 parents 4537ea5 + 459977d commit 32b1966
Show file tree
Hide file tree
Showing 29 changed files with 1,637 additions and 123 deletions.
149 changes: 139 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
[![Gem](https://img.shields.io/gem/v/fastlane-plugin-versioning.svg?style=flat)](http://rubygems.org/gems/fastlane-plugin-versioning)
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-versioning)

# MAINTAINERS WANTED

Unfortunately I don't have enough time to maintain this project. If you want to become a maintainer of this project, please, open the issue or [email](mailto:[email protected]) me.

## Getting Started

This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with fastlane-plugin-versioning, add it to your project by running:
Expand All @@ -20,14 +16,24 @@ fastlane add_plugin versioning
## About versioning

Extends fastlane versioning actions. Allows to set/get versions without using agvtool and do some other small tricks.
Note that all schemes that you pass to actions like `increment_version_number_in_plist` or `get_info_plist_path` in `scheme` parameter must be shared.
To make your scheme shared go to "Manage schemes" in Xcode and tich "Shared" checkbox near your scheme.
Note that all schemes that you pass to actions like `increment_version_number_in_plist`, `increment_build_number_in_xcodeproj` or `get_info_plist_path` in `scheme` parameter must be shared.
To make your scheme shared go to "Manage schemes" in Xcode and tick "Shared" checkbox near your scheme.


### what is this `plist_build_setting_support` stuff about?!
If you have a xcodeproject and have updated to Xcode 11, you'll notice that if you change your build and version numbers through the UI, the actual numbers are now stored inside build settings inside build confiugration. The Info.plist file -- where they used to be stored -- now contains build setting variables (looks like `$(CURRENT_PROJECT_VERSION)` or `$(MARKETING_VERSION)`, for build number and version number respectively).
If you are at this migration 'turning point', you have two options. you can either:
1. simply add `plist_build_setting_support: true` to your plist action parameters
2. change the command to be the xcodeproj variants - i.e. `increment_version_number_in_xcodeproj` or `increment_build_number_in_xcodeproj`

these also apply to the `getters` of build and version numbers.
We will leave the plist actions in, as for those consumers who are limited to their upgrade path.

## Actions

### increment_version_number_in_plist

Increment/set version number in Info.plist of specific target. Doesn't use agvtool (unlike default increment_version_number).
Increment/set the version number in a Info.plist of specific target. Doesn't use `agvtool` (unlike default `increment_version_number`).

```ruby
increment_version_number_in_plist # Automatically increment patch version number.
Expand Down Expand Up @@ -61,20 +67,42 @@ increment_version_number_in_plist(
# (optional)
target: 'TestTarget' # or `scheme`
)

increment_version_number_in_plist(
# specify specific version number (optional, omitting it increments patch version number)
version_number: '2.1.1',
# (optional, you must specify the path to your main Xcode project if it is not in the project root directory
# or if you have multiple xcodeproj's in the root directory)
xcodeproj: './path/to/MyApp.xcodeproj'
# (optional)
target: 'TestTarget' # or `scheme`
plist_build_setting_support: true, # optional, and defaulting to false.
# setting this will resolve the version number using the relevant build settings from your xcodeproj.
)

```

#### plist_build_setting_support
`get_version_number_from_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to edit, _OR_ change __ALL__ of them.


### get_version_number_from_plist

Get version number from Info.plist of specific target. Doesn't use agvtool (unlike default get_version_number).
Get the version number from an Info.plist of specific target. Doesn't use `agvtool` (unlike default `get_version_number`).

```ruby
version = get_version_number_from_plist(xcodeproj: 'Project.xcodeproj', # optional
target: 'TestTarget', # optional, or `scheme`
# optional, must be specified if you have different Info.plist build settings
# for different build configurations
plist_build_setting_support: true, # optional, and defaulting to false. setting this will
# resolve the version number using the relevant build settings from your xcodeproj.
build_configuration_name: 'Release')
```

#### plist_build_setting_support
`get_version_number_from_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to retrieve, _OR_ pick the first it finds.

### get_app_store_version_number


Expand All @@ -101,7 +129,7 @@ version = get_version_number_from_git_branch(pattern: 'release-#')

### increment_build_number_in_plist

Increment/set build number in Info.plist of specific target. Doesn't use agvtool (unlike default increment_version_number).
Increment/set build number in Info.plist of specific target. Doesn't use `agvtool` (unlike default `increment_version_number`).

```ruby
increment_build_number_in_plist # Automatically increments the last part of the build number.
Expand All @@ -110,16 +138,115 @@ increment_build_number_in_plist(
)
```

#### plist_build_setting_support
`increment_build_number_in_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to edit, _OR_ change __ALL__ of them.

### get_build_number_from_plist

Get build number from Info.plist of specific target. Doesn't use agvtool (unlike default get_build_number).
Get the build number from an Info.plist of specific target. Doesn't use `agvtool` (unlike default `get_build_number`).

```ruby
version = get_build_number_from_plist(xcodeproj: "Project.xcodeproj", # optional
target: 'TestTarget', # optional, or `scheme`
plist_build_setting_support: true, # optional, and defaulting to false. setting this will
# resolve the build number using the relevant build settings from your xcodeproj.
build_configuration_name: 'Release') # optional, must be specified if you have different Info.plist build settings for different build configurations
```

#### plist_build_setting_support
`get_build_number_from_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to retrieve, _OR_ pick the first it finds.

### get_build_number_from_xcodeproj

Get the build number from a xcodeproj - specific to a target. Doesn't use agvtool (unlike default `get_build_number`).

```ruby
version = get_build_number_from_xcodeproj(xcodeproj: "Project.xcodeproj", # optional
target: 'TestTarget', # optional, or `scheme`
build_configuration_name: 'Release') # optional, must be specified if you have different Info.plist build settings for different build configurations
```

### get_version_number_from_xcodeproj

Get the version number from a xcodeproj - specific to a target. Doesn't use agvtool (unlike default `get_build_number`).

```ruby
version = get_version_number_from_xcodeproj(xcodeproj: 'Project.xcodeproj', # optional
target: 'TestTarget', # optional, or `scheme`
# optional, must be specified if you have different Info.plist build settings
# for different build configurations
build_configuration_name: 'Release')
```

### increment_version_number_in_xcodeproj

Increment/set the version number in a xcodeproj of specific target. Doesn't use `agvtool` (unlike default `increment_version_number`).

```ruby
increment_version_number_in_xcodeproj # Automatically increment patch version number.
increment_version_number_in_xcodeproj(
bump_type: 'patch' # Automatically increment patch version number
)
increment_version_number_in_xcodeproj(
bump_type: 'minor' # Automatically increment minor version number
)
increment_version_number_in_xcodeproj(
bump_type: 'minor',
omit_zero_patch_version: true # if true omits zero in patch version(so 42.10.0 will become 42.10 and 42.10.1 will remain 42.10.1), default is false
)
increment_version_number_in_xcodeproj(
bump_type: 'major' # Automatically increment major version number
)
increment_version_number_in_xcodeproj(
version_number: '2.1.1' # Set a specific version number
)
increment_version_number_in_xcodeproj(
# Automatically increment patch version number. Use App Store version number as a source.
version_source: 'appstore'
)

increment_version_number_in_xcodeproj(
# specify specific version number (optional, omitting it increments patch version number)
version_number: '2.1.1',
# (optional, you must specify the path to your main Xcode project if it is not in the project root directory
# or if you have multiple xcodeproj's in the root directory)
xcodeproj: './path/to/MyApp.xcodeproj'
# (optional)
target: 'TestTarget' # or `scheme`
)

```

### get_version_number_from_plist

Get version number from Info.plist of specific target. Doesn't use agvtool (unlike default `get_version_number`).

```ruby
version = get_version_number_from_plist(xcodeproj: 'Project.xcodeproj', # optional
target: 'TestTarget', # optional, or `scheme`
# optional, must be specified if you have different Info.plist build settings
# for different build configurations
plist_build_setting_support: true, # optional, and defaulting to false. setting this will
# resolve the version number using the relevant build settings from your xcodeproj.
build_configuration_name: 'Release')
```

#### plist_build_setting_support
`get_version_number_from_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to retrieve, _OR_ pick the first it finds.

### get_app_store_version_number


```ruby
version = get_app_store_version_number(xcodeproj: 'Project.xcodeproj', # optional
target: 'TestTarget', # optional, or `scheme`
# optional, must be specified if you have different Info.plist build settings
# for different build configurations
build_configuration_name: 'Release')
)
version = get_app_store_version_number(bundle_id: 'com.apple.Numbers')

```

### get_info_plist_path

Expand All @@ -142,6 +269,8 @@ increment_build_number_in_plist(
)
```



## Issues and Feedback

For any other issues and feedback about this plugin, please submit it to this repository.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def self.run(params)
bundle_id = params[:bundle_id]
else
if Helper.test?
plist = "/tmp/fastlane/tests/fastlane/Info.plist"
plist = "/tmp/fastlane/tests/fastlane/plist/Info.plist"
else
plist = GetInfoPlistPathAction.run(params)
end
bundle_id = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleIdentifier')
bundle_id = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleIdentifier') # TODO: add same kind of flag to support build setting variables
end

uri = URI("http://itunes.apple.com/lookup?bundleId=#{bundle_id}")
Expand Down Expand Up @@ -42,7 +42,7 @@ def self.available_options
env_name: "FL_APPSTORE_VERSION_NUMBER_BUNDLE_ID",
description: "Bundle ID of the application",
optional: true,
conflicting_options: [:xcodeproj, :target, :scheme, :build_configuration_name],
conflicting_options: %i[xcodeproj target scheme build_configuration_name],
is_string: true),
FastlaneCore::ConfigItem.new(key: :xcodeproj,
env_name: "FL_VERSION_NUMBER_PROJECT",
Expand All @@ -56,12 +56,12 @@ def self.available_options
FastlaneCore::ConfigItem.new(key: :target,
env_name: "FL_VERSION_NUMBER_TARGET",
optional: true,
conflicting_options: [:bundle_id, :scheme],
conflicting_options: %i[bundle_id scheme],
description: "Specify a specific target if you have multiple per project, optional"),
FastlaneCore::ConfigItem.new(key: :scheme,
env_name: "FL_VERSION_NUMBER_SCHEME",
optional: true,
conflicting_options: [:bundle_id, :target],
conflicting_options: %i[bundle_id target],
description: "Specify a specific scheme if you have multiple per project, optional"),
FastlaneCore::ConfigItem.new(key: :build_configuration_name,
optional: true,
Expand All @@ -75,7 +75,7 @@ def self.authors
end

def self.is_supported?(platform)
[:ios, :mac].include? platform
%i[ios mac].include? platform
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ module Actions
class GetBuildNumberFromPlistAction < Action
def self.run(params)
if Helper.test?
plist = "/tmp/fastlane/tests/fastlane/Info.plist"
plist = "/tmp/fastlane/tests/fastlane/plist/Info.plist"
else
plist = GetInfoPlistPathAction.run(params)
end

version_number = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleVersion')
if params[:plist_build_setting_support]
UI.important "build number will originate from xcodeproj"
build_number = GetBuildNumberFromXcodeprojAction.run(params)
else
UI.important "build number will originate from plist."
build_number = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleVersion')
end

# Store the number in the shared hash
Actions.lane_context[SharedValues::BUILD_NUMBER] = version_number
Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number
build_number
end

#####################################################
Expand All @@ -23,7 +31,8 @@ def self.description

def self.details
[
"This action will return the current build number set on your project's Info.plist."
"This action will return the current build number set on your project's Info.plist.",
"note that you can pass plist_build_setting_support: true, in which case it will return from your xcodeproj."
].join(' ')
end

Expand All @@ -49,8 +58,11 @@ def self.available_options
description: "Specify a specific scheme if you have multiple per project, optional"),
FastlaneCore::ConfigItem.new(key: :build_configuration_name,
optional: true,
description: "Specify a specific build configuration if you have different Info.plist build settings for each configuration")

description: "Specify a specific build configuration if you have different Info.plist build settings for each configuration"),
FastlaneCore::ConfigItem.new(key: :plist_build_setting_support,
description: "support automatic resolution of build setting from xcodeproj if not a literal value in the plist",
is_string: false,
default_value: false)
]
end

Expand All @@ -65,7 +77,7 @@ def self.authors
end

def self.is_supported?(platform)
[:ios, :mac].include? platform
%i[ios mac].include? platform
end
end
end
Expand Down
Loading

0 comments on commit 32b1966

Please sign in to comment.