Last active
September 17, 2016 00:49
-
-
Save geraint0923/f392cd3cdb88f513fa02ec7f0d578a5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # This script is to add a release not on Github | |
| # | |
| # Requirement: | |
| # Octokit.rb (gem install octokit) | |
| # pandoc (for Mac: brew install pandoc) | |
| # | |
| # You must have $GITHUB_KEY exported in your .bashrc or .zshrc | |
| # HELP: https://help.github.com/articles/creating-an-access-token-for-command-line-use/ | |
| # export GITHUB_KEY="replace with your Github access token" | |
| # | |
| # Usage: | |
| # | |
| # Create release notes for all existing tags | |
| # ruby ./release.rb | |
| # | |
| # Create release note for specified tags(e.g. 0.125) | |
| # ruby ./release.rb 0.125 | |
| # Config repo info | |
| $path = '/PATH/TO/presto' | |
| $repo = 'OWNER/presto' | |
| ###################################################################################################### | |
| require 'octokit' | |
| require 'set' | |
| Octokit.auto_paginate = true | |
| $access_token = `echo $GITHUB_KEY`.strip | |
| $options_template = { | |
| :target_commitish => 'master', | |
| :name => '', | |
| :body => '', | |
| :draft => false, | |
| :prerelease => false | |
| } | |
| def create_release(tag_name, name, body) | |
| client = Octokit::Client.new(:access_token => $access_token) | |
| options = $options_template.clone | |
| options[:name] = name | |
| options[:body] = body | |
| client.create_release($repo, tag_name, options) | |
| end | |
| def create_release_for_version(version) | |
| md_content = `pandoc -f rst -t markdown_github -s #{$path}/presto-docs/src/main/sphinx/release/release-#{version}.rst -o - 2> /dev/null` | |
| create_release(version, version, md_content) | |
| end | |
| def build_tag_set() | |
| Set.new(Octokit::Client.new(:access_token => $access_token).tags($repo).map {|tag| tag[:name] }) | |
| end | |
| if ARGV.empty? | |
| tag_set = build_tag_set | |
| Dir["#{$path}/presto-docs/src/main/sphinx/release/*.rst"].each do |rst| | |
| basename = File.basename(rst) | |
| match = /release-(.+).rst/.match(basename) | |
| if match | |
| version = match[1] | |
| if version.split('.').length == 2 and tag_set.include?(version) | |
| puts "Creating release for #{version}..." | |
| begin | |
| create_release_for_version(version) | |
| rescue SystemExit, Interrupt | |
| raise | |
| rescue Exception => e | |
| puts "Failed" | |
| end | |
| else | |
| puts "Skip #{version}..." | |
| end | |
| end | |
| end | |
| else | |
| tag_set = build_tag_set | |
| version = ARGV[0] | |
| if tag_set.include?(version) | |
| puts "Creating release for #{version}..." | |
| begin | |
| create_release_for_version(version) | |
| rescue SystemExit, Interrupt | |
| raise | |
| rescue Exception => e | |
| puts "Failed" | |
| end | |
| else | |
| puts "Skip #{version}..." | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment