File: release

package info (click to toggle)
golang-gitaly-proto 1.37.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 372 kB
  • sloc: ruby: 216; makefile: 93
file content (88 lines) | stat: -rwxr-xr-x 2,554 bytes parent folder | download | duplicates (4)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env ruby
require 'erb'

require_relative 'run.rb'

GEM_NAME = 'gitaly-proto'
RUBY_PREFIX = 'ruby/lib'
RUBY_VERSION_FILE = 'gitaly/version.rb'

REMOTE_REGEX = %r{gitlab.com.gitlab-org/gitaly-proto.git}

# Sanity check
%w[
  git@gitlab.com:gitlab-org/gitaly-proto.git
  https://gitlab.com/gitlab-org/gitaly-proto.git
  https://janedoe@gitlab.com/gitlab-org/gitaly-proto.git
].each do |remote|
  abort "regex check failed failed for #{remote.inspect}" unless REMOTE_REGEX.match(remote)
end

def main(version)
  remote = capture!(%w[git remote get-url --push origin])
  unless REMOTE_REGEX.match(remote)
    abort "Git remote 'origin' must match #{REMOTE_REGEX}, got #{remote.inspect}"
  end

  unless version =~ /^[0-9]/
    abort "Version string #{version.inspect} does not look like a semver (e.g. \"1.0.2\"). Aborting."
  end

  run!(%w[make generate])
  puts 'Testing for changed files'
  run!(%w[git diff --quiet --exit-code])
  puts 'Testing for staged changes'
  run!(%w[git diff --quiet --cached --exit-code])
  write_version_files(version)
  version_msg = "Version #{version}"
  run!(%W[git commit -m #{version_msg}])
  tag_name = "v#{version}"
  run!(%W[git tag -a -m #{version_msg} #{tag_name}])
  run!(%W[git show --pretty #{tag_name}])
  run!(%W[gem build #{GEM_NAME}.gemspec])
  puts "Proceed to publish version #{version}? Enter 'Yes' to continue; Ctrl-C to abort"
  $stdout.flush
  abort unless $stdin.gets.chomp == 'Yes'

  run!(%W[git push origin HEAD #{tag_name}])
  run!(%W[gem push #{GEM_NAME}-#{version}.gem])
end

def write_version_files(version)
  version_file = 'VERSION'
  open(version_file, 'w') { |f| f.puts version }
  run!(%W[git add #{version_file}])

  go_version_file = 'go/VERSION'
  open(go_version_file, 'w') { |f| f.puts version }
  run!(%W[git add #{go_version_file}])

  version_rb_template = ERB.new <<EOT
# This file was auto-generated by #{$0}
module Gitaly
  VERSION = "#{version}"
end
EOT
  version_rb = File.join(RUBY_PREFIX, RUBY_VERSION_FILE)
  open(version_rb, 'w') { |f| f.write(version_rb_template.result) }
  run!(%W[git add #{version_rb}])
end

def error(msg)
  warn "#{$0}: #{msg}"
end

unless ARGV.count == 1
  warn "Usage: #{$0} VERSION"
  warn "Specify version as x.y.z"
  abort
end

directory_current_file = File.expand_path('..', __FILE__)
git_root_current_file = capture!(%w[git rev-parse --show-toplevel], directory_current_file).chomp
unless git_root_current_file == Dir.pwd
  error "#{$0}: this script must be run from the root of the Gitaly repository"
  abort
end

main(ARGV.first)