diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 19b270dd8..63edad33e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -5,4 +5,5 @@ - [ ] Run `bundle exec rubocop` to test for code style violations and recommendations - [ ] Add Unit Tests (aka `specs/*_spec.rb`) if applicable - [ ] Run `bundle exec rspec` to run the whole test suite and ensure all your tests pass -- [ ] Make sure you added an entry in [the `CHANGELOG.md` file](https://github.com/wordpress-mobile/release-toolkit/blob/trunk/CHANGELOG.md#trunk) to describe your changes under the approprioate existing `###` subsection of the existing `## Trunk` section. \ No newline at end of file +- [ ] Make sure you added an entry in [the `CHANGELOG.md` file](https://github.com/wordpress-mobile/release-toolkit/blob/trunk/CHANGELOG.md#trunk) to describe your changes under the appropriate existing `###` subsection of the existing `## Trunk` section. +- [ ] If relevant, please add an entry in [the `MIGRATION.md` file](https://github.com/wordpress-mobile/release-toolkit/blob/trunk/MIGRATION.md#migrating-to-trunk) to provide more context for a version migration impacted by the changes in this pull request, in the appropriate `###` subsection of the existing `## Migrating to Trunk` section. diff --git a/CHANGELOG.md b/CHANGELOG.md index 70e29f095..4b8fd43bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ ### Breaking Changes - Remove the `skip_glotpress` parameter from the `ios_bump_version_release` action [#443] +- Add the `public_version_xcconfig_file` parameter to the `ios_get_app_version` action to replace the need for an environment variable [#445] +- Remove the `ios_localize_project` and `ios_update_metadata` actions [#447] +- Remove the `skip_deliver` parameter from `ios_bump_version_hotfix` and `ios_bump_version_release` actions [#450] ### New Features @@ -20,6 +23,7 @@ _None_ ### Internal Changes - Updates `activesupport` to `6.1.7.1`, addressing [a security issue](https://github.com/advisories/GHSA-j6gc-792m-qgm2). This is a major version change, but as the dependency is internal-only, it shouldn't be a breaking change for clients. [#441] +- Add the explicit dependency to `xcodeproj (~> 1.22)`, used in this case to replace the previous manual parsing of `.xcconfig` files. [#451] ## 6.3.0 diff --git a/Gemfile.lock b/Gemfile.lock index e25104bc0..df251f5e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,6 +16,7 @@ PATH progress_bar (~> 1.3) rake (>= 12.3, < 14.0) rake-compiler (~> 1.0) + xcodeproj (~> 1.22) GEM remote: https://rubygems.org/ diff --git a/MIGRATION.md b/MIGRATION.md new file mode 100644 index 000000000..784cce6d6 --- /dev/null +++ b/MIGRATION.md @@ -0,0 +1,20 @@ +# Release Toolkit Migration Guide + +--- + +## Migrating to Trunk + +### Considerations for breaking changes + +- Ensure that calls to `ios_bump_version_release` already passed `skip_glotpress: true`. +In case of passing false as parameter or not providing a value (false being the default for this ConfigItem), you'll have to ensure that: + - `download_metadata.swift` isn't being used; if it is, it's a good time to migrate to the new tooling + - You're not relying on `ios_bump_version_release` for commiting the `.po/.pot` file +- The deprecated actions `ios_localize_project` and `ios_update_metadata` were now completely removed. If your project is still using them, please use the new tooling instead. + - See `ios_generate_strings_file_from_code`, `ios_extract_keys_from_strings_files`, `ios_download_strings_files_from_glotpress` and `ios_merge_strings_files` for typical replacements. +- The action `ios_get_app_version` now requires a parameter `public_version_xcconfig_file` with the public `.xcconfig` file path instead of relying on the environment variable `PUBLIC_CONFIG_FILE`. While the complete removal of this environment variable is our goal, at this point it is still required by other actions such as `ios_bump_version_release` and `ios_codefreeze_prechecks`. +- The usage of a `Deliverfile` (including its `app_version`) is discouraged -- please use `upload_to_app_store` directly from your `Fastfile` instead. Therefore, the parameter `skip_deliver` from the actions `ios_bump_version_hotfix` and `ios_bump_version_release` has been removed. + +### Clean-ups + +- You can now delete the `ENV['APP_STORE_STRINGS_FILE_NAME']` from your Fastfile, as it isn't being used anymore. diff --git a/fastlane-plugin-wpmreleasetoolkit.gemspec b/fastlane-plugin-wpmreleasetoolkit.gemspec index 3266d5cbd..3e67c9591 100644 --- a/fastlane-plugin-wpmreleasetoolkit.gemspec +++ b/fastlane-plugin-wpmreleasetoolkit.gemspec @@ -37,6 +37,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'progress_bar', '~> 1.3' spec.add_dependency 'rake', '>= 12.3', '< 14.0' spec.add_dependency 'rake-compiler', '~> 1.0' + spec.add_dependency 'xcodeproj', '~> 1.22' # `google-cloud-storage` is required by fastlane, but we pin it in case it's not in the future spec.add_dependency 'google-cloud-storage', '~> 1.31' diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_beta.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_beta.rb index f6228c9f9..36016085a 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_beta.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_beta.rb @@ -15,7 +15,7 @@ def self.run(params) Fastlane::Helper::Ios::VersionHelper.update_xc_configs(@new_beta_version, @short_version, @new_internal_version) UI.message 'Done!' - Fastlane::Helper::Ios::GitHelper.commit_version_bump(include_deliverfile: false, include_metadata: false) + Fastlane::Helper::Ios::GitHelper.commit_version_bump() end ##################################################### diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_hotfix.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_hotfix.rb index aa6ff18dc..71cabe795 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_hotfix.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_hotfix.rb @@ -9,18 +9,11 @@ def self.run(params) create_config(params[:previous_version], params[:version]) show_config() - update_deliverfile = params[:skip_deliver] == false - if update_deliverfile - UI.message 'Updating Fastlane deliver file...' - Fastlane::Helper::Ios::VersionHelper.update_fastlane_deliver(@new_short_version) - UI.message 'Done!' - end - UI.message 'Updating XcConfig...' Fastlane::Helper::Ios::VersionHelper.update_xc_configs(@new_version, @new_short_version, @new_version_internal) UI.message 'Done!' - Fastlane::Helper::Ios::GitHelper.commit_version_bump(include_deliverfile: update_deliverfile, include_metadata: false) + Fastlane::Helper::Ios::GitHelper.commit_version_bump() UI.message 'Done.' end @@ -51,16 +44,6 @@ def self.available_options description: 'The version to branch from', is_string: true ), - FastlaneCore::ConfigItem.new( - key: :skip_deliver, - env_name: 'FL_IOS_BUMP_VERSION_HOTFIX_SKIP_DELIVER', - description: 'Skips Deliverfile key update', - is_string: false, # Boolean parameter - optional: true, - # Don't skip the Deliverfile by default. At the time of writing, 2 out of 3 consumers - # still have a Deliverfile. - default_value: false - ), ] end diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_release.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_release.rb index 2cddf478f..0f71931ce 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_release.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_bump_version_release.rb @@ -21,18 +21,11 @@ def self.run(params) Fastlane::Helper::GitHelper.create_branch(@new_release_branch, from: default_branch) UI.message 'Done!' - UI.message 'Updating Fastlane deliver file...' unless params[:skip_deliver] - Fastlane::Helper::Ios::VersionHelper.update_fastlane_deliver(@new_short_version) unless params[:skip_deliver] - UI.message 'Done!' unless params[:skip_deliver] - UI.message 'Updating XcConfig...' Fastlane::Helper::Ios::VersionHelper.update_xc_configs(@new_version, @new_short_version, @new_version_internal) UI.message 'Done!' - Fastlane::Helper::Ios::GitHelper.commit_version_bump( - include_deliverfile: !params[:skip_deliver], - include_metadata: false - ) + Fastlane::Helper::Ios::GitHelper.commit_version_bump() UI.message 'Done.' end @@ -51,11 +44,6 @@ def self.details def self.available_options [ - FastlaneCore::ConfigItem.new(key: :skip_deliver, - env_name: 'FL_IOS_CODEFREEZE_BUMP_SKIPDELIVER', - description: 'Skips Deliver key update', - type: Boolean, - default_value: false), FastlaneCore::ConfigItem.new(key: :default_branch, env_name: 'FL_RELEASE_TOOLKIT_DEFAULT_BRANCH', description: 'Default branch of the repository', diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_get_app_version.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_get_app_version.rb index 8d2a647be..e08aa40fb 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_get_app_version.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_get_app_version.rb @@ -4,9 +4,8 @@ class IosGetAppVersionAction < Action def self.run(params) require_relative '../../helper/ios/ios_version_helper' - UI.user_error!('You need to set at least the PUBLIC_CONFIG_FILE env var to the path to the public xcconfig file') unless ENV['PUBLIC_CONFIG_FILE'] - - Fastlane::Helper::Ios::VersionHelper.get_public_version + public_version_xcconfig_file = params[:public_version_xcconfig_file] + Fastlane::Helper::Ios::VersionHelper.get_xcconfig_public_version(xcconfig_file: public_version_xcconfig_file) end ##################################################### @@ -22,7 +21,15 @@ def self.details end def self.available_options - # Define all options your action supports. + [ + FastlaneCore::ConfigItem.new( + key: :public_version_xcconfig_file, + env_name: 'FL_IOS_PUBLIC_VERSION_XCCONFIG_FILE', + description: 'Path to the .xcconfig file containing the public app version', + type: String, + optional: false + ), + ] end def self.output diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_localize_project.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_localize_project.rb deleted file mode 100644 index 4c30e07c3..000000000 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_localize_project.rb +++ /dev/null @@ -1,43 +0,0 @@ -module Fastlane - module Actions - class IosLocalizeProjectAction < Action - def self.run(params) - UI.message 'Updating project localisation...' - - require_relative '../../helper/ios/ios_git_helper' - other_action.cocoapods() - Fastlane::Helper::Ios::GitHelper.localize_project() - - UI.message 'Done.' - end - - ##################################################### - # @!group Documentation - ##################################################### - - def self.description - 'Gathers the strings to localise. Deprecated' - end - - def self.details - 'Gathers the strings to localise. Deprecated in favor of the new `ios_generate_strings_file_from_code`' - end - - def self.category - :deprecated - end - - def self.deprecated_notes - 'This action is deprecated in favor of `ios_generate_strings_file_from_code`' - end - - def self.authors - ['Automattic'] - end - - def self.is_supported?(platform) - platform == :ios - end - end - end -end diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_update_metadata.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_update_metadata.rb deleted file mode 100644 index 996671246..000000000 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_update_metadata.rb +++ /dev/null @@ -1,40 +0,0 @@ -module Fastlane - module Actions - class IosUpdateMetadataAction < Action - def self.run(params) - require_relative '../../helper/ios/ios_git_helper' - - Fastlane::Helper::Ios::GitHelper.update_metadata() - end - - ##################################################### - # @!group Documentation - ##################################################### - - def self.description - 'Downloads translated metadata from the translation system' - end - - def self.details - 'Downloads translated metadata from the translation system' - end - - def self.available_options - end - - def self.output - end - - def self.return_value - end - - def self.authors - ['Automattic'] - end - - def self.is_supported?(platform) - [:ios, :mac].include?(platform) - end - end - end -end diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb index 01909b8c1..659ffc27d 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb @@ -8,68 +8,15 @@ module GitHelper # # This typically commits and pushes: # - The files in `./config/*` – especially `Version.*.xcconfig` files - # - The `fastlane/Deliverfile` file (which contains the `app_version` line) - # - The `//Resources/AppStoreStrings.pot` file, containing a key for that version's release notes # # @env PROJECT_ROOT_FOLDER The path to the git root of the project - # @env PROJECT_NAME The name of the directory containing the project code (especially containing the Resources/ subfolder) # - # @param [Bool] include_deliverfile If true (the default), includes the `fastlane/Deliverfile` in files being commited - # @param [Bool] include_metadata If true (the default), includes the `fastlane/download_metadata.swift` file and the `.pot` file (which typically contains an entry or release notes for the new version) - # - def self.commit_version_bump(include_deliverfile: true, include_metadata: true) - files_list = [File.join(ENV['PROJECT_ROOT_FOLDER'], 'config', '.')] - files_list.append File.join('fastlane', 'Deliverfile') if include_deliverfile - if include_metadata - files_list.append File.join('fastlane', 'download_metadata.swift') - files_list.append File.join(ENV['PROJECT_ROOT_FOLDER'], ENV['PROJECT_NAME'], 'Resources', ENV['APP_STORE_STRINGS_FILE_NAME']) - end + def self.commit_version_bump + files_list = [File.join(get_from_env!(key: 'PROJECT_ROOT_FOLDER'), 'config', '.')] Fastlane::Helper::GitHelper.commit(message: 'Bump version number', files: files_list, push: true) end - # Calls the `Scripts/localize.py` script in the project root folder and push the `*.strings` files - # - # That script updates the `.strings` files with translations from GlotPress. - # - # @env PROJECT_ROOT_FOLDER The path to the git root of the project - # @env PROJECT_NAME The name of the directory containing the project code (especially containing the `build.gradle` file) - # - # @deprecated This method is only used by the `ios_localize_project` action, which is itself deprecated - # in favor of the new `ios_generate_strings_file_from_code` action - # @todo [Next Major] Remove this method once we fully remove `ios_localize_project` - # - def self.localize_project - Action.sh("cd #{get_from_env!(key: 'PROJECT_ROOT_FOLDER')} && ./Scripts/localize.py") - - Fastlane::Helper::GitHelper.commit(message: 'Update strings for localization', files: strings_files, push: true) || UI.message('No new strings, skipping commit') - end - - # Call the `Scripts/update-translations.rb` then the `fastlane/download_metadata` Scripts from the host project folder - # - # @env PROJECT_ROOT_FOLDER The path to the git root of the project - # @env PROJECT_NAME The name of the directory containing the project code (especially containing the `build.gradle` file) - # - # @todo Migrate the scripts, currently in each host repo and called by this method, to be helpers and actions - # in the release-toolkit instead, and move this code away from `ios_git_helper`. - # - def self.update_metadata - Action.sh("cd #{get_from_env!(key: 'PROJECT_ROOT_FOLDER')} && ./Scripts/update-translations.rb") - - Fastlane::Helper::GitHelper.commit(message: 'Update translations', files: strings_files, push: false) - - Action.sh('cd fastlane && ./download_metadata.swift') - - Fastlane::Helper::GitHelper.commit(message: 'Update metadata translations', files: './fastlane/metadata/', push: true) - end - - def self.strings_files - project_root = get_from_env!(key: 'PROJECT_ROOT_FOLDER') - project_name = get_from_env!(key: 'PROJECT_NAME') - - Dir.glob(File.join(project_root, project_name, '**', '*.strings')) - end - def self.get_from_env!(key:) ENV.fetch(key) do UI.user_error! "Could not find value for \"#{key}\" in environment." diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb index 16059c4b4..d638640c6 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb @@ -1,3 +1,5 @@ +require 'xcodeproj' + module Fastlane module Helper module Ios @@ -15,12 +17,33 @@ module VersionHelper # Returns the public-facing version string. # + # @param [String] xcconfig_file The path for the .xcconfig file containing the public-facing version + # # @return [String] The public-facing version number, extracted from the VERSION_LONG entry of the xcconfig file. # - If this version is a hotfix (more than 2 parts and 3rd part is non-zero), returns the "X.Y.Z" formatted string # - Otherwise (not a hotfix / 3rd part of version is 0), returns "X.Y" formatted version number # + def self.get_xcconfig_public_version(xcconfig_file:) + version = read_long_version_from_config_file(xcconfig_file) + + UI.user_error!(".xcconfig file doesn't have a version configured") if version.nil? + + vp = get_version_parts(version) + return "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" unless is_hotfix?(version) + + "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}" + end + + # Returns the public-facing version string. + # + # @return [String] The public-facing version number, extracted from the VERSION_LONG entry of the xcconfig file. + # - If this version is a hotfix (more than 2 parts and 3rd part is non-zero), returns the "X.Y.Z" formatted string + # - Otherwise (not a hotfix / 3rd part of version is 0), returns "X.Y" formatted version number + # + # @deprecated This method is going to be removed soon due to it's dependency on `ENV['PUBLIC_CONFIG_FILE']` via `get_build_version`. + # def self.get_public_version - version = get_build_version + version = get_build_version() vp = get_version_parts(version) return "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" unless is_hotfix?(version) @@ -169,7 +192,8 @@ def self.is_hotfix?(version) # @return [String] The current version according to the public xcconfig file. # def self.get_build_version - versions = get_version_strings()[0] + xcconfig_file = ENV['PUBLIC_CONFIG_FILE'] + read_long_version_from_config_file(xcconfig_file) end # Returns the current value of the `VERSION_LONG` key from the internal xcconfig file @@ -177,7 +201,8 @@ def self.get_build_version # @return [String] The current version according to the internal xcconfig file. # def self.get_internal_version - get_version_strings()[1] + xcconfig_file = ENV['INTERNAL_CONFIG_FILE'] + read_long_version_from_config_file(xcconfig_file) end # Prints the current and next release version numbers to stdout, then return the next release version @@ -195,20 +220,6 @@ def self.bump_version_release return verified_version end - # Updates the `app_version` entry in the `Deliverfile` - # - # @param [String] new_version The new value to set the `app_version` entry to. - # @raise [UserError] If the Deliverfile was not found. - # - def self.update_fastlane_deliver(new_version) - fd_file = './fastlane/Deliverfile' - if File.exist?(fd_file) - Action.sh("sed -i '' \"s/app_version.*/app_version \\\"#{new_version}\\\"/\" #{fd_file}") - else - UI.user_error!("Can't find #{fd_file}.") - end - end - # Update the `.xcconfig` files (the public one, and the internal one if it exists) with the new version strings. # # @env PUBLIC_CONFIG_FILE The path to the xcconfig file containing the public version numbers. @@ -286,35 +297,15 @@ def self.read_build_number_from_config_file(filePath) # Read the value of a given key from an `.xcconfig` file. # # @param [String] key The xcconfig key to get the value for - # @param [String] filePath The path to the `.xcconfig` file to read the value from + # @param [String] file_path The path to the `.xcconfig` file to read the value from # # @return [String] The value for the given key, or `nil` if the key was not found. # - def self.read_from_config_file(key, filePath) - File.open(filePath, 'r') do |f| - f.each_line do |line| - line = line.strip() - return line.split('=')[1] if line.start_with?("#{key}=") - end - end - - return nil - end - - # Read the version numbers from the xcconfig file - # - # @env PUBLIC_CONFIG_FILE The path to the xcconfig file containing the public version numbers. - # @env INTERNAL_CONFIG_FILE The path to the xcconfig file containing the internal version numbers. Can be nil. - # - # @return [String] Array of long version strings found. - # The first element is always present and contains the version extracted from the public config file - # The second element is the version extracted from the internal config file, only present if one was provided. - def self.get_version_strings - version_strings = [] - version_strings << read_long_version_from_config_file(ENV['PUBLIC_CONFIG_FILE']) - version_strings << read_long_version_from_config_file(ENV['INTERNAL_CONFIG_FILE']) unless ENV['INTERNAL_CONFIG_FILE'].nil? + def self.read_from_config_file(key, file_path) + UI.user_error!(".xcconfig file #{file_path} not found") unless File.exist?(file_path) - return version_strings + config = Xcodeproj::Config.new(file_path) + config.attributes[key] end # Ensure that the version provided is only composed of number parts and return the validated string diff --git a/spec/ios_bump_version_release_spec.rb b/spec/ios_bump_version_release_spec.rb index f2a3f882e..10089ba72 100644 --- a/spec/ios_bump_version_release_spec.rb +++ b/spec/ios_bump_version_release_spec.rb @@ -2,7 +2,7 @@ describe Fastlane::Actions::IosBumpVersionReleaseAction do let(:default_branch) { 'my_new_branch' } - let(:versions) { ['6.30'] } + let(:version) { '6.30' } let(:next_version) { '6.31.0.0' } let(:next_version_short) { '6.31' } @@ -11,34 +11,17 @@ other_action_mock = double() allow(Fastlane::Action).to receive(:other_action).and_return(other_action_mock) allow(other_action_mock).to receive(:ensure_git_branch).with(branch: default_branch) - - allow(Fastlane::Helper::GitHelper).to receive(:checkout_and_pull).with(default_branch) - allow(Fastlane::Helper::GitHelper).to receive(:create_branch).with("release/#{next_version_short}", from: default_branch) - - allow(Fastlane::Helper::Ios::VersionHelper).to receive(:get_version_strings).and_return(versions) - allow(Fastlane::Helper::Ios::VersionHelper).to receive(:update_xc_configs).with(next_version, next_version_short, nil) - end - - it 'does the fastlane deliver update' do - skip_deliver = false - - expect(Fastlane::Helper::Ios::VersionHelper).to receive(:update_fastlane_deliver).with(next_version_short) - expect(Fastlane::Helper::Ios::GitHelper).to receive(:commit_version_bump).with(include_deliverfile: !skip_deliver, include_metadata: false) - - run_described_fastlane_action( - skip_deliver: skip_deliver, - default_branch: default_branch - ) + allow(Fastlane::Helper::Ios::VersionHelper).to receive(:read_from_config_file).and_return(version) end - it 'skips the fastlane deliver update properly' do - skip_deliver = true + it 'correctly uses the next version, short and long' do + expect(Fastlane::Helper::GitHelper).to receive(:checkout_and_pull).with(default_branch) + expect(Fastlane::Helper::GitHelper).to receive(:create_branch).with("release/#{next_version_short}", from: default_branch) - expect(Fastlane::Helper::Ios::VersionHelper).not_to receive(:update_fastlane_deliver) - expect(Fastlane::Helper::Ios::GitHelper).to receive(:commit_version_bump).with(include_deliverfile: !skip_deliver, include_metadata: false) + expect(Fastlane::Helper::Ios::VersionHelper).to receive(:update_xc_configs).with(next_version, next_version_short, nil) + expect(Fastlane::Helper::Ios::GitHelper).to receive(:commit_version_bump) run_described_fastlane_action( - skip_deliver: skip_deliver, default_branch: default_branch ) end diff --git a/spec/ios_get_app_version_spec.rb b/spec/ios_get_app_version_spec.rb new file mode 100644 index 000000000..0355fd175 --- /dev/null +++ b/spec/ios_get_app_version_spec.rb @@ -0,0 +1,87 @@ +require 'spec_helper' + +describe Fastlane::Actions::IosGetAppVersionAction do + describe 'getting the public app version from the provided .xcconfig file' do + it 'parses the xcconfig file format correctly and gets the public version' do + xcconfig_mock_content = <<~CONTENT + // a comment + VERSION_SHORT = 6 + VERSION_LONG = 6.30.0 + CONTENT + + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30') + end + + it 'parses the xcconfig file format correctly and gets the public hotfix version' do + xcconfig_mock_content = <<~CONTENT + VERSION_SHORT = 6 + // a comment + VERSION_LONG = 6.30.1 + CONTENT + + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30.1') + end + + it 'parses the xcconfig with keys without spacing and gets the public version' do + xcconfig_mock_content = <<~CONTENT + // a comment + VERSION_SHORT=6 + VERSION_LONG=6.30.0 + CONTENT + + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30') + end + + it 'parses the xcconfig with keys without spacing and gets the public hotfix version' do + xcconfig_mock_content = <<~CONTENT + VERSION_SHORT=6 + // a comment + VERSION_LONG=6.30.1 + CONTENT + + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30.1') + end + + it 'fails to extract the version from an xcconfig file with an invalid format' do + xcconfig_mock_content = <<~CONTENT + VERSION_SHORT = 6 + VERSION_LONG 6.30.1 + CONTENT + + expect do + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: 'n/a') + end.to raise_error(FastlaneCore::Interface::FastlaneError) + end + + it 'throws an error when the file is not found' do + file_path = 'file/not/found' + + expect do + run_described_fastlane_action( + public_version_xcconfig_file: file_path + ) + end.to raise_error(FastlaneCore::Interface::FastlaneError) + end + + it "throws an error when there isn't a version configured in the .xcconfig file" do + xcconfig_mock_content = <<~CONTENT + VERSION_SHORT = 6 + // a comment + CONTENT + + expect do + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: 'n/a') + end.to raise_error(FastlaneCore::Interface::FastlaneError) + end + + def expect_version(xcconfig_mock_content:, expected_version:) + with_tmp_file(named: 'mock_xcconfig.xcconfig', content: xcconfig_mock_content) do |tmp_file_path| + version_result = run_described_fastlane_action( + public_version_xcconfig_file: tmp_file_path + ) + + expect(version_result).to eq(expected_version) + end + end + end +end