-
Notifications
You must be signed in to change notification settings - Fork 6
Publish releases via CI #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f011c6f
24d047c
a3b34f3
a172f5a
635afed
eddb419
c825015
3c13f64
14e1cf5
c77008c
92551f0
c2aa3b5
74784dc
ac660e0
9ceef72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct - that's the output from |
||
| script: | ||
| - ./ci-helpers/gem_helper tag_new_release_if_applicable | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # atomic_cache Gem | ||
| [](https://badge.fury.io/rb/atomic_cache) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| [](https://travis-ci.org/Ibotta/atomic_cache) | ||
| [](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 | ||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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/**/*") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to trust the I think I'd advocate for using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dev dependencies are way less breaking, ~> is perfectly fine
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. binding slightly.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| spec.add_dependency 'murmurhash3', '~> 0.1' | ||
| end | ||
| 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)", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we include the latest changelog blob?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gemfile.lockshould not be committed to the repository for gems. More information available here.