Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Semantic Versioning for Git tags #16

Merged
merged 2 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions lib/ra10ke.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'ra10ke/version'
require 'ra10ke/solve'
require 'git'
require 'semverse'

module Ra10ke
class RakeTask < ::Rake::TaskLib
Expand Down Expand Up @@ -35,35 +36,38 @@ def initialize(*args)
end

if puppet_module.class == R10K::Module::Git
remote = puppet_module.instance_variable_get(:@remote)

# use helper; avoid `desired_ref`
# we do not want to deal with `:control_branch`
ref = puppet_module.version
next unless ref

remote = puppet_module.instance_variable_get(:@remote)
remote_refs = Git.ls_remote(remote)

# skip if ref is a branch
next if remote_refs['branches'].key?(ref)

ref_type = 'sha' if ref.match(/^[a-z0-9]{40}$/)
ref_type = 'tag' if remote_refs['tags'].key?(ref)
case ref_type
when 'sha'
if remote_refs['tags'].key?(ref)
# there are too many possible versioning conventions
# we have to be be opinionated here
# so semantic versioning (vX.Y.Z) it is for us
# as well as support for skipping the leading v letter
tags = remote_refs['tags'].keys
latest_tag = tags.map do |tag|
begin
Semverse::Version.new tag
rescue Semverse::InvalidVersionFormat
# ignore tags that do not comply to semver
nil
end
end.select { |tag| !tag.nil? }.sort.last.to_s.downcase
latest_ref = tags.detect { |tag| tag.downcase == latest_tag || tag.downcase == latest_tag[1..-1] }
Copy link
Contributor Author

@sigv sigv Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, tag.downcase == latest_tag[1..-1] here could use an extra latest_tag[0] == 'v' check.

latest_ref = 'undef (tags do not match semantic versioning)' if latest_ref.nil?
elsif ref.match(/^[a-z0-9]{40}$/)
# for sha just assume head should be tracked
latest_ref = remote_refs['head'][:sha]
when 'tag'
# we have to be opinionated here, due to multiple conventions only the two main will be accepted
# v#.#.# or #.#.# is what we will pick.
if ref.match(/^[vV]?\d[\.\d]*/)
tags = remote_refs['tags']
version_tags = tags.select { |f| /^[vV]?\d[\.\d]*$/.match(f) }
latest_ref = version_tags.keys.sort.last
else
latest_ref = "undef (tags don't match v#.#.# or #.#.#)"
end
else
raise "Unable to determine ref_type for #{puppet_module.title}"
raise "Unable to determine ref type for #{puppet_module.title}"
end

puts "#{puppet_module.title} is OUTDATED: #{ref} vs #{latest_ref}" if ref != latest_ref
Expand Down
1 change: 1 addition & 0 deletions ra10ke.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "r10k"
spec.add_dependency "git"
spec.add_dependency "solve"
spec.add_dependency 'semverse', '~> 2.0'
end