forked from tuist/tuist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
316 lines (262 loc) · 8.87 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# frozen_string_literal: true
SWIFTDOC_VERSION = "1.0.0-beta.5".freeze
SWIFTLINT_VERSION = "0.40.2".freeze
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'
require 'mkmf'
require 'fileutils'
require "google/cloud/storage"
require "encrypted/environment"
require 'colorize'
require 'highline'
require 'tmpdir'
require 'json'
require 'zip'
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "--format pretty"
end
desc("Updates swift-doc binary with the latest version available.")
task :swift_doc_update do
root_dir = File.expand_path(__dir__)
Dir.mktmpdir do |temporary_dir|
Dir.chdir(temporary_dir) do
system("curl", "-LO", "https://github.com/SwiftDocOrg/swift-doc/archive/#{SWIFTDOC_VERSION}.zip")
extract_zip("#{SWIFTDOC_VERSION}.zip", "swift-doc")
Dir.chdir("swift-doc/swift-doc-#{SWIFTDOC_VERSION}") do
system("make", "swift-doc")
end
system("cp", "swift-doc/swift-doc-#{SWIFTDOC_VERSION}/.build/release/swift-doc", "#{root_dir}/vendor/swift-doc")
end
end
File.write(File.join(root_dir, "vendor/.swiftdoc.version"), SWIFTDOC_VERSION)
end
desc("Updates swift-lint binary with the latest version available.")
task :swift_lint_update do
root_dir = File.expand_path(__dir__)
Dir.mktmpdir do |temporary_dir|
Dir.chdir(temporary_dir) do
system("curl", "-LO", "https://github.com/realm/SwiftLint/releases/download/#{SWIFTLINT_VERSION}/portable_swiftlint.zip")
extract_zip("portable_swiftlint.zip", "portable_swiftlint")
system("cp", "portable_swiftlint/swiftlint", "#{root_dir}/vendor/swiftlint")
end
end
File.write(File.join(root_dir, "vendor/.swiftlint.version"), SWIFTLINT_VERSION)
end
desc("Formats the code style")
task :style_correct do
system(swiftlint_path, "autocorrect")
system(swiftformat_path, ".")
end
desc("Swift format check")
task :swift_format do
Kernel.system(swiftformat_path, "--lint", ".") || abort
end
desc("Swift lint check")
task :swift_lint do
Kernel.system(swiftlint_path) || abort
end
desc("Lints the Ruby code style")
task :style_ruby do
system("bundle", "exec", "rubocop")
end
desc("Corrects the issues with the Ruby style")
task :style_ruby_correct do
system("bundle", "exec", "rubocop", "-a")
end
desc("Builds and archive a release version of tuist and tuistenv for local testing.")
task :local_package do
package
end
desc("Builds, archives, and publishes tuist and tuistenv for release")
task :release, [:version] do |task, options|
decrypt_secrets
release(options[:version])
end
desc("Publishes the installation scripts")
task :release_scripts do
decrypt_secrets
release_scripts
end
desc("Packages tuist, tags it with the commit sha and uploads it to gcs")
task :package_commit do
decrypt_secrets
package
bucket = storage.bucket("tuist-builds")
sha = %x(git rev-parse HEAD).strip.chomp
print_section("Uploading tuist-#{sha}")
file = bucket.create_file(
"build/tuist.zip",
"#{sha}.zip"
)
file.acl.public!
print_section("Uploaded 🚀")
end
desc("Encrypt secret keys")
task :encrypt_secrets do
Encrypted::Environment.encrypt_ejson("secrets.ejson", private_key: ENV["SECRET_KEY"])
end
desc("Benchmarks tuist against a specified versiom")
task :benchmark do
print_section("🛠 Building supporting tools")
# Build tuistbench
system(
"swift", "build",
"-c", "release",
"--package-path", "tools/tuistbench"
)
# Build fixturegen
system(
"swift", "build",
"-c", "release",
"--package-path", "tools/fixturegen"
)
# Generate large fixture
print_section("📁 Generating fixtures ...")
FileUtils.mkdir_p("generated_fixtures")
system(
"tools/fixturegen/.build/release/fixturegen",
"--path", "generated_fixtures/50_projects",
"--projects", "50",
)
system(
"tools/fixturegen/.build/release/fixturegen",
"--path", "generated_fixtures/2000_sources",
"--projects", "2",
"--sources", "2000",
)
# Generate fixture list
fixtures = {
"paths" => [
"generated_fixtures/50_projects",
"generated_fixtures/2000_sources",
"fixtures/ios_app_with_static_frameworks",
"fixtures/ios_app_with_framework_and_resources",
"fixtures/ios_app_with_transitive_framework",
"fixtures/ios_app_with_xcframeworks",
]
}
File.open(".fixtures.generated.json","w") do |f|
f.write(fixtures.to_json)
end
# Build current version of tuist
print_section("🔨 Building release version of tuist ...")
system("swift", "build", "--product", "tuist", "--configuration", "release")
system("swift", "build", "--product", "tuistenv", "--configuration", "release")
system("swift", "build", "--product", "ProjectDescription", "--configuration", "release")
# Download latest tuist
print_section("⬇️ Downloading latest published version of tuist ...")
system(".build/release/tuistenv", "update")
puts("Reference tuist version:")
system(".build/release/tuistenv", "version")
print_section("⏱ Benchmarking ...")
system(
"tools/tuistbench/.build/release/tuistbench",
"-b", ".build/release/tuist",
"-r", ".build/release/tuistenv",
"-l", ".fixtures.generated.json",
"--format", "markdown"
)
end
def swiftformat_path
File.expand_path("bin/swiftformat", __dir__)
end
def swiftlint_path
File.expand_path("bin/swiftlint", __dir__)
end
def decrypt_secrets
Encrypted::Environment.load_from_ejson("secrets.ejson", private_key: ENV["SECRET_KEY"])
end
def release_scripts
bucket = storage.bucket("tuist-releases")
print_section("Uploading installation scripts to the tuist-releases bucket on GCS")
bucket.create_file("script/install", "scripts/install").acl.public!
bucket.create_file("script/uninstall", "scripts/uninstall").acl.public!
end
def package
print_section("Building tuist")
FileUtils.mkdir_p("build")
system("swift", "build", "--product", "tuist", "--configuration", "release")
system(
"swift", "build",
"--product", "ProjectDescription",
"--configuration", "release",
"-Xswiftc", "-enable-library-evolution",
"-Xswiftc", "-emit-module-interface",
"-Xswiftc", "-emit-module-interface-path",
"-Xswiftc", ".build/release/ProjectDescription.swiftinterface"
)
system("swift", "build", "--product", "tuistenv", "--configuration", "release")
build_templates_path = File.join(__dir__, ".build/release/Templates")
vendor_path = File.join(__dir__, ".build/release/vendor")
FileUtils.rm_rf(build_templates_path) if File.exist?(build_templates_path)
FileUtils.cp_r(File.expand_path("Templates", __dir__), build_templates_path)
FileUtils.cp_r(File.expand_path("vendor", __dir__), vendor_path)
File.delete("tuist.zip") if File.exist?("tuist.zip")
File.delete("tuistenv.zip") if File.exist?("tuistenv.zip")
Dir.chdir(".build/release") do
system(
"zip", "-q", "-r", "--symlinks",
"tuist.zip", "tuist",
"ProjectDescription.swiftmodule", "ProjectDescription.swiftdoc", "libProjectDescription.dylib", "ProjectDescription.swiftinterface",
"Templates",
"vendor"
)
system("zip", "-q", "-r", "--symlinks", "tuistenv.zip", "tuistenv")
end
FileUtils.cp(".build/release/tuist.zip", "build/tuist.zip")
FileUtils.cp(".build/release/tuistenv.zip", "build/tuistenv.zip")
end
def release(version)
if version == nil
version = cli.ask("Introduce the released version:")
end
puts "Releasing #{version} 🚀"
package
bucket = storage.bucket("tuist-releases")
print_section("Uploading to the tuist-releases bucket on GCS")
bucket.create_file("build/tuist.zip", "#{version}/tuist.zip").acl.public!
bucket.create_file("build/tuistenv.zip", "#{version}/tuistenv.zip").acl.public!
bucket.create_file("build/tuist.zip", "latest/tuist.zip").acl.public!
bucket.create_file("build/tuistenv.zip", "latest/tuistenv.zip").acl.public!
Dir.mktmpdir do |tmp_dir|
version_path = File.join(tmp_dir, "version")
File.write(version_path, version)
bucket.create_file(version_path, "latest/version").acl.public!
end
end
def system(*args)
Kernel.system(*args) || abort
end
def cli
@cli ||= HighLine.new
end
def storage
@storage ||= Google::Cloud::Storage.new(
project_id: ENV["GCS_PROJECT_ID"],
credentials: {
type: ENV["GCS_TYPE"],
project_id: ENV["GCS_PROJECT_ID"],
private_key_id: ENV["GCS_PRIVATE_KEY_ID"],
private_key: ENV["GCS_PRIVATE_KEY"],
client_email: ENV["GCS_CLIENT_EMAIL"],
client_id: ENV["GCS_CLIENT_ID"],
auth_uri: ENV["GCS_AUTH_URI"],
token_uri: ENV["GCS_TOKEN_URI"],
auth_provider_x509_cert_url: ENV["GCS_AUTH_PROVIDER_X509_CERT_URL"],
client_x509_cert_url: ENV["GCS_CLIENT_X509_CERT_URL"],
}
)
end
def print_section(text)
puts(text.bold.green)
end
def extract_zip(file, destination)
FileUtils.mkdir_p(destination)
Zip::File.open(file) do |zip_file|
zip_file.each do |f|
fpath = File.join(destination, f.name)
zip_file.extract(f, fpath) unless File.exist?(fpath)
end
end
end