--- # tasks file for qb/ruby/gem/release # NOTE We do this because the `release` Rake task `bundler/gem_tasks` # provides **will** fail if there are any uncommitted files... # which is annoying as all hell when the dirt is just a dev submod that # is not used in the release version, but there does not seem to be # any options to ignore files or paths: # # https://github.com/bundler/bundler/blob/c4fc79a2bfed38335a3371300bea49286a371d83/lib/bundler/gem_helper.rb#L151 # # So, we do the check first so we don't both with anything else if it's # going to fail (and it's the most common thing that gets in the way, # so it's nice to catch it early). # - name: >- Check that the git repo at {{ gem_root }} is clean. include_role: name: qb/git/check/clean vars: git_root: >- {{ gem_root }} - name: >- Do a `bundle install`. bundler: state: present chdir: >- {{ gem_root }} - name: >- See if a pre-release script exists at `//dev/hooks/pre-release`. stat: path: >- {{ gem_root | path_join( 'dev', 'hooks', 'pre-release' ) }} register: gem_pre_release_script_stat # NOTE Contrary to how it might seems in the [docs][1], # the `stat` object seems to *only* have the `exists` property if the # path does not exist (set to `false`), necessitating we # # [1]: http://docs.ansible.com/ansible/latest/stat_module.html # - when: >- gem_pre_release_script_stat.stat.exists and gem_pre_release_script_stat.stat.executable name: >- Execute `//dev/hooks/pre-release` script. stream: cmd: ./dev/hooks/pre-release chdir: >- {{ gem_root }} - name: >- Get gem and version info vars.rb: namespace: gem bind: gem_root: "{{ gem_root }}" version_file: "{{ gem_version_file }}" cwd: "{{ qb_cwd }}" src: | spec_pattern = "#{ gem_root }/*.gemspec" spec_path = Dir.glob(spec_pattern)[0] if spec_path.nil? raise "No gemspec found for pattern #{ spec_pattern }" end # The gem *may already be loaded*, which would break the standard gemspec # approach because the `require` will be a no-op, resulting in the # already loaded version number being used instead of the one in the # file. # # This is only a problem for NRSER, which is loaded in vars.rb.rb, but # this fix should work for any module without worrying about what is # currently loaded... grab the info we need in a clean child process. # code = <<-END require 'json' spec = Gem::Specification.load(#{ JSON.dump spec_path }) puts JSON.dump({ 'version' => spec.version.version, 'name' => spec.name, }) END obj = JSON.load `ruby -e #{ code.shellescape }` version = Gem::Version.new obj['version'] name = obj['name'] segments = version.segments.dup segments.pop while segments.any? {|s| s.is_a? String} segments[-1] = segments[-1].succ segments << 'dev' next_version = segments.join('.') version_path = if version_file.nil? # quick hack to deal with `a-b => a/b` gem names name_path = name.gsub '-', '/' File.join gem_root, 'lib', name_path, 'version.rb' else File.expand_path version_file, cwd end unless File.file?( version_path ) raise "Version file not found at #{ version_path }" end { 'name' => name, 'current_version' => version.version, 'release_version' => version.release, 'next_version' => next_version, 'version_path' => version_path, 'spec_path' => spec_path, } - debug: msg: - current: >- {{ gem_current_version }} - release: >- {{ gem_release_version }} - next: >- {{ gem_next_version }} # - spec_path: >- # {{ gem_spec_path }} # - version_path: >- # {{ gem_version_path } - when: gem_current_version != gem_release_version name: >- Change version in `{{ gem_version_path }}` from current `{{ gem_current_version }}` to `{{ gem_release_version }}`. block: - name: >- Change version to release version `{{ gem_release_version }}`. replace: dest: >- {{ gem_version_path }} regexp: >- VERSION\s*=\s*["']{{ gem_current_version }}["'] replace: >- VERSION = "{{ gem_release_version }}" - when: gem_current_version != gem_release_version name: >- Add version file `{{ gem_version_path }}` to Git. command: >- git add {{ gem_version_path }} args: chdir: >- {{ gem_root }} - name: >- Commit version file `{{ gem_version_path }}` in Git. command: git commit -m "bump to v{{ gem_release_version }}" args: chdir: >- {{ gem_root }} when: gem_current_version != gem_release_version # /block - name: >- Do the actual release via Rake and Bundler's gem helper tasks include_tasks: >- {{ role_path }}/tasks/release.yml - name: >- Change version to next version `{{ gem_next_version }}`. replace: dest: >- {{ gem_version_path }} regexp: >- VERSION\s*=\s*["']{{ gem_release_version }}["'] replace: >- VERSION = "{{ gem_next_version }}" - name: >- Add next dev version to git. command: >- git add {{ gem_version_path }} args: chdir: >- {{ gem_root }} - name: >- Commit next dev version. command: >- git commit -m "start {{ gem_next_version }}" args: chdir: >- {{ gem_root }} - name: >- Push next dev version. command: git push args: chdir: >- {{ gem_root }} - debug: msg: > v{{ gem_release_version }} released.