forked from SwiftGen/SwiftGenPlugin
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Rakefile
executable file
·51 lines (38 loc) · 1.49 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
#!/usr/bin/rake
# frozen_string_literal: true
require 'English'
require 'open-uri'
require 'tempfile'
unless defined?(Bundler)
puts 'Please use bundle exec to run the rake command'
exit 1
end
## [ Constants ] ##############################################################
MIN_XCODE_VERSION = 13.0
BUILD_DIR = File.absolute_path('./.build')
## [ Build Tasks ] ############################################################
namespace :spm do
desc "Update SwiftGen in Package.swift"
task :update_swiftgen, [:version] do |task, args|
require 'octokit'
client = Utils.octokit_client
release = client.latest_release('SwiftGen/SwiftGen')
asset = release.assets.find { |a| a.name.end_with? '.artifactbundle.zip' }
raise 'Release asset not found' if asset.nil?
# download bundle
puts 'Downloading artifact bundle…'
artifactBundle = Tempfile.new(['artifactbundle', '.zip'])
artifactBundle << URI::open(asset.browser_download_url).read
# calculate checksum
puts 'Checksumming…'
checksum = Utils::run("swift package compute-checksum #{artifactBundle.path}", task, formatter: :to_string).strip
# update package file
puts 'Updating `Package.swift`…'
package = File.read('Package.swift')
package.sub!(/https:\/\/.+\.artifactbundle\.zip/, asset.browser_download_url)
package.sub!(/checksum: "\w+"/, "checksum: \"#{checksum}\"")
File.write('Package.swift', package)
Utils::print_info 'Done!'
end
end
task :default => 'spm:test_command'