diff --git a/.gitignore b/.gitignore index d87d4be..164d39f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ spec/reports test/tmp test/version_tmp tmp +packaging/traveling-ruby* +parity-* diff --git a/README.md b/README.md index 5694b00..385e453 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,31 @@ and the other programs can be installed with Homebrew: Install ------- +OSX: + + brew tap thoughtbot/formulae + brew install parity + +On other systems you can: + +1. Download the package for your system from the [releases +page][releases] +2. Extract the tarball and place it so that `/bin` is in your `PATH` + +Alternatively, you can do the following on all systems (requires a ruby +installation): + gem install parity -This installs three shell commands: +All these methods install the following three shell commands: development staging production + +[releases]: https://github.com/croaky/parity/releases + Usage ----- @@ -130,6 +147,11 @@ Contributing Please see CONTRIBUTING.md for details. +Releasing +--------- + +See guidelines in RELEASING.md for details + Credits ------- diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..c38753e --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,38 @@ +# Releasing + +Parity uses a set of `rake` tasks to create packages and bundles [traveling +ruby][traveling_ruby] to simplify the dependency on Ruby. + +Generating packages: +------------------- + +Packages can be generated for the following systems: + +* OSX `rake package:osx` +* Linux x86 `rake package:linux:x86` +* Linux x86_64 `rake package:linux:x86_64` + +You can generate all packages with `rake package:all` + +[traveling_ruby]: https://github.com/phusion/traveling-ruby + +The packages generated are tarballs of the following directory structure: + + parity-package + ├── bin # shims + └── lib + ├── app # parity's bin and lib directories + └── ruby # traveling ruby for target system + +Releasing a new version +---------------------- + +1. Update the version in `parity/version.rb` +2. Create a new tag based on the version number +3. Generate packages +4. Create a [release] for the latest tag and attach the packages +5. Update the [homebrew formula] to point to the latest OSX package + +[homebrew formula]: +https://github.com/thoughtbot/homebrew-formulae/blob/master/Formula/parity.rb +[release]: https://github.com/croaky/parity/releases diff --git a/Rakefile b/Rakefile index c09fb9b..1913756 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,111 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' +require File.expand_path("../lib/parity/version", __FILE__) RSpec::Core::RakeTask.new('spec') task default: :spec + +PROJECT_NAME = "parity" +TRAVELING_RUBY_VERSION = "20141215-2.1.5" +TRAVELING_RUBY_HOST = "http://d6r77u77i8pq3.cloudfront.net/releases" +RUBY_BASENAME = "traveling-ruby-#{TRAVELING_RUBY_VERSION}" + +namespace :package do + desc "Generate parity #{Parity::VERSION} packages for OSX, Linux x86 and Linux x86_64" + task all: ["linux:x86", "linux:x86_64", "osx"] + + namespace :linux do + desc "Generate parity #{Parity::VERSION} package for Linux x86" + task x86: "packaging/#{RUBY_BASENAME}-linux-x86.tar.gz" do + clean_up("linux-x86") + create_package("linux-x86") + end + + desc "Generate parity #{Parity::VERSION} package for Linux x86_64" + task x86_64: "packaging/#{RUBY_BASENAME}-linux-x86_64.tar.gz" do + clean_up("linux-x86_64") + create_package("linux-x86_64") + end + end + + desc "Generate parity #{Parity::VERSION} package for OSX" + task osx: "packaging/#{RUBY_BASENAME}-osx.tar.gz" do + clean_up("osx") + create_package("osx") + end + + desc "Remove the files generated by packaging" + task :cleanup do + clean_up("osx") + clean_up("linux-x86") + clean_up("linux-x86_64") + end +end + +file "packaging/#{RUBY_BASENAME}-osx.tar.gz" do + sh "cd packaging && curl -L -O --fail #{TRAVELING_RUBY_HOST}/#{ruby_for("osx")}" +end + +file "packaging/#{RUBY_BASENAME}-linux-x86.tar.gz" do + sh "cd packaging && curl -L -O --fail #{TRAVELING_RUBY_HOST}/#{ruby_for("linux-x86")}" +end + +file "packaging/#{RUBY_BASENAME}-linux-x86_64.tar.gz" do + sh "cd packaging && curl -L -O --fail #{TRAVELING_RUBY_HOST}/#{ruby_for("linux-x86_64")}" +end + +def create_package(target) + package_dir = "#{PROJECT_NAME}-#{Parity::VERSION}-#{target}" + + copy_lib(package_dir) + copy_binaries(package_dir) + copy_shims(package_dir) + extract_ruby(package_dir, target) + archive_package(package_dir) +end + +def clean_up(target) + package_name = "#{PROJECT_NAME}-#{Parity::VERSION}-#{target}" + rm_rf package_name + rm_f "#{package_name}.tar.gz" +end + +def ruby_for(target) + "#{RUBY_BASENAME}-#{target}.tar.gz" +end + +def copy_lib(package_dir) + app_dir = "#{package_dir}/lib/app" + mkdir_p app_dir + + cp_r "lib", app_dir + cp "README.md", app_dir +end + +def copy_binaries(package_dir) + bin_path = "#{package_dir}/lib/app/bin" + mkdir_p bin_path + + cp "bin/development", bin_path + cp "bin/staging", bin_path + cp "bin/production", bin_path +end + +def copy_shims(package_dir) + shim_dir = "#{package_dir}/bin" + mkdir shim_dir + cp "packaging/development_shim.sh", "#{shim_dir}/development" + cp "packaging/staging_shim.sh", "#{shim_dir}/staging" + cp "packaging/production_shim.sh", "#{shim_dir}/production" +end + +def extract_ruby(package_dir, target) + ruby_dir = "#{package_dir}/lib/ruby" + mkdir_p ruby_dir + sh "tar -xzf packaging/#{ruby_for(target)} -C #{ruby_dir}" +end + +def archive_package(package_dir) + sh "tar -czf #{package_dir}.tar.gz #{package_dir}" +end diff --git a/lib/parity.rb b/lib/parity.rb index 6bdfc19..f42f4b9 100644 --- a/lib/parity.rb +++ b/lib/parity.rb @@ -1,3 +1,6 @@ +$LOAD_PATH << File.expand_path("..", __FILE__) + +require "parity/version" require "parity/configuration" require "parity/environment" require "parity/usage" diff --git a/lib/parity/version.rb b/lib/parity/version.rb new file mode 100644 index 0000000..da51204 --- /dev/null +++ b/lib/parity/version.rb @@ -0,0 +1,3 @@ +module Parity + VERSION = "0.4.1" +end diff --git a/packaging/development_shim.sh b/packaging/development_shim.sh new file mode 100755 index 0000000..da7d22c --- /dev/null +++ b/packaging/development_shim.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +REALPATH=$(readlink $0 || $0) +RELATIVE_DIR=$(dirname $REALPATH) +SELF_DIR=$(cd $(dirname $0) && cd $RELATIVE_DIR && pwd) + +exec "$SELF_DIR/../lib/ruby/bin/ruby" "$SELF_DIR/../lib/app/bin/development" diff --git a/packaging/production_shim.sh b/packaging/production_shim.sh new file mode 100755 index 0000000..38c522d --- /dev/null +++ b/packaging/production_shim.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +REALPATH=$(readlink $0 || $0) +RELATIVE_DIR=$(dirname $REALPATH) +SELF_DIR=$(cd $(dirname $0) && cd $RELATIVE_DIR && pwd) + +exec "$SELF_DIR/../lib/ruby/bin/ruby" "$SELF_DIR/../lib/app/bin/production" diff --git a/packaging/staging_shim.sh b/packaging/staging_shim.sh new file mode 100755 index 0000000..bf959d6 --- /dev/null +++ b/packaging/staging_shim.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +REALPATH=$(readlink $0 || $0) +RELATIVE_DIR=$(dirname $REALPATH) +SELF_DIR=$(cd $(dirname $0) && cd $RELATIVE_DIR && pwd) + +exec "$SELF_DIR/../lib/ruby/bin/ruby" "$SELF_DIR/../lib/app/bin/staging" diff --git a/parity.gemspec b/parity.gemspec index fd30bf0..e9b1c40 100644 --- a/parity.gemspec +++ b/parity.gemspec @@ -1,3 +1,5 @@ +require File.expand_path("../lib/parity/version", __FILE__) + Gem::Specification.new do |spec| spec.authors = ["Dan Croak"] @@ -14,5 +16,5 @@ Gem::Specification.new do |spec| spec.name = "parity" spec.require_paths = ["lib"] spec.summary = "Shell commands for development, staging, and production parity." - spec.version = "0.4.1" + spec.version = Parity::VERSION end