-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathRakefile
144 lines (122 loc) · 4.69 KB
/
Rakefile
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require 'digest'
require 'erb'
require 'net/http'
require 'tmpdir'
def fetch(uri, limit = 10)
# puts "Fetching #{uri}" # Uncomment to debug what URI's are being fetched
raise 'too many HTTP redirects' if limit == 0
response = Net::HTTP.get_response(URI(uri))
case response
when Net::HTTPSuccess then
response
when Net::HTTPRedirection then
fetch(response['location'], limit - 1)
else
raise "Request for listing failed: #{response.body}"
end
end
PKG_TO_COLLECTIONS = {
'puppet-bolt' => 'puppet-tools',
'pdk' => 'puppet-tools'
}
VERSION_TO_CODENAME = {
'10.10' => :yosemite,
'10.11' => :el_capitan,
'10.12' => :sierra,
'10.13' => :high_sierra,
'10.14' => :mojave,
'10.15' => :catalina,
'11' => :big_sur,
'12' => :monterey,
'13' => :ventura,
'14' => :sonoma,
}
LATEST_PE = '2021'
CLIENT_TOOLS = {
'2021' => '21.1.0',
'2019.8' => '19.8.6',
}
def operating_systems(collection, pkg = nil)
if %w[puppet-bolt].include?(pkg)
return %w[10.11 10.12 10.13 10.14 10.15 11 12]
end
if %w[pdk].include?(pkg)
return %w[11 12 13]
end
case collection
when 'pct2019.8'
%w[10.14 10.15]
when 'pct2021'
%w[10.14 10.15]
when 'puppet7'
%w[11 12 13 14]
when 'puppet'
%w[11 12 13 14]
when 'puppet8'
%w[11 12 13 14]
else
%w[10.11 10.12 10.13 10.14 10.15 11 12 13 14]
end
end
namespace :brew do
desc 'Update SHAs for a specific package: rake brew:cask[puppet-bolt] or rake brew:cask[puppet-agent,5]'
task :cask, [:pkg, :collection] do |task, args|
pkg = args[:pkg]
collection = PKG_TO_COLLECTIONS[pkg] || "puppet#{args[:collection]}"
cask = pkg
cask += '-' + args[:collection] if args[:collection]
os_versions = operating_systems(collection, pkg)
path_pre = "https://downloads.puppet.com/mac/#{collection}/"
latest_versions = os_versions.map do |os_ver|
resp = fetch("#{path_pre}#{os_ver}/x86_64/")
raise "Request for listing failed: #{resp.body}" unless resp.kind_of? Net::HTTPSuccess
versions = resp.body.scan(/#{pkg}-(\d+\.\d+\.\d+(?:\.\d+)?)-\d\.osx#{os_ver}\.dmg/).map(&:first).uniq
versions.sort_by! {|version| Gem::Version.new(version)}
versions.last
end
puts "Getting SHA256 sums for #{pkg}: #{latest_versions}"
package_triples = os_versions.zip(latest_versions).map do |os_ver, pkg_ver|
if pkg_ver
resp = fetch("#{path_pre}#{os_ver}/x86_64/#{pkg}-#{pkg_ver}-1.osx#{os_ver}.dmg")
x86_64_sha = Digest::SHA256.hexdigest(resp.body)
arm64_sha = 'nil'
if pkg == 'puppet-agent' && os_ver.to_i > 11 && cask == 'puppet-agent-8' || pkg == 'puppet-agent' && cask != 'puppet-agent-8' ||
pkg == 'pdk' && os_ver.to_i > 12
resp_arm64 = fetch("#{path_pre}#{os_ver}/arm64/#{pkg}-#{pkg_ver}-1.osx#{os_ver}.dmg")
arm64_sha = Digest::SHA256.hexdigest(resp_arm64.body)
end
[os_ver, pkg_ver, x86_64_sha, arm64_sha]
end
end.compact
url = "#{path_pre}"+'#{os_ver}/#{arch}/'+pkg+'-#{version}-1.osx#{os_ver}.dmg'
source_stanza = ERB.new(File.read(File.join(__dir__, 'templates', "source_stanza.erb")), trim_mode: '-').result(binding)
cask_erb = ERB.new(File.read(File.join(__dir__, 'templates', "#{cask}.rb.erb")), trim_mode: '-')
File.write(File.join(__dir__, 'Casks', "#{cask}.rb"), cask_erb.result(binding))
end
desc 'Update SHAs for pe-client-tools: rake brew:pe_client_tools rake brew:pe_client_tools[2019.3]'
task :pe_client_tools, [:collection] do |task, args|
pkg = 'pe-client-tools'
collection = args[:collection] || LATEST_PE
version = CLIENT_TOOLS[collection]
cask = pkg
cask += '-' + args[:collection] if args[:collection]
os_versions = operating_systems("pct#{collection}")
pe_ver = CLIENT_TOOLS[collection].dup.prepend('20')
path_pre = "https://pm.puppet.com/pe-client-tools/#{pe_ver}/"
latest_versions = os_versions.map do |os_ver|
version
end
package_triples = os_versions.zip(latest_versions).map do |os_ver, pkg_ver|
if pkg_ver
puts "Getting SHA256 sum for #{pkg} #{pkg_ver} on macOS #{os_ver}"
resp = fetch("#{path_pre}#{pkg_ver}/repos/apple/#{os_ver}/PC1/x86_64/#{pkg}-#{pkg_ver}-1.osx#{os_ver}.dmg")
sha = Digest::SHA256.hexdigest(resp.body)
[os_ver, pkg_ver, sha]
end
end.compact
url = "#{path_pre}"+'#{version}/repos/apple/#{os_ver}/PC1/x86_64/'+pkg+'-#{version}-1.osx#{os_ver}.dmg'
source_stanza = ERB.new(File.read(File.join(__dir__, 'templates', "source_stanza.erb")), 0, '-').result(binding)
cask_erb = ERB.new(File.read(File.join(__dir__, 'templates', "#{cask}.rb.erb")), 0, '-')
File.write(File.join(__dir__, 'Casks', "#{cask}.rb"), cask_erb.result(binding))
end
end