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

Feature: Checkout latest release tag #603

Open
elfranne opened this issue May 3, 2023 · 0 comments
Open

Feature: Checkout latest release tag #603

elfranne opened this issue May 3, 2023 · 0 comments

Comments

@elfranne
Copy link

elfranne commented May 3, 2023

Use Case

Ability to checkout the latest release.

Describe the Solution You Would Like

Currently i made a custom lib to call Github API which is a simplified version of https://github.com/takumakume/puppet-github-release-properties :

require 'net/http'
require 'uri'
require 'json'
require 'stringio'

Puppet::Functions.create_function(:latest_git_tag) do
  dispatch :latest_git_tag do
    param 'String', :repo
  end

  def latest_git_tag(repo)
    uri = URI.parse("https://api.github.com/repos/#{repo}/releases/latest")
    http = Net::HTTP.new(uri.host, uri.port)
    http.open_timeout = 10
    http.read_timeout = 15
    http.use_ssl = true

    request = Net::HTTP::Get.new(uri)
    request['Content-Type']    = 'application/json'
    request['Accept']          = 'application/vnd.github.v3+json'
    request['Accept-Encoding'] = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'

    response = http.request(request)
    raise "#{response.code} #{response.message}: #{uri}" unless response.class == Net::HTTPOK
    
    raw_body = if response.header['Content-Encoding'].eql?('gzip')
      Zlib::GzipReader.new(StringIO.new(response.body)).read
    else
      response.body
    end
    return JSON.load(raw_body)['tag_name']
  end
end

That I use like that :

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
  revision => latest_git_tag('puppetlabs/puppetlabs-vcsrepo'),
}

Describe Alternatives You've Considered

Downloading the tarball might be an option ?

Additional Context

This is a very simplified that fit my very specific needs (Github). Is there a better way ? Feedback is very welcome !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants