diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-10-28 08:43:30 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-10-28 09:03:26 +0300 |
commit | 49d098476b160a2c938eed0d0cd1616c8dd5d9a6 (patch) | |
tree | d6d928e7e1a6ee75d535ded64e60e7eaa2a7c1d2 /tools | |
parent | a55f6c710a4a48af6dac25b8236497388447584b (diff) |
tools/protogem: Generate version file ad-hoc
On every version bump the GitLab Release Tools bot updates the version
in two different files: first in our top-level `VERSION` file, and
second in the Ruby Protobuf files at `ruby/proto/version.rb`. Both files
basically contain the same information, but serve different purposes.
We're about to drop our generated Ruby Protobuf code though in favor of
creating the Protobuf Gem ad-hoc. This also means it doesn't make a
whole lot of sense anymore to carry around the version file in our tree.
Consequentially, we've adjusted the Release Tools bot to stop writing
the `version.rb` file completely. Instead, we now generate the file via
the information we already have in our `VERSION` file.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/protogem/generate-proto-ruby | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/protogem/generate-proto-ruby b/tools/protogem/generate-proto-ruby index cfbbbed75..d4b807d37 100755 --- a/tools/protogem/generate-proto-ruby +++ b/tools/protogem/generate-proto-ruby @@ -11,7 +11,10 @@ RUBY_VERSION_FILE = File.join('gitaly', 'version.rb') def main proto_output_dir = File.absolute_path(File.join(SOURCE_DIR, 'ruby', 'proto', 'gitaly')) + version = File.read(File.join(SOURCE_DIR, 'VERSION')).strip + FileUtils.rm(Dir[File.join(proto_output_dir, '**/*_pb.rb')]) + FileUtils.rm(Dir[File.join(proto_output_dir, 'version.rb')]) FileUtils.mkdir_p(proto_output_dir) proto_dir = File.join(SOURCE_DIR, 'proto') @@ -22,9 +25,22 @@ def main File.join(SOURCE_DIR, 'tools', 'protogem') ) + write_version_file(SOURCE_DIR, version) write_ruby_requires(SOURCE_DIR) end +def write_version_file(output_dir, version) + path = File.join(output_dir, 'ruby', 'proto', RUBY_VERSION_FILE) + content = <<~EOF + # This file is generated by #{File.basename($0)}. Do not edit. + module Gitaly + VERSION = '#{version}' + end + EOF + + open(path, 'w') { |f| f.write(content) } +end + def write_ruby_requires(output_dir) requires = Dir.glob(File.join('gitaly', '*_services_pb.rb'), base: File.join(output_dir, 'ruby', 'proto')).sort abort "No auto-generated Ruby service files found" if requires.empty? |