File: prepare_tag.rake

package info (click to toggle)
yard 0.9.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,736 kB
  • sloc: ruby: 31,680; javascript: 7,658; makefile: 21
file content (47 lines) | stat: -rw-r--r-- 1,566 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'json'
require 'tempfile'

namespace :release do
  desc 'Updates repository and tags VERSION=X.Y.Z'
  task :tag do
    restore_file = Tempfile.new
    restore_file.close
    at_exit { restore_file.unlink }

    version = ENV['VERSION']
    build_path = File.expand_path(File.join(`gem which samus`.strip, '..', '..', 'commands', 'build'))
    samus_contents = File.read(File.join(__dir__, '..', 'samus.json'))
    samus_json = JSON.parse(samus_contents.gsub('$version', version))

    samus_json['actions'].each do |action|
      env = {
        '_VERSION' => version,
        '__ORIG_BRANCH' => `git rev-parse --abbrev-ref HEAD`.strip,
        '__RESTORE_FILE' => restore_file.path,
      }
      (action['arguments'] || {}).each {|k, v| env["_#{k.upcase}"] = v }
      file = File.join(build_path, action['action'])
      shebang = File.readlines(file).first[%r{\A#!(?:\S+)/(.+)}, 1].strip.split(' ')
      cmd = [*shebang, file, *action['files']]
      puts "[C] #{action['action']} #{(action['files'] || []).join(' ')}"
      output = ""
      IO.popen(env, cmd) {|io| output = io.read }
      status = $?
      unless status.success?
        puts "[F] Last command failed with: #{status.to_i}"
        puts output
        exit(status.to_i)
      end
    end

    puts ""
    puts "Tag v#{version} created. To publish, type the following:"
    puts ""
    puts "  bundle exec rake release:push VERSION=#{version}"
  end

  desc 'Pushes the main branch and tag for VERSION=X.Y.Z'
  task :push do
    sh "git push origin main v#{ENV['VERSION']}"
  end
end