diff --git a/tasks/update_components.rake b/tasks/update_components.rake index a396aca0..1a9b56d1 100644 --- a/tasks/update_components.rake +++ b/tasks/update_components.rake @@ -24,12 +24,17 @@ def github_owner_repo(url) [Regexp.last_match(1), Regexp.last_match(2).sub(/\.git$/, '')] end -# Normalize a version string by stripping common tag prefixes. +# Normalize a version string by stripping common tag prefixes and +# replacing underscores with . def normalize_version(tag) + return nil if tag.nil? + tag.sub(/\Av(?=\d)/, '') .sub(/\Arefs\/tags\/v?/, '') .sub(/\Arelease-/, '') .sub(/\Aopenssl-/, '') + .sub(/\Acurl-/, '') + .gsub('_', '.') end # Try to parse a version from a normalized string, returning nil if unparseable. @@ -50,11 +55,12 @@ end # and somme people, like openssl, maintain multiple streams. So the latest tag might not be the highest version # We do some version comparison to find the actual highest version def latest_github_tag(owner, repo) - github_client.tags("#{owner}/#{repo}", per_page: 100) - .map { |tag| [tag.name, try_version(normalize_version(tag.name))] } - .reject { |_, version| version.nil? || version.prerelease? } - .max_by { |_, version| version } - .first + tags = github_client.tags("#{owner}/#{repo}", per_page: 100) + .map { |tag| [tag.name, try_version(normalize_version(tag.name))] } + .reject { |_, version| version.nil? || version.prerelease? } + .max_by { |_, version| version } + + tags.nil? ? tags : tags.first end def current_version(data)