Skip to content

Commit

Permalink
fix: takes v* as a fallback for name of tag
Browse files Browse the repository at this point in the history
If it doesn't match tag for passed option it tries to find v* tag and
figure out what version we used last time.
  • Loading branch information
xotahal committed Oct 5, 2021
1 parent c507623 commit f93db15
Showing 1 changed file with 61 additions and 27 deletions.
88 changes: 61 additions & 27 deletions lib/fastlane/plugin/semantic_release/actions/analyze_commits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,76 @@ def self.get_commits_from_hash(params)
commits.split("|>")
end

def self.is_releasable(params)
# Hash of the commit where is the last version
# If the tag is not found we are taking HEAD as reference
hash = 'HEAD'
# Default last version
version = '0.0.0'
def self.get_beginning_of_next_sprint(params)
# command to get first commit
git_command = 'git rev-list --max-parents=0 HEAD'

tag = get_last_tag(
match: params[:match],
debug: params[:debug]
)
tag = get_last_tag(match: params[:match], debug: params[:debug])

# if tag doesn't exist it get's first commit or fallback tag (v*.*.*)
if tag.empty?
UI.message("First commit of the branch is taken as a begining of next release")
UI.message("It couldn't match tag for #{params[:match]}. Check if first commit can be taken as a beginning of next release")
# If there is no tag found we taking the first commit of current branch
hash = Actions.sh('git rev-list --max-parents=0 HEAD', log: params[:debug]).chomp
else
# Tag's format is v2.3.4-5-g7685948
# See git describe man page for more info
tag_name = tag.split('-')[0...-2].join('-').strip
parsed_version = tag_name.match(params[:tag_version_match])

if parsed_version.nil?
UI.user_error!("Error while parsing version from tag #{tag_name} by using tag_version_match - #{params[:tag_version_match]}. Please check if the tag contains version as you expect and if you are using single brackets for tag_version_match parameter.")
hash_lines = Actions.sh("#{git_command} | wc -l", log: params[:debug]).chomp

if hash_lines.to_i == 1
UI.message("First commit of the branch is taken as a begining of next release")
return {
# here we know this command will return 1 line
hash: Actions.sh(git_command, log: params[:debug]).chomp
}
end

version = parsed_version[0]
# Get a hash of last version tag
hash = get_last_tag_hash(
tag_name: tag_name,
debug: params[:debug]
)
# neighter matched tag and first hash could be used - as fallback we try vX.Y.Z
UI.message("It couldn't match tag for #{params[:match]} and couldn't use first commit. Check if tag vX.Y.Z can be taken as a begining of next release")
tag = get_last_tag(match: "v*", debug: params[:debug])

# even fallback tag doesn't work
if tag.empty?
return false
end
end

# Tag's format is v2.3.4-5-g7685948
# See git describe man page for more info
tag_name = tag.split('-')[0...-2].join('-').strip
parsed_version = tag_name.match(params[:tag_version_match])

if parsed_version.nil?
UI.user_error!("Error while parsing version from tag #{tag_name} by using tag_version_match - #{params[:tag_version_match]}. Please check if the tag contains version as you expect and if you are using single brackets for tag_version_match parameter.")
end

UI.message("Found a tag #{tag_name} associated with version #{version}")
version = parsed_version[0]
# Get a hash of last version tag
hash = get_last_tag_hash(
tag_name: tag_name,
debug: params[:debug]
)

UI.message("Found a tag #{tag_name} associated with version #{version}")

return {
hash: hash,
version: version
}
end

def self.is_releasable(params)
# Hash of the commit where is the last version
beginning = get_beginning_of_next_sprint(params)

unless beginning
UI.error('It could not find a begining of this sprint. How to fix this:')
UI.error('-- ensure there is only one commit with --max-parents=0 (this command should return one line: "git rev-list --max-parents=0 HEAD")')
UI.error('-- tell us explicitely where the release starts by adding tag like this: vX.Y.Z (where X.Y.Z is version from which it starts computing next version number)')
return false
end

# Default last version
version = beginning[:version] || '0.0.0'
# If the tag is not found we are taking HEAD as reference
hash = beginning[:hash] || 'HEAD'

# converts last version string to the int numbers
next_major = (version.split('.')[0] || 0).to_i
next_minor = (version.split('.')[1] || 0).to_i
Expand Down

0 comments on commit f93db15

Please sign in to comment.