Skip to content

Commit

Permalink
feat: add 'single_step' mode
Browse files Browse the repository at this point in the history
This is an optional mode where the version number will only be incremented by the minimum possible amount, regardless of how many underlying commits there were.
For example, assume the last release was v1.2.3 and your commit log is as follows:

  fix: ...
  feat: ...
  fix: ...
  fix: ...

If single_step is false (the default), this will result in the generated next version v1.3.2.
Setting single_step to true, however, will result in the version v1.3.0.
  • Loading branch information
thislooksfun committed Jun 16, 2020
1 parent 107e998 commit f54565e
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions lib/fastlane/plugin/semantic_release/actions/analyze_commits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def self.is_releasable(params)
next_minor = (version.split('.')[1] || 0).to_i
next_patch = (version.split('.')[2] || 0).to_i

# setup for single-step mode
single_step = params[:single_step]
bumped_major = false
bumped_minor = false
bumped_patch = false

# Get commits log between last version and head
splitted = get_commits_from_hash(
hash: hash,
Expand Down Expand Up @@ -107,14 +113,26 @@ def self.is_releasable(params)
end

if commit[:release] == "major" || commit[:is_breaking_change]
next_major += 1
next_minor = 0
next_patch = 0
unless bumped_major
next_major += 1
next_minor = 0
next_patch = 0
bumped_major = single_step
bumped_minor = single_step
bumped_patch = single_step
end
elsif commit[:release] == "minor"
next_minor += 1
next_patch = 0
unless bumped_major
next_minor += 1
next_patch = 0
bumped_minor = single_step
bumped_patch = single_step
end
elsif commit[:release] == "patch"
next_patch += 1
unless bumped_patch
next_patch += 1
bumped_patch = single_step
end
end

next_version = "#{next_major}.#{next_minor}.#{next_patch}"
Expand Down Expand Up @@ -143,6 +161,14 @@ def self.is_releasable(params)
end

def self.is_codepush_friendly(params)
if params[:single_step]
# If single-step mode is selected, skip checking last codepush version
# as it is likely in the middle of a release.
UI.important("Skipping RELEASE_LAST_INCOMPATIBLE_CODEPUSH_VERSION because single_step was set")
Actions.lane_context[SharedValues::RELEASE_LAST_INCOMPATIBLE_CODEPUSH_VERSION] = "0.0.0"
return false
end

git_command = 'git rev-list --max-parents=0 HEAD'
# Begining of the branch is taken for codepush analysis
hash_lines = Actions.sh("#{git_command} | wc -l", log: params[:debug]).chomp
Expand Down Expand Up @@ -252,6 +278,13 @@ def self.available_options
type: Array,
optional: true
),
FastlaneCore::ConfigItem.new(
key: :single_step,
description: "Only update the new version by the minimal amount",
default_value: false,
type: Boolean,
optional: true
),
FastlaneCore::ConfigItem.new(
key: :debug,
description: "True if you want to log out a debug info",
Expand Down

0 comments on commit f54565e

Please sign in to comment.