packaging 0.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +17 -0
  3. data/README-Solaris.md +117 -0
  4. data/README.md +1031 -0
  5. data/lib/packaging.rb +32 -0
  6. data/lib/packaging/artifactory.rb +278 -0
  7. data/lib/packaging/config.rb +392 -0
  8. data/lib/packaging/config/params.rb +366 -0
  9. data/lib/packaging/deb.rb +28 -0
  10. data/lib/packaging/deb/repo.rb +263 -0
  11. data/lib/packaging/gem.rb +112 -0
  12. data/lib/packaging/ips.rb +57 -0
  13. data/lib/packaging/msi.rb +89 -0
  14. data/lib/packaging/nuget.rb +39 -0
  15. data/lib/packaging/osx.rb +36 -0
  16. data/lib/packaging/paths.rb +238 -0
  17. data/lib/packaging/platforms.rb +480 -0
  18. data/lib/packaging/repo.rb +55 -0
  19. data/lib/packaging/retrieve.rb +46 -0
  20. data/lib/packaging/rpm.rb +5 -0
  21. data/lib/packaging/rpm/repo.rb +257 -0
  22. data/lib/packaging/tar.rb +154 -0
  23. data/lib/packaging/util.rb +146 -0
  24. data/lib/packaging/util/date.rb +15 -0
  25. data/lib/packaging/util/execution.rb +85 -0
  26. data/lib/packaging/util/file.rb +125 -0
  27. data/lib/packaging/util/git.rb +174 -0
  28. data/lib/packaging/util/git_tags.rb +73 -0
  29. data/lib/packaging/util/gpg.rb +62 -0
  30. data/lib/packaging/util/jenkins.rb +95 -0
  31. data/lib/packaging/util/misc.rb +69 -0
  32. data/lib/packaging/util/net.rb +368 -0
  33. data/lib/packaging/util/os.rb +17 -0
  34. data/lib/packaging/util/platform.rb +40 -0
  35. data/lib/packaging/util/rake_utils.rb +111 -0
  36. data/lib/packaging/util/serialization.rb +19 -0
  37. data/lib/packaging/util/ship.rb +171 -0
  38. data/lib/packaging/util/tool.rb +41 -0
  39. data/lib/packaging/util/version.rb +326 -0
  40. data/spec/fixtures/config/ext/build_defaults.yaml +2 -0
  41. data/spec/fixtures/config/ext/project_data.yaml +2 -0
  42. data/spec/fixtures/config/params.yaml +2 -0
  43. data/spec/fixtures/configs/components/test_file.json +1 -0
  44. data/spec/fixtures/configs/components/test_file_2.json +0 -0
  45. data/spec/fixtures/configs/components/test_file_not_tagged.json +1 -0
  46. data/spec/fixtures/configs/components/test_file_wrong_ext.txt +0 -0
  47. data/spec/fixtures/configs/components/test_file_wrong_ext.wrong +0 -0
  48. data/spec/fixtures/util/pre_tasks.yaml +4 -0
  49. data/spec/lib/packaging/artifactory_spec.rb +171 -0
  50. data/spec/lib/packaging/config_spec.rb +556 -0
  51. data/spec/lib/packaging/deb/repo_spec.rb +148 -0
  52. data/spec/lib/packaging/deb_spec.rb +52 -0
  53. data/spec/lib/packaging/paths_spec.rb +153 -0
  54. data/spec/lib/packaging/platforms_spec.rb +153 -0
  55. data/spec/lib/packaging/repo_spec.rb +97 -0
  56. data/spec/lib/packaging/retrieve_spec.rb +61 -0
  57. data/spec/lib/packaging/rpm/repo_spec.rb +133 -0
  58. data/spec/lib/packaging/tar_spec.rb +122 -0
  59. data/spec/lib/packaging/util/execution_spec.rb +56 -0
  60. data/spec/lib/packaging/util/file_spec.rb +139 -0
  61. data/spec/lib/packaging/util/git_spec.rb +160 -0
  62. data/spec/lib/packaging/util/git_tag_spec.rb +36 -0
  63. data/spec/lib/packaging/util/gpg_spec.rb +64 -0
  64. data/spec/lib/packaging/util/jenkins_spec.rb +112 -0
  65. data/spec/lib/packaging/util/misc_spec.rb +31 -0
  66. data/spec/lib/packaging/util/net_spec.rb +239 -0
  67. data/spec/lib/packaging/util/os_spec.rb +31 -0
  68. data/spec/lib/packaging/util/rake_utils_spec.rb +70 -0
  69. data/spec/lib/packaging/util/ship_spec.rb +117 -0
  70. data/spec/lib/packaging/util/version_spec.rb +123 -0
  71. data/spec/lib/packaging_spec.rb +19 -0
  72. data/spec/spec_helper.rb +36 -0
  73. data/static_artifacts/PackageInfo.plist +3 -0
  74. data/tasks/00_utils.rake +216 -0
  75. data/tasks/30_metrics.rake +33 -0
  76. data/tasks/apple.rake +266 -0
  77. data/tasks/build.rake +12 -0
  78. data/tasks/clean.rake +5 -0
  79. data/tasks/config.rake +30 -0
  80. data/tasks/deb.rake +129 -0
  81. data/tasks/deb_repos.rake +28 -0
  82. data/tasks/deprecated.rake +130 -0
  83. data/tasks/doc.rake +20 -0
  84. data/tasks/education.rake +57 -0
  85. data/tasks/fetch.rake +57 -0
  86. data/tasks/gem.rake +146 -0
  87. data/tasks/jenkins.rake +494 -0
  88. data/tasks/jenkins_dynamic.rake +202 -0
  89. data/tasks/load_extras.rake +21 -0
  90. data/tasks/mock.rake +348 -0
  91. data/tasks/nightly_repos.rake +335 -0
  92. data/tasks/pe_deb.rake +12 -0
  93. data/tasks/pe_rpm.rake +13 -0
  94. data/tasks/pe_ship.rake +221 -0
  95. data/tasks/pe_sign.rake +13 -0
  96. data/tasks/pe_tar.rake +5 -0
  97. data/tasks/retrieve.rake +45 -0
  98. data/tasks/rpm.rake +66 -0
  99. data/tasks/rpm_repos.rake +29 -0
  100. data/tasks/ship.rake +752 -0
  101. data/tasks/sign.rake +226 -0
  102. data/tasks/tag.rake +8 -0
  103. data/tasks/tar.rake +34 -0
  104. data/tasks/update.rake +16 -0
  105. data/tasks/vanagon.rake +35 -0
  106. data/tasks/vendor_gems.rake +117 -0
  107. data/tasks/version.rake +33 -0
  108. data/tasks/z_data_dump.rake +65 -0
  109. data/templates/README +1 -0
  110. data/templates/downstream.xml.erb +47 -0
  111. data/templates/msi.xml.erb +197 -0
  112. data/templates/packaging.xml.erb +344 -0
  113. data/templates/repo.xml.erb +114 -0
  114. metadata +234 -0
@@ -0,0 +1,17 @@
1
+ # Utility methods for handling system os information
2
+
3
+ require 'rbconfig'
4
+
5
+ module Pkg::Util::OS
6
+ def windows?
7
+ case RbConfig::CONFIG['host_os']
8
+ when /mswin|mingw/i
9
+ true
10
+ else
11
+ false
12
+ end
13
+ end
14
+ module_function :windows?
15
+
16
+ DEVNULL = windows? ? 'NUL' : '/dev/null'
17
+ end
@@ -0,0 +1,40 @@
1
+ module Pkg::Util::Platform
2
+ module_function
3
+ ##########################################################################
4
+ # DEPRECATED METHODS
5
+ #
6
+ def platform_tags
7
+ Pkg::Util.deprecate('Pkg::Util::Platform.platform_tags', 'Pkg::Platforms.platform_tags')
8
+ Pkg::Platforms.platform_tags
9
+ end
10
+
11
+ def platform_lookup(platform_tag)
12
+ Pkg::Util.deprecate('Pkg::Util::Platform.platform_lookup', 'Pkg::Platforms.platform_lookup')
13
+ Pkg::Platforms.platform_lookup(platform_tag)
14
+ end
15
+
16
+ def parse_platform_tag(platform_tag)
17
+ Pkg::Util.deprecate('Pkg::Util::Platform.parse_platform_tag', 'Pkg::Platforms.parse_platform_tag')
18
+ Pkg::Platforms.parse_platform_tag(platform_tag)
19
+ end
20
+
21
+ def get_attribute(platform_tag, attribute_name)
22
+ Pkg::Util.deprecate('Pkg::Util::Platform.get_attribute', 'Pkg::Platforms.get_attribute')
23
+ Pkg::Platforms.get_attribute(platform_tag, attribute_name)
24
+ end
25
+
26
+ def artifacts_path(platform_tag, package_url = nil)
27
+ Pkg::Util.deprecate('Pkg::Util::Platform.artifacts_path', 'Pkg::Paths.artifacts_path')
28
+ Pkg::Paths.artifacts_path(platform_tag)
29
+ end
30
+
31
+ def repo_path(platform_tag)
32
+ Pkg::Util.deprecate('Pkg::Util::Platform.repo_path', 'Pkg::Paths.repo_path')
33
+ Pkg::Paths.repo_path(platform_tag)
34
+ end
35
+
36
+ def repo_config_path(platform_tag)
37
+ Pkg::Util.deprecate('Pkg::Util::Platform.repo_config_path', 'Pkg::Paths.repo_config_path')
38
+ Pkg::Paths.repo_config_path(platform_tag)
39
+ end
40
+ end
@@ -0,0 +1,111 @@
1
+ require 'rake'
2
+
3
+ # Utility methods for working with rake tasks. These utilities will not work
4
+ # if the packaging repo was loaded as a library unless rake has been required
5
+ # explicitly.
6
+
7
+ module Pkg::Util::RakeUtils
8
+ class << self
9
+ def using_rake?
10
+ defined?(Rake::Task)
11
+ end
12
+
13
+ def task_defined?(task_name)
14
+ if using_rake?
15
+ Rake::Task.task_defined?(task_name)
16
+ end
17
+ end
18
+
19
+ # Return the Rake::Task object associated with a task name
20
+ #
21
+ def get_task(task_name)
22
+ if using_rake? and task_defined?(task_name)
23
+ Rake::Task[task_name]
24
+ end
25
+ end
26
+
27
+ def invoke_task(task, *args)
28
+ Rake::Task[task].reenable
29
+ Rake::Task[task].invoke(*args)
30
+ end
31
+
32
+ # Add a dependency to a rake task. "depender" must be an instance of
33
+ # Rake::Task, but dependency can be either a Rake::Task instance, or a String
34
+ # referring to the name of a Rake::Task instance.
35
+ #
36
+ def add_dependency(depender, dependency)
37
+ if using_rake?
38
+ if !task_defined?(depender)
39
+ fail "Could not locate a Rake task named '#{depender.to_s}' to add a dependency of '#{dependency.to_s}' to"
40
+ elsif !task_defined?(dependency)
41
+ fail "Could not locate a Rake task named '#{dependency.to_s}' to add as a dependency of '#{depender.to_s}'"
42
+ else
43
+ depender_task = Rake::Task[depender]
44
+ depender_task.enhance([dependency])
45
+ end
46
+ end
47
+ end
48
+
49
+ # Evaluate any pre-tasks known by the configuration of this invocation.
50
+ # Again, this is quite pointless if the user has not invoked the packaging
51
+ # repo via rake, so we're just not going to do anything.
52
+ #
53
+ def evaluate_pre_tasks
54
+ if using_rake? and Pkg::Config.pre_tasks
55
+ unless Pkg::Config.pre_tasks.is_a?(Hash)
56
+ fail "The 'pre_tasks' key must be a Hash of depender => dependency pairs"
57
+ end
58
+ Pkg::Config.pre_tasks.each do |depender, dependency|
59
+ add_dependency(depender, dependency)
60
+ end
61
+ end
62
+ end
63
+
64
+ def load_packaging_tasks(packaging_root = Pkg::Config.packaging_root)
65
+ packaging_task_dir = File.join(packaging_root, 'tasks')
66
+ tasks = [
67
+ '00_utils.rake',
68
+ '30_metrics.rake',
69
+ 'apple.rake',
70
+ 'build.rake',
71
+ 'clean.rake',
72
+ 'deb.rake',
73
+ 'deb_repos.rake',
74
+ 'doc.rake',
75
+ 'education.rake',
76
+ 'fetch.rake',
77
+ 'gem.rake',
78
+ 'jenkins.rake',
79
+ 'jenkins_dynamic.rake',
80
+ 'load_extras.rake',
81
+ 'mock.rake',
82
+ 'nightly_repos.rake',
83
+ 'pe_deb.rake',
84
+ 'pe_rpm.rake',
85
+ 'pe_ship.rake',
86
+ 'pe_sign.rake',
87
+ 'pe_tar.rake',
88
+ 'retrieve.rake',
89
+ 'rpm.rake',
90
+ 'rpm_repos.rake',
91
+ 'ship.rake',
92
+ 'sign.rake',
93
+ 'tag.rake',
94
+ 'tar.rake',
95
+ 'update.rake',
96
+ 'vendor_gems.rake',
97
+ 'version.rake',
98
+ 'z_data_dump.rake',
99
+ 'config.rake',
100
+ 'vanagon.rake',
101
+ 'deprecated.rake'
102
+ ]
103
+
104
+ tasks.each do |task|
105
+ load File.join(packaging_task_dir, task)
106
+ end
107
+
108
+ Pkg::Util::RakeUtils.evaluate_pre_tasks
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,19 @@
1
+ # Utility methods for dealing with serialization of Config params
2
+
3
+ module Pkg::Util::Serialization
4
+ class << self
5
+
6
+ # Given the path to a yaml file, load the yaml file into an object and return the object.
7
+ def load_yaml(file)
8
+ require 'yaml'
9
+ file = File.expand_path(file)
10
+ begin
11
+ input_data = YAML.load_file(file) || {}
12
+ rescue => e
13
+ fail "There was an error loading data from #{file}.\n#{e}"
14
+ end
15
+ input_data
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,171 @@
1
+ # Module for shipping all packages to places
2
+ require 'tmpdir'
3
+ module Pkg::Util::Ship
4
+ module_function
5
+
6
+ def collect_packages(pkg_exts, excludes = []) # rubocop:disable Metrics/MethodLength
7
+ pkgs = pkg_exts.map { |ext| Dir.glob(ext) }.flatten
8
+ return [] if pkgs.empty?
9
+ excludes.each do |exclude|
10
+ pkgs.delete_if { |p| p.match(exclude) }
11
+ end if excludes
12
+ if pkgs.empty?
13
+ $stdout.puts "No packages with (#{pkg_exts.join(', ')}) extensions found staged in 'pkg'"
14
+ $stdout.puts "Maybe your excludes argument (#{excludes}) is too restrictive?"
15
+ end
16
+ pkgs
17
+ end
18
+
19
+ # Takes a set of packages and reorganizes them into the final repo
20
+ # structure before they are shipping out to their final destination.
21
+ #
22
+ # This assumes the working directory is a temporary directory that will
23
+ # later be cleaned up
24
+ #
25
+ # If this is platform_independent the packages will not get reorganized,
26
+ # just copied under the tmp directory for more consistent workflows
27
+ def reorganize_packages(pkgs, tmp, platform_independent = false)
28
+ new_pkgs = []
29
+ pkgs.each do |pkg|
30
+ if platform_independent
31
+ path = 'pkg'
32
+ else
33
+ platform_tag = Pkg::Paths.tag_from_artifact_path(pkg)
34
+ path = Pkg::Paths.artifacts_path(platform_tag, 'pkg')
35
+ end
36
+ FileUtils.mkdir_p File.join(tmp, path)
37
+ FileUtils.cp pkg, File.join(tmp, path)
38
+ new_pkgs << File.join(path, File.basename(pkg))
39
+ end
40
+ new_pkgs
41
+ end
42
+
43
+ # Take local packages and restructure them to the desired final path before
44
+ # shipping to the staging server
45
+ # @param [Array] pkg_exts the file globs for the files you want to ship
46
+ # For example, something like ['pkg/**/*.rpm', 'pkg/**/*.deb'] to ship
47
+ # the rpms and debs
48
+ # @param [String] staging_server The hostname to ship the packages to
49
+ # @param [String] remote_path The base path to ship the packages to on the
50
+ # staging_server, for example '/opt/downloads/windows' or
51
+ # '/opt/repository/yum'
52
+ # @param [Hash] opts Additional options that can be used when shipping
53
+ # packages
54
+ # @option opts [Array] :excludes File globs to exclude packages from shipping
55
+ # @option opts [Boolean] :chattr Whether or not to make the files immutable
56
+ # after shipping. Defaults to true.
57
+ # @option opts [Boolean] :platform_independent Whether or not the path the
58
+ # packages ship to has platform-dependent information in it. Defaults to
59
+ # false (most paths will be platform dependent), but set to true for gems
60
+ # and tarballs since those just land directly under /opt/downloads/<project>
61
+ #
62
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
63
+ def ship_pkgs(pkg_exts, staging_server, remote_path, opts = {})
64
+ options = {
65
+ excludes: [],
66
+ chattr: true,
67
+ platform_independent: false }.merge(opts)
68
+
69
+ # First find the packages to be shipped. We must find them before moving
70
+ # to our temporary staging directory
71
+ local_packages = collect_packages(pkg_exts, options[:excludes])
72
+ return if local_packages.empty?
73
+
74
+ tmpdir = Dir.mktmpdir
75
+ staged_pkgs = reorganize_packages(local_packages, tmpdir, options[:platform_independent])
76
+
77
+ puts staged_pkgs.sort
78
+ puts "Do you want to ship the above files to (#{staging_server})?"
79
+ if Pkg::Util.ask_yes_or_no
80
+ extra_flags = ['--ignore-existing', '--delay-updates']
81
+ extra_flags << '--dry-run' if ENV['DRYRUN']
82
+
83
+ staged_pkgs.each do |pkg|
84
+ Pkg::Util::Execution.retry_on_fail(times: 3) do
85
+ sub_string = 'pkg'
86
+ remote_pkg = pkg.sub(sub_string, remote_path)
87
+ remote_basepath = File.dirname(remote_pkg)
88
+ Pkg::Util::Net.remote_ssh_cmd(staging_server, "mkdir -p #{remote_basepath}")
89
+ Pkg::Util::Net.rsync_to(
90
+ File.join(tmpdir, pkg),
91
+ staging_server,
92
+ remote_basepath,
93
+ extra_flags: extra_flags
94
+ )
95
+
96
+ Pkg::Util::Net.remote_set_ownership(staging_server, 'root', 'release', [remote_basepath, remote_pkg])
97
+ Pkg::Util::Net.remote_set_permissions(staging_server, '775', [remote_basepath])
98
+ Pkg::Util::Net.remote_set_permissions(staging_server, '0664', [remote_pkg])
99
+ Pkg::Util::Net.remote_set_immutable(staging_server, [remote_pkg]) if options[:chattr]
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ def rolling_repo_link_command(platform_tag, repo_path)
106
+ base_path, link_path = Pkg::Paths.artifacts_base_path_and_link_path(platform_tag, repo_path)
107
+
108
+ if link_path.nil?
109
+ puts "No link target set, not creating rolling repo link for #{base_path}"
110
+ return nil
111
+ end
112
+
113
+ cmd = <<-CMD
114
+ if [ ! -d #{base_path} ] ; then
115
+ echo "Link target '#{base_path}' does not exist; skipping"
116
+ exit 0
117
+ fi
118
+ # If it's a link but pointing to the wrong place, remove the link
119
+ # This is likely to happen around the transition times, like puppet5 -> puppet6
120
+ if [ -L #{link_path} ] && [ ! #{base_path} -ef #{link_path} ] ; then
121
+ rm #{link_path}
122
+ # This is the link you're looking for, nothing to see here
123
+ elif [ -L #{link_path} ] ; then
124
+ exit 0
125
+ # Don't want to delete it if it isn't a link, that could be destructive
126
+ # So, fail!
127
+ elif [ -e #{link_path} ] ; then
128
+ echo "#{link_path} exists but isn't a link, I don't know what to do with this" >&2
129
+ exit 1
130
+ fi
131
+ ln -s #{base_path} #{link_path}
132
+ CMD
133
+ end
134
+
135
+ def create_rolling_repo_link(platform_tag, staging_server, repo_path)
136
+ command = rolling_repo_link_command(platform_tag, repo_path)
137
+
138
+ Pkg::Util::Net.remote_ssh_cmd(staging_server, command) unless command.nil?
139
+ rescue => e
140
+ fail "Failed to create rolling repo link for '#{platform_tag}'.\n#{e}"
141
+ end
142
+
143
+ def test_ship(vm, ship_task)
144
+ command = 'getent group release || groupadd release'
145
+ Pkg::Util::Net.remote_ssh_cmd(vm, command)
146
+ hosts_to_override = %w(
147
+ APT_HOST
148
+ DMG_HOST
149
+ GEM_HOST
150
+ IPS_HOST
151
+ MSI_HOST
152
+ P5P_HOST
153
+ SVR4_HOST
154
+ SWIX_HOST
155
+ TAR_HOST
156
+ YUM_HOST
157
+ APT_SIGNING_SERVER
158
+ APT_STAGING_SERVER
159
+ DMG_STAGING_SERVER
160
+ MSI_STAGING_SERVER
161
+ SWIX_STAGING_SERVER
162
+ TAR_STAGING_SERVER
163
+ YUM_STAGING_SERVER
164
+ STAGING_SERVER
165
+ )
166
+ hosts_to_override.each do |host|
167
+ ENV[host] = vm
168
+ end
169
+ Rake::Task[ship_task].invoke
170
+ end
171
+ end
@@ -0,0 +1,41 @@
1
+ # Utility methods for handling system binaries
2
+
3
+ module Pkg::Util::Tool
4
+
5
+ # Set up utility methods for handling system binaries
6
+ #
7
+ class << self
8
+ def check_tool(tool)
9
+ find_tool(tool, :required => true)
10
+ end
11
+
12
+ def find_tool(tool, args = { :required => false })
13
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |root|
14
+ location = File.join(root, tool)
15
+
16
+ if Pkg::Util::OS.windows? && File.extname(location).empty?
17
+ exts = ENV['PATHEXT']
18
+ exts = exts ? exts.split(File::PATH_SEPARATOR) : %w(.EXE .BAT .CMD .COM)
19
+ exts.each do |ext|
20
+ locationext = File.expand_path(location + ext)
21
+
22
+ return locationext if FileTest.executable?(locationext)
23
+ end
24
+ end
25
+
26
+ return location if FileTest.executable? location
27
+ end
28
+ fail "#{tool} tool not found...exiting" if args[:required]
29
+ return nil
30
+ end
31
+
32
+ alias :has_tool :find_tool
33
+
34
+ end
35
+
36
+ # Set up paths to system tools we use in the packaging repo
37
+ # no matter what distribution we're packaging for.
38
+
39
+ GIT = Pkg::Util::Tool.check_tool('git')
40
+
41
+ end
@@ -0,0 +1,326 @@
1
+ require 'json'
2
+
3
+ # Utility methods used for versioning projects for various kinds of packaging
4
+ module Pkg::Util::Version
5
+ class << self
6
+ def uname_r
7
+ uname = Pkg::Util::Tool.find_tool('uname', required: true)
8
+ stdout, = Pkg::Util::Execution.capture3("#{uname} -r")
9
+ stdout.chomp
10
+ end
11
+
12
+ def pwd_version
13
+ Dir.pwd.split('.')[-1]
14
+ end
15
+
16
+ def debversion
17
+ base_pkg_version.join('-') << "#{Pkg::Config.packager}1"
18
+ end
19
+
20
+ def origversion
21
+ Pkg::Config.debversion.split('-')[0]
22
+ end
23
+
24
+ def rpmversion
25
+ base_pkg_version[0]
26
+ end
27
+
28
+ def rpmrelease
29
+ base_pkg_version[1]
30
+ end
31
+
32
+ # This is used to set Pkg::Config.version
33
+ # describe can return a number of potential formats
34
+ # 5.3.0
35
+ # 5.3.0-18-gfbddc8f
36
+ # 5.3.0-18-gfbddc8f-dirty
37
+ # 0.7.0-rc1
38
+ # 0.7.0-rc1-63-g51ccc51
39
+ # 0.7.0-rc1-63-g51ccc51-dirty
40
+ #
41
+ # we want all of it except the `gfbddc8f` part.
42
+ def dash_version
43
+ describe = Pkg::Util::Git.describe
44
+ info = describe.split('-')
45
+
46
+ if Pkg::Util::Git.ref_type == "tag"
47
+ describe
48
+ else
49
+ info.reject { |d| d.match(/^g.{7}/) }.join('-')
50
+ end
51
+ end
52
+
53
+ # This version is used for gems and platform types that do not support
54
+ # dashes in the package version
55
+ def dot_version(version = Pkg::Config.version)
56
+ version.tr('-', '.')
57
+ end
58
+
59
+ # Given a version, reformat it to be appropriate for a final package
60
+ # version. This means we need to add a `0.` before the release version
61
+ # for non-final builds
62
+ #
63
+ # This only applies to packages that are built with the automation in this
64
+ # repo. This is invalid for all other build automation, like vanagon
65
+ #
66
+ # Examples of output:
67
+ # 4.99.0.22.gf64bc49-1
68
+ # 4.4.1-0.1SNAPSHOT.2017.05.16T1005
69
+ # 4.99.0-1
70
+ # 4.99.0.29.g431768c-1
71
+ # 2.7.1-1
72
+ # 5.3.0.rc4-1
73
+ # 3.0.5.rc6.24.g431768c-1
74
+ #
75
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
76
+ def base_pkg_version(version = Pkg::Config.version)
77
+ return "#{dot_version(version)}-#{Pkg::Config.release}".split('-') if final?(version) || Pkg::Config.vanagon_project
78
+
79
+ if version.include?('SNAPSHOT')
80
+ new_version = dot_version(version).sub(/\.SNAPSHOT/, "-0.#{Pkg::Config.release}SNAPSHOT")
81
+ elsif version.include?('rc')
82
+ rc_ver = dot_version(version).match(/\.?rc(\d+)/)[1]
83
+ new_version = dot_version(version).sub(/\.?rc(\d+)/, '') + "-0.#{Pkg::Config.release}rc#{rc_ver}"
84
+ else
85
+ new_version = dot_version(version) + "-0.#{Pkg::Config.release}"
86
+ end
87
+
88
+ if new_version.include?('dirty')
89
+ new_version = new_version.sub(/\.?dirty/, '') + 'dirty'
90
+ end
91
+
92
+ new_version.split('-')
93
+ end
94
+
95
+ # Determines if the version we are working with is or is not final
96
+ #
97
+ # The version here does not include the release version. Therefore, we
98
+ # assume that any version that includes a `-\d+` was not built from a tag
99
+ # and is a non-final version.
100
+ # Examples:
101
+ # Final
102
+ # - 5.0.0
103
+ # - 2016.5.6.7
104
+ # Nonfinal
105
+ # - 4.99.0-22
106
+ # - 1.0.0-658-gabc1234
107
+ # - 5.0.0.master.SNAPSHOT.2017.05.16T1357
108
+ # - 5.9.7-rc4
109
+ # - 4.99.0-56-dirty
110
+ #
111
+ def final?(version = Pkg::Config.version)
112
+ case version
113
+ when /rc/
114
+ false
115
+ when /SNAPSHOT/
116
+ false
117
+ when /g[a-f0-9]{7}/
118
+ false
119
+ when /^(\d+\.)+\d+-\d+/
120
+ false
121
+ when /-dirty/
122
+ Pkg::Config.allow_dirty_tree
123
+ else
124
+ true
125
+ end
126
+ end
127
+
128
+ # This is to support packages that only burn-in the version number in the
129
+ # release artifact, rather than storing it two (or more) times in the
130
+ # version control system. Razor is a good example of that; see
131
+ # https://github.com/puppetlabs/Razor/blob/master/lib/project_razor/version.rb
132
+ # for an example of that this looks like.
133
+ #
134
+ # If you invoke this the version will only be modified in the temporary copy,
135
+ # with the intent that it never change the official source tree.
136
+ #
137
+ # rubocop:disable Metrics/AbcSize
138
+ # rubocop:disable Metrics/CyclomaticComplexity
139
+ # rubocop:disable Metrics/PerceivedComplexity
140
+ def versionbump(workdir = nil)
141
+ version = ENV['VERSION'] || Pkg::Config.version.to_s.strip
142
+ new_version = '"' + version + '"'
143
+
144
+ version_file = "#{workdir ? workdir + '/' : ''}#{Pkg::Config.version_file}"
145
+
146
+ # Read the previous version file in...
147
+ contents = IO.read(version_file)
148
+
149
+ # Match version files containing 'VERSION = "x.x.x"' and just x.x.x
150
+ if contents =~ /VERSION =.*/
151
+ old_version = contents.match(/VERSION =.*/).to_s.split[-1]
152
+ else
153
+ old_version = contents
154
+ end
155
+
156
+ puts "Updating #{old_version} to #{new_version} in #{version_file}"
157
+ if contents =~ /@DEVELOPMENT_VERSION@/
158
+ contents.gsub!('@DEVELOPMENT_VERSION@', version)
159
+ elsif contents =~ /version\s*=\s*[\'"]DEVELOPMENT[\'"]/
160
+ contents.gsub!(/version\s*=\s*['"]DEVELOPMENT['"]/, "version = '#{version}'")
161
+ elsif contents =~ /VERSION = #{old_version}/
162
+ contents.gsub!("VERSION = #{old_version}", "VERSION = #{new_version}")
163
+ elsif contents =~ /#{Pkg::Config.project.upcase}VERSION = #{old_version}/
164
+ contents.gsub!("#{Pkg::Config.project.upcase}VERSION = #{old_version}", "#{Pkg::Config.project.upcase}VERSION = #{new_version}")
165
+ else
166
+ contents.gsub!(old_version, Pkg::Config.version)
167
+ end
168
+
169
+ # ...and write it back on out.
170
+ File.open(version_file, 'w') { |f| f.write contents }
171
+ end
172
+
173
+ # Human readable output for json tags reporting. This will load the
174
+ # input json file and output if it "looks tagged" or not
175
+ #
176
+ # @param json_data [hash] json data hash containing the ref to check
177
+ def report_json_tags(json_data) # rubocop:disable Metrics/AbcSize
178
+ puts 'component: ' + File.basename(json_data['url'])
179
+ puts 'ref: ' + json_data['ref'].to_s
180
+ if Pkg::Util::Git.remote_tagged?(json_data['url'], json_data['ref'].to_s)
181
+ tagged = 'Tagged? [ Yes ]'
182
+ else
183
+ tagged = 'Tagged? [ No ]'
184
+ end
185
+ col_len = (ENV['COLUMNS'] || 70).to_i
186
+ puts format("\n%#{col_len}s\n\n", tagged)
187
+ puts '*' * col_len
188
+ end
189
+
190
+ ##########################################################################
191
+ # DEPRECATED METHODS
192
+ #
193
+ def git_co(ref)
194
+ Pkg::Util.deprecate('Pkg::Util::Version.git_co', 'Pkg::Util::Git.checkout')
195
+ Pkg::Util::Git.checkout(ref)
196
+ end
197
+
198
+ def git_tagged?
199
+ Pkg::Util.deprecate('Pkg::Util::Version.git_tagged?', 'Pkg::Util::Git.tagged?')
200
+ Pkg::Util::Git.tagged?
201
+ end
202
+
203
+ def git_describe
204
+ Pkg::Util.deprecate('Pkg::Util::Version.git_describe', 'Pkg::Util::Git.describe')
205
+ Pkg::Util::Git.describe
206
+ end
207
+
208
+ def git_sha(length = 40)
209
+ Pkg::Util.deprecate('Pkg::Util::Version.git_sha', 'Pkg::Util::Git.sha')
210
+ Pkg::Util::Git.sha(length)
211
+ end
212
+
213
+ def git_ref_type
214
+ Pkg::Util.deprecate('Pkg::Util::Version.git_ref_type', 'Pkg::Util::Git.ref_type')
215
+ Pkg::Util::Git.ref_type
216
+ end
217
+
218
+ def git_sha_or_tag(length = 40)
219
+ Pkg::Util.deprecate('Pkg::Util::Version.git_sha_or_tag', 'Pkg::Util::Git.sha_or_tag')
220
+ Pkg::Util::Git.sha_or_tag(length)
221
+ end
222
+
223
+ def is_git_repo?
224
+ Pkg::Util.deprecate('Pkg::Util::Version.is_git_repo?', 'Pkg::Util::Git.repo?')
225
+ Pkg::Util::Git.repo?
226
+ end
227
+
228
+ def git_project_name
229
+ Pkg::Util.deprecate('Pkg::Util::Version.git_project_name', 'Pkg::Util::Git.project_name')
230
+ Pkg::Util::Git.project_name
231
+ end
232
+
233
+ def git_describe_version
234
+ Pkg::Util.deprecate('Pkg::Util::Version.git_describe_version', 'Pkg::Util::Git.describe')
235
+ Pkg::Util::Git.describe
236
+ end
237
+
238
+ def run_git_describe_internal
239
+ Pkg::Util.deprecate('Pkg::Util::Version.git_describe_version', 'Pkg::Util::Git.describe')
240
+ Pkg::Util::Git.describe
241
+ end
242
+
243
+ def get_dash_version
244
+ Pkg::Util.deprecate('Pkg::Util::Version.get_dash_version', 'Pkg::Util::Version.dash_version')
245
+ Pkg::Util::Version.dash_version
246
+ end
247
+
248
+ def get_ips_version
249
+ raise "The IPS build tasks have been removed from puppetlabs/packaging. Please port all Solaris projects to vanagon (https://github.com/puppetlabs/vanagon)"
250
+ end
251
+
252
+ def get_dot_version
253
+ Pkg::Util.deprecate('Pkg::Util::Version.get_dot_version', 'Pkg::Util::Version.dot_version')
254
+ Pkg::Util::Version.dot_version
255
+ end
256
+
257
+ def get_pwd_version
258
+ Pkg::Util.deprecate('Pkg::Util::Version.get_pwd_version', 'Pkg::Util::Version.pwd_version')
259
+ Pkg::Util::Version.pwd_version
260
+ end
261
+
262
+ def get_base_pkg_version
263
+ Pkg::Util.deprecate('Pkg::Util::Version.get_base_pkg_version', 'Pkg::Util::Version.base_pkg_version')
264
+ Pkg::Util::Version.base_pkg_version
265
+ end
266
+
267
+ def get_debversion
268
+ Pkg::Util.deprecate('Pkg::Util::Version.get_debversion', 'Pkg::Util::Version.debversion')
269
+ Pkg::Util::Version.debversion
270
+ end
271
+
272
+ def get_origversion
273
+ Pkg::Util.deprecate('Pkg::Util::Version.get_origversion', 'Pkg::Util::Version.origversion')
274
+ Pkg::Util::Version.origversion
275
+ end
276
+
277
+ def get_rpmversion
278
+ Pkg::Util.deprecate('Pkg::Util::Version.get_rpmversion', 'Pkg::Util::Version.rpmversion')
279
+ Pkg::Util::Version.rpmversion
280
+ end
281
+
282
+ def get_rpmrelease
283
+ Pkg::Util.deprecate('Pkg::Util::Version.get_rpmrelease', 'Pkg::Util::Version.rpmrelease')
284
+ Pkg::Util::Version.rpmrelease
285
+ end
286
+
287
+ def source_dirty?
288
+ Pkg::Util.deprecate('Pkg::Util::Version.source_dirty?', 'Pkg::Util::Git.source_dirty?')
289
+ Pkg::Util::Git.source_dirty?
290
+ end
291
+
292
+ def fail_on_dirty_source
293
+ Pkg::Util.deprecate('Pkg::Util::Version.fail_on_dirty_source', 'Pkg::Util::Git.fail_on_dirty_source')
294
+ Pkg::Util::Git.fail_on_dirty_source
295
+ end
296
+
297
+ def is_final?
298
+ Pkg::Util.deprecate('Pkg::Util::Version.is_final?', 'Pkg::Util::Version.final?')
299
+ Pkg::Util::Version.final?
300
+ end
301
+
302
+ def is_rc?
303
+ Pkg::Util.deprecate('Pkg::Util::Version.is_rc?', 'Pkg::Util::Version.final?')
304
+ Pkg::Util::Version.final?
305
+ end
306
+
307
+ def is_odd?
308
+ Pkg::Util.deprecate('Pkg::Util::Version.is_odd?', 'Pkg::Util::Version.final?')
309
+ Pkg::Util::Version.final?
310
+ end
311
+
312
+ def is_less_than_one?
313
+ Pkg::Util.deprecate('Pkg::Util::Version.is_less_than_one?', 'Pkg::Util::Version.final?')
314
+ Pkg::Util::Version.final?
315
+ end
316
+
317
+ def el_version
318
+ raise "Pkg::Util::Version.el_version has been removed"
319
+ end
320
+
321
+ def tagged?(url, ref)
322
+ Pkg::Util.deprecate('Pkg::Util::Version.tagged?', 'Pkg::Util::Git.remote_tagged?')
323
+ Pkg::Util::Git.remote_tagged?(url, ref)
324
+ end
325
+ end
326
+ end