Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemfile.lock should not be committed to the repository for gems. More information available here.

# .ruby-version
# .ruby-gemset

Expand Down
41 changes: 30 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this is because they don't support custom SSH keys outside of private repos for travis. this is the recommended way to do it for public repos. i used this guide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the encrypted_... coming from travis env vars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - that's the output from travis encrypt

script:
- ./ci-helpers/gem_helper tag_new_release_if_applicable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a no-op if the versions are the same


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
60 changes: 0 additions & 60 deletions Gemfile.lock

This file was deleted.

12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# atomic_cache Gem
[![Gem Version](https://badge.fury.io/rb/atomic_cache.svg)](https://badge.fury.io/rb/atomic_cache)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I manually published 0.1.0.rc1 to rubygems to kick this off.

[![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)

Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -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
15 changes: 10 additions & 5 deletions atomic_cache.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for more of a "select" vs. "reject" here.


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'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to trust the ~> syntax for a public project? ~> 4.0 means >= 4.0 && < 5.0. What if one of our dependencies doesn't respect semver and pushes a breaking change on a minor version?

I think I'd advocate for using => for everything just to be safe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev dependencies are way less breaking, ~> is perfectly fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @trose , good point, but I tend to agree with @onyxraven 's comment for development dependencies.

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'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binding slightly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't look like we currently have matrix testing against different rails versions here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I'll file a story for that. It feels slightly out of scope for the publishing piece. Definitely before we remove the rc indicator we'll want this. Thanks for calling this out.

spec.add_dependency 'murmurhash3', '~> 0.1'
end
Binary file added ci-helpers/atomic_cache_deploy.enc
Binary file not shown.
120 changes: 120 additions & 0 deletions ci-helpers/gem_helper
Original file line number Diff line number Diff line change
@@ -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)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we include the latest changelog blob?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm thinking I'd need to parse out the markdown which feels like a good future addition. I'd like to get this MVP release structure in place. I'll file an enhancement for this though because it would be nice 😄

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
2 changes: 1 addition & 1 deletion lib/atomic_cache/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module AtomicCache
VERSION = "1.0.0"
VERSION = "0.1.0.rc1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured a pre-1.0 would be ideal while we kick the tires in our projects for a bit.

end