Skip to content

Commit

Permalink
Add release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Apr 21, 2017
1 parent 6dac797 commit 47a36ae
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mruby/
dist/
*.tar.xz
.mrb
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ifdef VERSION
else
VERSION := $(shell sh -c 'git describe --always --tags')
endif

build-all:
rm -rf ./dist
rm -rf ./mruby/build/macos*
rm -rf ./mruby/build/linux*
rake host_clean
BUILD_TARGET=darwin-x86_64 rake compile
rake host_clean
docker-compose run --rm -e BUILD_TARGET=linux-x86_64 compile

s3-deploy:
aws s3 sync --acl=public-read ./dist "s3://acli/builds/$(VERSION)"

downloads-md:
ruby etc/generate_downloads.rb

collect-bins:
ruby etc/collect_bins.rb

release: build-all collect-bins s3-deploy downloads-md
70 changes: 45 additions & 25 deletions build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ def gem_config(conf)
conf.gem(File.expand_path(File.dirname(__FILE__)))
end

build_targets = ENV.fetch("BUILD_TARGET", "").split(",")

if build_targets == %w(all)
build_targets = %w(
linux-x86_64
linux-i686
darwin-x86_64
darwin-i386
mingw-x86_64
mingw-i686
)
end

MRuby::Build.new do |conf|
toolchain :clang

Expand All @@ -28,21 +41,8 @@ def gem_config(conf)
gem_config(conf)
end

build_targets = ENV.fetch("BUILD_TARGET", "").split(",")

if build_targets == %w(all)
build_targets = %w(
linux-x86_64
linux-i686
darwin-x86_64
darwin-i386
mingw-x86_64
mingw-i686
)
end

if build_targets.include?("linux-x86_64")
MRuby::Build.new("x86_64-pc-linux-gnu") do |conf|
MRuby::Build.new("linux-x86_64") do |conf|
toolchain :gcc

# C compiler settings
Expand All @@ -51,13 +51,15 @@ def gem_config(conf)
cc.include_paths << %(/root/wslay/lib)
end

linker.libraries << %w(ssl crypto)

gem_config(conf)
end
end

if build_targets.include?("linux-i686")
MRuby::CrossBuild.new("i686-pc-linux-gnu") do |conf|
toolchain :gcc
MRuby::CrossBuild.new("linux-i686") do |conf|
toolchain :clang

# C compiler settings
conf.cc do |cc|
Expand All @@ -69,24 +71,42 @@ def gem_config(conf)
cc.flags << "-m32"
end

linker.libraries << %w(ssl crypto)

gem_config(conf)
end
end

if build_targets.include?("darwin-x86_64")
MRuby::CrossBuild.new("x86_64-apple-darwin15") do |conf|
toolchain :clang
if RUBY_PLATFORM =~ /darwin/i
MRuby::Build.new("macos-x86_64") do |conf|
toolchain :clang

[conf.cc, conf.linker].each do |cc|
cc.command = "x86_64-apple-darwin15-clang"
# C compiler settings
conf.cc do |cc|
cc.include_paths << %w(/usr/local/include /usr/local/opt/openssl/include)
linker.library_paths << %w(/usr/local/lib /usr/local/opt/openssl/lib)

linker.libraries << %w(ssl crypto)
end

gem_config(conf)
end
conf.cxx.command = "x86_64-apple-darwin15-clang++"
conf.archiver.command = "x86_64-apple-darwin15-ar"
else
MRuby::CrossBuild.new("x86_64-apple-darwin15") do |conf|
toolchain :clang

conf.build_target = "x86_64-pc-linux-gnu"
conf.host_target = "x86_64-apple-darwin15"
[conf.cc, conf.linker].each do |cc|
cc.command = "x86_64-apple-darwin15-clang"
end
conf.cxx.command = "x86_64-apple-darwin15-clang++"
conf.archiver.command = "x86_64-apple-darwin15-ar"

gem_config(conf)
conf.build_target = "x86_64-pc-linux-gnu"
conf.host_target = "x86_64-apple-darwin15"

gem_config(conf)
end
end
end

Expand Down
18 changes: 18 additions & 0 deletions etc/collect_bins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'fileutils'

Dir.chdir(File.join(__dir__, "../"))

EXCLUDE_DIRS = %w(mruby/build/host mruby/build/mrbgems).freeze

FileUtils.mkdir_p("dist")

Dir["mruby/build/*"].each do |path|
next if EXCLUDE_DIRS.include?(path)

dir = File.basename(path)
bin_path = File.join(path, "bin", "acli")

next unless File.exist?(bin_path)

FileUtils.cp(bin_path, File.join("dist", "acli-#{dir}"))
end
47 changes: 47 additions & 0 deletions etc/generate_downloads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Dir.chdir(File.join(__dir__, "../"))

VERSION_RXP = /^\#\# Version ([\.\-\w]+)$/
PATH_RXP = /acli\-(\w+)\-.+/

PLATFORM_NAMES = {
'macos' => 'MacOS',
'linux' => 'Linux',
'freebsd' => 'FreeBSD',
'win' => 'Windows'
}.freeze

contents = []

version = `git describe --always --tags`.chomp

contents << "\#\# Version #{version}\n"

bin_groups = Dir["dist/*"].group_by do |path|
path.match(PATH_RXP)[1]
end

bin_groups.each do |k, files|
contents << "\#\#\# #{PLATFORM_NAMES[k]}\n"

files.each do |path|
basepath = File.basename(path)
contents << "- [#{basepath}](https://s3.amazonaws.com/acli/builds/#{version}/#{basepath})"
end

contents << ""
end

old_contents = (File.exist?("DOWNLOADS.md") ? File.read("DOWNLOADS.md") : '').split("\n")

if !old_contents.empty? && (vmatch = old_contents[0].match(VERSION_RXP))
# Overwrite downloads for the same version
if vmatch[1] == version
old_contents = old_contents.drop(1)
old_contents = old_contents.drop_while { |str| str !~ VERSION_RXP }
old_contents = old_contents.drop(1)
end
end

contents += old_contents

File.write("DOWNLOADS.md", contents.join("\n"))
2 changes: 1 addition & 1 deletion mrblib/acli/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Acli
VERSION = "0.0.1"
VERSION = "0.1.0"
end

0 comments on commit 47a36ae

Please sign in to comment.