diff --git a/.gitignore b/.gitignore index e289ab2..f05be97 100644 --- a/.gitignore +++ b/.gitignore @@ -43,7 +43,7 @@ build-iPhoneSimulator/ # for a library or gem, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: -# Gemfile.lock +Gemfile.lock # .ruby-version # .ruby-gemset diff --git a/.travis.yml b/.travis.yml index 88781ef..a196d99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,35 @@ language: ruby -rvm: - - 2.4.3 - - 2.5.0 +jobs: + include: + - stage: test-2.4 + rvm: 2.4.3 + script: + - bundle exec rake spec -before_script: - - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - - chmod +x ./cc-test-reporter - - ./cc-test-reporter before-build + - stage: test-2.5 + rvm: 2.5.0 + before_script: + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter + - ./cc-test-reporter before-build + script: + - bundle exec rake spec + after_script: + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT -script: - - bundle exec rake spec + - stage: tag-new-release-if-applicable + if: branch = master + before_script: + - openssl aes-256-cbc -K $encrypted_bfd358de8814_key -iv $encrypted_bfd358de8814_iv -in ./ci-helpers/atomic_cache_deploy.enc -out atomic_cache_deploy -d + - echo -e "Host example.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config + - chmod 600 atomic_cache_deploy + - mv atomic_cache_deploy ~/.ssh/id_rsa + - git remote add deploy ssh://git@github.com/Ibotta/atomic_cache.git + script: + - ./ci-helpers/gem_helper tag_new_release_if_applicable -after_script: - - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT + - stage: publish-gem + if: tag =~ ^v # tags starting with "v" represent releases (as in v0.1.0) + script: + - ./ci-helpers/gem_helper publish diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 768b0d7..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,60 +0,0 @@ -PATH - remote: . - specs: - atomic_cache (1.0.0) - activesupport (>= 4.2) - murmurhash3 (~> 0.1) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (5.1.4) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - concurrent-ruby (1.0.5) - diff-lcs (1.3) - docile (1.1.5) - i18n (0.9.3) - concurrent-ruby (~> 1.0) - json (2.1.0) - minitest (5.11.3) - murmurhash3 (0.1.6) - rake (10.5.0) - rspec (3.7.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-core (3.7.0) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.0) - simplecov (0.15.1) - docile (~> 1.1.0) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - thread_safe (0.3.6) - timecop (0.8.1) - tzinfo (1.2.4) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - atomic_cache! - bundler (~> 1.14) - rake (~> 10.0) - rspec (~> 3.0) - simplecov (~> 0.15) - timecop (~> 0.8.1) - -BUNDLED WITH - 1.16.1 diff --git a/README.md b/README.md index 7abf435..757d12c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # atomic_cache Gem +[![Gem Version](https://badge.fury.io/rb/atomic_cache.svg)](https://badge.fury.io/rb/atomic_cache) [![Build Status](https://travis-ci.org/Ibotta/atomic_cache.svg?branch=master)](https://travis-ci.org/Ibotta/atomic_cache) [![Test Coverage](https://api.codeclimate.com/v1/badges/790faad5866d2a00ca6c/test_coverage)](https://codeclimate.com/github/Ibotta/atomic_cache/test_coverage) @@ -42,8 +43,15 @@ For further details and examples see [Usage & Testing](docs/USAGE.md) After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). - ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/ibotta/atomic_cache + +## Releasing + +Releases are automatically handled via the Travis CI build. When a version greater than +the version published on rubygems.org is pushed to the `master` branch, Travis will: + +- re-generate the CHANGELOG file +- tag the release with GitHub +- release to rubygems.org diff --git a/Rakefile b/Rakefile index b7e9ed5..9a7427e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,13 @@ -require "bundler/gem_tasks" +require './lib/atomic_cache/version' +require "github_changelog_generator/task" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) +GitHubChangelogGenerator::RakeTask.new :changelog do |config| + config.user = 'Ibotta' + config.project = 'atomic_cache' + config.future_release = AtomicCache::VERSION +end + task :default => :spec diff --git a/atomic_cache.gemspec b/atomic_cache.gemspec index 5e06294..df649aa 100644 --- a/atomic_cache.gemspec +++ b/atomic_cache.gemspec @@ -13,23 +13,28 @@ Gem::Specification.new do |spec| spec.summary = 'summary' spec.description = 'desc' - spec.licenses = ['apache 2.0'] + spec.licenses = ['Apache-2.0'] spec.homepage = 'https://github.com/ibotta/atomic_cache' - spec.files = `git ls-files -z`.split("\x0").reject do |f| - f.match(%r{^(test|spec|features)/}) - end + spec.files = %w( README.md LICENSE ) + spec.files += Dir.glob("lib/**/*") + spec.files += Dir.glob("docs/**/*") + spec.files += Dir.glob("spec/**/*") spec.require_paths = ['lib'] # Dev dependencies spec.add_development_dependency 'bundler', '~> 1.14' + spec.add_development_dependency 'gems', '~> 1.0' + spec.add_development_dependency 'git', '~> 1.3' + spec.add_development_dependency 'github_changelog_generator', '>= 1.15.0.pre.rc' + spec.add_development_dependency 'octokit', '~> 4.0' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'simplecov', '~> 0.15' spec.add_development_dependency 'timecop', '~> 0.8.1' # Dependencies - spec.add_dependency 'activesupport', '>= 4.2' + spec.add_dependency 'activesupport', '>= 4.2', '< 6' spec.add_dependency 'murmurhash3', '~> 0.1' end diff --git a/ci-helpers/atomic_cache_deploy.enc b/ci-helpers/atomic_cache_deploy.enc new file mode 100644 index 0000000..951a340 Binary files /dev/null and b/ci-helpers/atomic_cache_deploy.enc differ diff --git a/ci-helpers/gem_helper b/ci-helpers/gem_helper new file mode 100755 index 0000000..9a24e90 --- /dev/null +++ b/ci-helpers/gem_helper @@ -0,0 +1,120 @@ +#!/usr/bin/env ruby + +require './lib/atomic_cache/version' +require 'bundler/gem_helper' +require 'gems' +require 'git' +require 'octokit' +require 'rake' +require 'rubygems' + +GEM_NAME = 'atomic_cache'.freeze + +module AtomicCacheCi + class GemHelper + def initialize + Gems.configure do |config| + config.key = ENV['RUBYGEMS_API_TOKEN'] + end + end + + def tag_new_release_if_applicable + puts('Determining if a new release tag is required...') + + create_new_release if repo_has_newer_version_than_rubygems? + end + + def publish_to_rubygems + gemfile = gemhelper.build_gem + Gems.push(File.new(gemfile)) + end + + private + + def gemhelper + @gemhelper ||= Bundler::GemHelper.new(nil, GEM_NAME) + end + + def git_client + @git_client ||= Git.open('.') + end + + def local_version + AtomicCache::VERSION + end + + def repo_has_newer_version_than_rubygems? + git_version_str = version(:local) do + local_version + end + + remote_version_str = version(:rubygems) do + Gems.info(GEM_NAME)['version'] + end + + if Gem::Version.new(git_version_str) > Gem::Version.new(remote_version_str) + puts 'The version in the repository is newer than what is on rubygems.org.' + true + else + puts 'The version in the repository is not newer than what is on rubygems.org' + false + end + end + + def version(source) + puts "Fetching #{GEM_NAME} version from #{source}" + + version = yield + raise("Error fetching #{source} version! ABORT.") if version.nil? + + puts "#{GEM_NAME} version on #{source} is #{version}" + version + end + + def create_new_release + update_changelog + github_release + end + + def update_changelog + # generate the changelog + rake = Rake.application + rake.init + rake.load_rakefile + rake['changelog'].invoke + + # commit it to master + git = git_client + git.reset + git.add('CHANGELOG.md') + + # https://docs.travis-ci.com/user/customizing-the-build/#Skipping-a-build + git.commit("[skip ci] release #{local_version}") + git.push('deploy') + end + + def github_release + github = Octokit::Client.new(access_token: ENV['GITHUB_API_TOKEN']) + tag = "v#{local_version}" + github.create_release("Ibotta/#{GEM_NAME}", local_version, + tag_name: tag, + target_commitish: 'master', + name: "atomic_cache release #{local_version}", + body: "See [changelog](https://github.com/Ibotta/atomic_cache/blob/#{tag}/CHANGELOG.md)", + prerelease: local_version.include?('.rc') + ) + end + end +end + +if !ENV['CI'] + raise('This script should only be used by Travis in a CI enviornment.') +end + +cmd = ARGV.first +case cmd +when 'tag_new_release_if_applicable' + AtomicCacheCi::GemHelper.new.tag_new_release_if_applicable +when 'publish' + AtomicCacheCi::GemHelper.new.publish_to_rubygems +end diff --git a/lib/atomic_cache/version.rb b/lib/atomic_cache/version.rb index fd80856..a2c933f 100644 --- a/lib/atomic_cache/version.rb +++ b/lib/atomic_cache/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module AtomicCache - VERSION = "1.0.0" + VERSION = "0.1.0.rc1" end