forked from mdaines/viz-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.rb
53 lines (39 loc) · 1.58 KB
/
deploy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require "octokit"
require "git"
require "shellwords"
require "json"
project_name = "Viz.js"
repo_slug = ENV["TRAVIS_REPO_SLUG"]
release_tag_name = ENV["TRAVIS_TAG"]
build_dir = ENV["TRAVIS_BUILD_DIR"]
asset_paths = ["viz.js", "viz.es.js", "full.render.js", "lite.render.js"].map { |name| File.join(build_dir, name) }
# Validate that version numbers match
raise "Invalid tag name: #{release_tag_name}" unless release_tag_name =~ /^v(\d+\.\d+\.\d+(?:-pre\.\d+)?)$/
version = $1
is_prerelease = version.include?("-pre")
asset_paths.each do |path|
unless File.read(path).include?("#{project_name} #{version}")
raise "Asset has incorrect version number: #{path}"
end
end
npm_package_json = JSON.parse(File.read("package.json"))
unless npm_package_json["version"] == version
raise "package.json has incorrect version number"
end
# Create release and upload assets
client = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
local_repo = Git.open(build_dir)
local_tag = local_repo.tag(release_tag_name)
puts "Creating release for tag #{release_tag_name}..."
puts local_tag.message
release = client.create_release(repo_slug, release_tag_name, :name => release_tag_name, :body => local_tag.message, :prerelease => is_prerelease)
puts "Uploading release assets..."
asset_paths.each do |path|
client.upload_asset(release[:url], path, :content_type => "application/javascript", :name => File.basename(path))
end
puts "Publishing #{version}..."
if is_prerelease
system Shellwords.join(["npm", "publish", "--tag", "next", build_dir])
else
system Shellwords.join(["npm", "publish", build_dir])
end