Class: Fastlane::Actions::AndroidCommitVersionBumpAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::AndroidCommitVersionBumpAction
- Defined in:
- lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .build_git_command_add(repo_path, paths) ⇒ Object
- .build_git_command_commit(params, repo_path) ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
67 68 69 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 67 def self. ["futabooo"] end |
.available_options ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 79 def self. [ FastlaneCore::ConfigItem.new(key: :gradle_file, env_name: "FL_ANDROID_COMMIT_VERSION_BUMP_GRADLE_FILE", description: "(optional) Specify the path to your app build.gradle if it isn't in the default location", optional: true, type: String, default_value: "app/build.gradle"), FastlaneCore::ConfigItem.new(key: :message, env_name: "FL_ANDROID_COMMIT_VERSION_BUMP_COMMIT_MESSAGE", description: "(optional) The commit message when committing the version bump", optional: true), FastlaneCore::ConfigItem.new(key: :force, env_name: "FL_ANDROID_COMMIT_VERSION_BUMP_FORCE_COMMIT", description: "(optional) Forces the commit, even if other files than the ones containing the version number have been modified", optional: true, default_value: false, is_string: false), FastlaneCore::ConfigItem.new(key: :no_verify, env_name: "FL_ANDROID_COMMIT_VERSION_BUMP_GIT_PUSH_USE_NO_VERIFY", description: "Whether or not to use --no-verify", type: Boolean, default_value: false) ] end |
.build_git_command_add(repo_path, paths) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 110 def build_git_command_add(repo_path, paths) command = ['git', '-C', "'#{repo_path}'", 'add', "'#{paths}'"] return command.join(' ') end |
.build_git_command_commit(params, repo_path) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 120 def build_git_command_commit(params, repo_path) version_code = Actions.lane_context[SharedValues::ANDROID_NEW_VERSION_CODE] params[:message] ||= (version_code ? "Version Bump to #{version_code}" : "Version Bump") command = [ 'git', '-C', "'#{repo_path}'", 'commit', '-m', "'#{params[:message]}'" ] command << '--no-verify' if params[:no_verify] return command.join(' ') end |
.description ⇒ Object
63 64 65 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 63 def self.description "This action is like a commit_version_bump action for Android" end |
.details ⇒ Object
75 76 77 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 75 def self.details # Optional: end |
.is_supported?(platform) ⇒ Boolean
105 106 107 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 105 def self.is_supported?(platform) platform == :android end |
.return_value ⇒ Object
71 72 73 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 71 def self.return_value # If your method provides a return value, you can describe here what it does end |
.run(params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fastlane/plugin/android_version_manage/actions/android_commit_version_bump.rb', line 4 def self.run(params) require 'pathname' require 'set' require 'shellwords' gradle_file_path = File.(params[:gradle_file]).shellescape absolute_path = File.dirname(gradle_file_path) repo_path = Actions.sh("git -C #{absolute_path} rev-parse --show-toplevel").strip repo_pathname = Pathname.new(repo_path) # create our list of files that we expect to have changed, they should all be relative to the project root, which should be equal to the git workdir root expected_changed_files = [] expected_changed_files << params[:gradle_file] # get the list of files that have actually changed in our git workdir git_dirty_files = Actions.sh("git -C #{repo_path} diff --name-only HEAD").split("\n") + Actions.sh("git -C #{repo_path} ls-files --other --exclude-standard").split("\n") if git_dirty_files.empty? UI.user_error!("No file changes picked up. Make sure you run the `increment_version_code` action first.") end # check if the files changed are the ones we expected to change (these should be only the files that have version info in them) changed_files_as_expected = Set.new(git_dirty_files.map(&:downcase)).subset?(Set.new(expected_changed_files.map(&:downcase))) unless changed_files_as_expected unless params[:force] error = [ "Found unexpected uncommited changes in the working directory. Expected these files to have ", "changed: \n#{expected_changed_files.join("\n")}.\nBut found these actual changes: ", "#{git_dirty_files.join("\n")}.\nMake sure you have cleaned up the build artifacts and ", "are only left with the changed version files at this stage in your lane, and don't touch the ", "working directory while your lane is running. You can also use the :force option to bypass this ", "check, and always commit a version bump regardless of the state of the working directory." ].join("\n") UI.user_error!(error) end end # get the absolute paths to the files git_add_paths = expected_changed_files.map do |path| updated = path updated.replace(updated.sub(repo_pathname.to_s, "./")) # .gsub(repo_pathname, ".") puts(" -- updated = #{updated}".yellow) File.(File.join(repo_pathname, updated)) end # then create a commit with a message command_add = build_git_command_add(repo_path, git_add_paths.map(&:shellescape).join(' ')) Actions.sh(command_add) begin command_commit = build_git_command_commit(params, repo_path) Actions.sh(command_commit) UI.success("Committed \"#{params[:message]}\" 💾.") rescue => ex UI.error(ex) UI.important("Didn't commit any changes.") end end |