class << self
def upload_binary(tag, github_token)
repo = sh("git", "remote", "get-url", "origin")
repo.sub!(/\.git$/, "")
repo = repo.split(/[:\/]/).last(2).join("/")
auth = ["-H", "Authorization: token #{github_token}"]
reply = sh("curl", *auth, "--data", {tag_name: tag}.to_json, "https://api.github.com/repos/#{repo}/releases")
id = JSON.parse(reply).fetch("id")
begin
name = Rubinjam.write(Dir.pwd)
sh(
"curl",
"-X", "POST",
"--data-binary", "@#{name}",
"-H", "Content-Type: application/octet-stream",
*auth,
"https://uploads.github.com/repos/#{repo}/releases/#{id}/assets?name=#{name}"
)
ensure
sh "rm", "-f", name.to_s
end
end
def sh(*command)
command = command.shelljoin
result = `#{command}`
raise "Command failed:\n#{command}\n#{result}" unless $?.success?
result
end
end