Skip to content

Commit

Permalink
fix(ci): find tag from remote
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed Jun 29, 2023
1 parent 03d1c34 commit fd1ddac
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,29 @@ def upload_test(build_prefix, tag_prefix, browserstack_username, browserstack_ac
# update xcconfig
update_xcconfig

# Get tags that matches the pattern
tags = sh("git tag --list '#{tag_prefix}/#{build_prefix.to_s}.*'").strip.split("\n")
# Get the remote origin URL
remote_url = sh("git config --get remote.origin.url").strip

# Sort the tags in descending order
sorted_tags = tags.sort { |a, b| Gem::Version.new(b.split('.').last) <=> Gem::Version.new(a.split('.').last) }
# Get the tags matching the pattern (build_prefix.*)
tags = sh("git ls-remote --tags #{remote_url} '#{tag_prefix}/#{build_prefix.to_s}.*'").strip.split("\n")

# Extract the number from the last tag
last_tag = sorted_tags.first
number_of_released_builds = last_tag ? last_tag.split('.').last.to_i : 0
# Extract the tag names from the ls-remote output
tag_names = tags.map { |tag| tag.split("\t")[1].split("/").last }

puts "Pushed tags suffix #{tag_names}"

# Find last build number
if tag_names.empty?
number_of_released_builds = 0
else
# Sort the tag names in descending order
sorted_build_numbers = tag_names
.map { |tag| tag.split(".").last.to_i }
.sort { |a, b| b <=> a }

# Extract the number following the dot in the tag
number_of_released_builds = sorted_build_numbers.first
end

# Increase the number to create new tag
build_number = number_of_released_builds + 1
Expand Down

0 comments on commit fd1ddac

Please sign in to comment.