Android Version Bump to 29 (#549)
* Fastlane android version_code specific to mattermost-mobile * Version Bump to 29
This commit is contained in:
parent
f0d2b4b211
commit
e2180e511c
6 changed files with 250 additions and 9 deletions
|
|
@ -91,7 +91,7 @@ android {
|
|||
applicationId "com.mattermost.react.native"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 23
|
||||
versionCode 28
|
||||
versionCode 29
|
||||
versionName "1.0"
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
|
|
|
|||
|
|
@ -322,8 +322,8 @@ platform :android do
|
|||
end
|
||||
|
||||
if options[:increment_build]
|
||||
increment_version_code(app_folder_name: 'android/app')
|
||||
commit_android_version_bump(
|
||||
android_increment_version_code(app_folder_name: 'android/app')
|
||||
android_commit_version_bump(
|
||||
app_folder_name: 'android/app',
|
||||
force: true
|
||||
)
|
||||
|
|
|
|||
|
|
@ -54,8 +54,6 @@ GEM
|
|||
xcodeproj (>= 1.4.4, < 2.0.0)
|
||||
xcpretty (>= 0.2.4, < 1.0.0)
|
||||
xcpretty-travis-formatter (>= 0.0.3)
|
||||
fastlane-plugin-commit_android_version_bump (0.1.3)
|
||||
fastlane-plugin-increment_version_code (0.3.1)
|
||||
gh_inspector (1.0.3)
|
||||
google-api-client (0.9.28)
|
||||
addressable (~> 2.3)
|
||||
|
|
@ -134,8 +132,6 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
fastlane
|
||||
fastlane-plugin-commit_android_version_bump
|
||||
fastlane-plugin-increment_version_code
|
||||
|
||||
BUNDLED WITH
|
||||
1.13.7
|
||||
|
|
|
|||
|
|
@ -2,5 +2,3 @@
|
|||
#
|
||||
# Ensure this file is checked in to source control!
|
||||
|
||||
gem 'fastlane-plugin-increment_version_code'
|
||||
gem 'fastlane-plugin-commit_android_version_bump'
|
||||
|
|
|
|||
131
fastlane/actions/android_commit_version_bump.rb
Normal file
131
fastlane/actions/android_commit_version_bump.rb
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
module Fastlane
|
||||
module Actions
|
||||
class AndroidCommitVersionBumpAction < Action
|
||||
def self.run(params)
|
||||
require 'xcodeproj'
|
||||
require 'pathname'
|
||||
require 'set'
|
||||
require 'shellwords'
|
||||
|
||||
app_folder_name ||= params[:app_folder_name]
|
||||
UI.message("The commit_android_version_bump plugin is looking inside your project folder (#{app_folder_name})!")
|
||||
|
||||
build_folder_paths = Dir[File.expand_path(File.join('**/',app_folder_name))].reject { |file| file.include?('build/') || file.include?('node_modules')}
|
||||
# no build.gradle found: error
|
||||
UI.user_error!('Could not find a build folder in the current repository\'s working directory.') if build_folder_paths.count == 0
|
||||
|
||||
UI.message("Found the following project path: #{build_folder_paths}")
|
||||
# too many projects found: error
|
||||
if build_folder_paths.count > 1
|
||||
UI.user_error!("Found multiple build.gradle projects in the current repository's working directory.")
|
||||
end
|
||||
|
||||
build_folder_path = build_folder_paths.first
|
||||
|
||||
# find the repo root path
|
||||
repo_path = Actions.sh("git -C #{build_folder_path} rev-parse --show-toplevel").strip
|
||||
repo_pathname = Pathname.new(repo_path)
|
||||
|
||||
|
||||
build_file_paths = Dir[File.expand_path(File.join('**/',app_folder_name,'build.gradle'))].reject { |file| file.include?('build/') || file.include?('node_modules')}
|
||||
|
||||
# no build.gradle found: error
|
||||
UI.user_error!('Could not find a build.gradle in the current repository\'s working directory.') if build_file_paths.count == 0
|
||||
# too many projects found: error
|
||||
if build_file_paths.count > 1
|
||||
UI.user_error!("Found multiple build.gradle projects in the current repository's working directory.")
|
||||
end
|
||||
|
||||
build_file_path = build_file_paths.first
|
||||
build_file_path.replace build_file_path.sub("#{repo_pathname}/", "")
|
||||
|
||||
# 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 << build_file_path
|
||||
|
||||
# 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")
|
||||
|
||||
# little user hint
|
||||
UI.user_error!("No file changes picked up. Make sure you run the `increment_version_code` action first.") if git_dirty_files.empty?
|
||||
|
||||
# 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}", "./")#.gsub(repo_pathname, ".")
|
||||
puts " -- updated = #{updated}".yellow
|
||||
File.expand_path(File.join(repo_pathname, updated))
|
||||
end
|
||||
|
||||
# then create a commit with a message
|
||||
Actions.sh("git -C #{repo_path} add #{git_add_paths.map(&:shellescape).join(' ')}")
|
||||
|
||||
begin
|
||||
version_code = Actions.lane_context["VERSION_CODE"]
|
||||
|
||||
params[:message] ||= (version_code ? "Version Bump to #{version_code}" : "Version Bump")
|
||||
|
||||
Actions.sh("git -C #{repo_path} commit -m '#{params[:message]}'")
|
||||
|
||||
UI.success("Committed \"#{params[:message]}\" 💾.")
|
||||
rescue => ex
|
||||
UI.error(ex)
|
||||
|
||||
UI.important("Didn't commit any changes.")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.description
|
||||
"This Android plugins allow you to commit every modification done in your build.gradle file during the execution of a lane. In fast, it do the same as the commit_version_bump action, but for Android"
|
||||
end
|
||||
|
||||
def self.authors
|
||||
["jems"]
|
||||
end
|
||||
|
||||
def self.available_options
|
||||
[
|
||||
FastlaneCore::ConfigItem.new(key: :message,
|
||||
env_name: "CVB_COMMIT_BUMP_MESSAGE",
|
||||
description: "The commit message when committing the version bump",
|
||||
optional: true),
|
||||
FastlaneCore::ConfigItem.new(key: :app_folder_name,
|
||||
env_name: "CVB_APP_VERSION_NAME",
|
||||
description: "The name of the application source folder in the Android project (default: app)",
|
||||
optional: true,
|
||||
type: String,
|
||||
default_value:"app"),
|
||||
FastlaneCore::ConfigItem.new(key: :force,
|
||||
env_name: "CVB_FORCE_COMMIT",
|
||||
description: "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)
|
||||
]
|
||||
end
|
||||
|
||||
def self.is_supported?(platform)
|
||||
[:android].include?(platform)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
116
fastlane/actions/android_increment_version_code.rb
Normal file
116
fastlane/actions/android_increment_version_code.rb
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
# rubocop:disable Style/CaseEquality
|
||||
# rubocop:disable Style/MultilineTernaryOperator
|
||||
# rubocop:disable Style/NestedTernaryOperator
|
||||
|
||||
require 'tempfile'
|
||||
require 'fileutils'
|
||||
|
||||
module Fastlane
|
||||
module Actions
|
||||
class AndroidIncrementVersionCodeAction < Action
|
||||
def self.run(params)
|
||||
app_folder_name ||= params[:app_folder_name]
|
||||
UI.message("The get_version_code plugin is looking inside your project folder (#{app_folder_name})!")
|
||||
|
||||
version_code = "0"
|
||||
new_version_code ||= params[:version_code]
|
||||
UI.message("new version code = #{new_version_code}")
|
||||
|
||||
temp_file = Tempfile.new('fastlaneIncrementVersionCode')
|
||||
foundVersionCode = "false"
|
||||
Dir.glob("#{app_folder_name}/build.gradle") do |path|
|
||||
UI.message(" -> Found a build.gradle file at path: (#{path})!")
|
||||
begin
|
||||
temp_file = Tempfile.new('fastlaneIncrementVersionCode')
|
||||
File.open(path, 'r') do |file|
|
||||
file.each_line do |line|
|
||||
if line.include? "versionCode " and foundVersionCode=="false"
|
||||
|
||||
versionComponents = line.strip.split(' ')
|
||||
version_code = versionComponents[1].tr("\"","")
|
||||
if new_version_code <= 0
|
||||
new_version_code = version_code.to_i + 1
|
||||
end
|
||||
if !!(version_code =~ /\A[-+]?[0-9]+\z/)
|
||||
line.replace line.sub(version_code, new_version_code.to_s)
|
||||
foundVersionCode = "true"
|
||||
end
|
||||
temp_file.puts line
|
||||
else
|
||||
temp_file.puts line
|
||||
end
|
||||
end
|
||||
|
||||
if foundVersionCode=="true"
|
||||
break
|
||||
end
|
||||
file.close
|
||||
end
|
||||
temp_file.rewind
|
||||
temp_file.close
|
||||
FileUtils.mv(temp_file.path, path)
|
||||
temp_file.unlink
|
||||
ensure
|
||||
if foundVersionCode=="true"
|
||||
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if version_code == "0" || new_version_code == "1"
|
||||
UI.user_error!("Impossible to find the version code in the current project folder #{app_folder_name} 😭")
|
||||
else
|
||||
# Store the version name in the shared hash
|
||||
Actions.lane_context["VERSION_CODE"]=new_version_code
|
||||
UI.success("☝️ Version code has been changed from #{version_code} to #{new_version_code}")
|
||||
end
|
||||
|
||||
return new_version_code
|
||||
end
|
||||
|
||||
def self.description
|
||||
"Increment the version code of your android project."
|
||||
end
|
||||
|
||||
def self.authors
|
||||
["Jérémy TOUDIC"]
|
||||
end
|
||||
|
||||
def self.available_options
|
||||
[
|
||||
FastlaneCore::ConfigItem.new(key: :app_folder_name,
|
||||
env_name: "INCREMENTVERSIONCODE_APP_FOLDER_NAME",
|
||||
description: "The name of the application source folder in the Android project (default: app)",
|
||||
optional: true,
|
||||
type: String,
|
||||
default_value:"app"),
|
||||
FastlaneCore::ConfigItem.new(key: :version_code,
|
||||
env_name: "INCREMENTVERSIONCODE_VERSION_CODE",
|
||||
description: "Change to a specific version (optional)",
|
||||
optional: true,
|
||||
type: Integer,
|
||||
default_value: 0)
|
||||
]
|
||||
end
|
||||
|
||||
def self.output
|
||||
[
|
||||
['VERSION_CODE', 'The new version code of the project']
|
||||
]
|
||||
end
|
||||
|
||||
def self.is_supported?(platform)
|
||||
[:android].include?(platform)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# rubocop:enable Style/CaseEquality
|
||||
# rubocop:enable Style/MultilineTernaryOperator
|
||||
# rubocop:enable Style/NestedTernaryOperator
|
||||
Loading…
Reference in a new issue