]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/dev/release/test-helper.rb
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / dev / release / test-helper.rb
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18 require "English"
19 require "cgi/util"
20 require "fileutils"
21 require "find"
22 require "json"
23 require "open-uri"
24 require "rexml/document"
25 require "tempfile"
26 require "tmpdir"
27
28 module CommandRunnable
29 class Error < StandardError
30 end
31
32 def sh(*command_line, check_result: true)
33 if command_line[0].is_a?(Hash)
34 env = command_line.shift
35 else
36 env = {}
37 end
38 stdout = Tempfile.new("command-stdout.log")
39 stderr = Tempfile.new("command-stderr.log")
40 success = system(env, *command_line, out: stdout.path, err: stderr.path)
41 if check_result
42 unless success
43 message = "Failed to run: #{command_line.join(" ")}\n"
44 message << "stdout:\n #{stdout.read}\n"
45 message << "stderr:\n #{stderr.read}"
46 raise Error, message
47 end
48 end
49 stdout.read
50 end
51 end
52
53 module GitRunnable
54 include CommandRunnable
55
56 def git(*args)
57 if args[0].is_a?(Hash)
58 env = args.shift
59 else
60 env = {}
61 end
62 sh(env, "git", *args)
63 end
64
65 def git_current_commit
66 git("rev-parse", "HEAD").chomp
67 end
68
69 def git_tags
70 git("tags").lines(chomp: true)
71 end
72 end
73
74 module VersionDetectable
75 def detect_versions
76 top_dir = Pathname(__dir__).parent.parent
77 cpp_cmake_lists = top_dir + "cpp" + "CMakeLists.txt"
78 @snapshot_version = cpp_cmake_lists.read[/ARROW_VERSION "(.+?)"/, 1]
79 @release_version = @snapshot_version.gsub(/-SNAPSHOT\z/, "")
80 @so_version = compute_so_version(@release_version)
81 @next_version = @release_version.gsub(/\A\d+/) {|major| major.succ}
82 @next_snapshot_version = "#{@next_version}-SNAPSHOT"
83 @next_so_version = compute_so_version(@next_version)
84 r_description = top_dir + "r" + "DESCRIPTION"
85 @previous_version = r_description.read[/^Version: (.+?)\.9000$/, 1]
86 end
87
88 def compute_so_version(version)
89 major, minor, _patch = version.split(".")
90 Integer(major, 10) * 100 + Integer(minor, 10)
91 end
92
93 def on_release_branch?
94 @snapshot_version == @release_version
95 end
96 end