From 47a36ae39ff49261ada6ed71b46b8a4cdc173873 Mon Sep 17 00:00:00 2001 From: palkan Date: Fri, 21 Apr 2017 19:19:16 +0300 Subject: [PATCH] Add release scripts --- .gitignore | 1 + Makefile | 24 ++++++++++++++ build_config.rb | 70 +++++++++++++++++++++++++-------------- etc/collect_bins.rb | 18 ++++++++++ etc/generate_downloads.rb | 47 ++++++++++++++++++++++++++ mrblib/acli/version.rb | 2 +- 6 files changed, 136 insertions(+), 26 deletions(-) create mode 100644 Makefile create mode 100644 etc/collect_bins.rb create mode 100644 etc/generate_downloads.rb diff --git a/.gitignore b/.gitignore index 924cf50..7b55713 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ mruby/ +dist/ *.tar.xz .mrb diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4113e44 --- /dev/null +++ b/Makefile @@ -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 diff --git a/build_config.rb b/build_config.rb index 3dc2e14..118382e 100644 --- a/build_config.rb +++ b/build_config.rb @@ -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 @@ -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 @@ -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| @@ -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 diff --git a/etc/collect_bins.rb b/etc/collect_bins.rb new file mode 100644 index 0000000..be2717b --- /dev/null +++ b/etc/collect_bins.rb @@ -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 diff --git a/etc/generate_downloads.rb b/etc/generate_downloads.rb new file mode 100644 index 0000000..4cbee08 --- /dev/null +++ b/etc/generate_downloads.rb @@ -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")) diff --git a/mrblib/acli/version.rb b/mrblib/acli/version.rb index f7ca25e..efb91d7 100644 --- a/mrblib/acli/version.rb +++ b/mrblib/acli/version.rb @@ -1,3 +1,3 @@ module Acli - VERSION = "0.0.1" + VERSION = "0.1.0" end