Skip to content

Commit

Permalink
Add support for prerelease tags
Browse files Browse the repository at this point in the history
Add a new regex entry in the config for prerelease tags

Process prerelease and release tags separately and mark them
appropriately in the API

Signed-off-by: Doug Ledford <[email protected]>
  • Loading branch information
dledford committed Mar 25, 2017
1 parent 3c146fd commit 5912aea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ differently. None of them should be required for normal, sane use.
you might have decided to make. Only tags which match this regular
expression will be pushed up by `git release`, and only those tags will
be marked as releases.

* `release.pre-regex` (default `v\d+\.\d+(\.\d+)?(-rc\d+.*){1}$`) -- The
regular expression to filter which tages denote prereleases. Only tags
which match this regular expression will be pushed up by `git release`,
and these will be marked as Pre-release on the github release pages.
25 changes: 22 additions & 3 deletions lib/github-release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@

class GithubRelease
def run
new_prereleases = tagged_prereleases.select { |p| !github_releases.include?(p) }

if new_prereleases.empty?
puts "No new pre-release tags to push."
end

new_prereleases.each { |t| create_release(t, true) }

new_releases = tagged_releases.select { |r| !github_releases.include?(r) }

if new_releases.empty?
puts "No new release tags to push."
end

new_releases.each { |t| create_release(t) }
new_releases.each { |t| create_release(t, false) }

puts "All done!"
end
Expand Down Expand Up @@ -52,6 +60,12 @@ def get_new_token
log_val(token)
end

def pre_regex
@pre_regex ||= `git config --get release.pre-regex`.strip
@pre_regex = /^v\d+\.\d+(\.\d+)?(-rc\d+.*){1}$/ if @pre_regex.empty?
log_val(@pre_regex)
end

def tag_regex
@tag_regex ||= `git config --get release.tag-regex`.strip
@tag_regex = /^v\d+\.\d+(\.\d+)?$/ if @tag_regex.empty?
Expand All @@ -63,6 +77,11 @@ def tagged_releases
log_val(@tagged_releases)
end

def tagged_prereleases
@tagged_prereleases ||= `git tag`.split("\n").map(&:strip).grep pre_regex
log_val(@tagged_prereleases)
end

def repo_name
@repo_name ||= begin
case repo_url
Expand Down Expand Up @@ -106,7 +125,7 @@ def git_config(item, default = nil)
log_val(@config_cache[item], item)
end

def create_release(tag)
def create_release(tag, prerelease)
puts "Pushing to #{remote_name}..."
system("git push #{remote_name} tag #{tag}")

Expand All @@ -118,7 +137,7 @@ def create_release(tag)
name = name.gsub(/^#{tag}/, '').strip
body = body.split("\n").map { |l| l.sub(/^ /, '') }.join("\n")

api.create_release(repo_name, tag, :name => name, :body => body)
api.create_release(repo_name, tag, :name => name, :body => body, :prerelease => prerelease)

puts " done!"
end
Expand Down

0 comments on commit 5912aea

Please sign in to comment.