diff --git a/Gemfile b/Gemfile index 997a685009bf..1578b735fe6f 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source 'https://rubygems.org' +gem 'archive-tar-minitar' gem 'cocoapods', '~> 1.11' gem 'commonmarker' gem 'danger', '~> 9.3' diff --git a/Gemfile.lock b/Gemfile.lock index f4afd7aee948..da1919518d79 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,6 +13,9 @@ GEM algoliasearch (1.27.5) httpclient (~> 2.8, >= 2.8.3) json (>= 1.5.1) + archive-tar-minitar (0.8) + minitar (~> 0.8) + minitar-cli (~> 0.8) artifactory (3.0.15) ast (2.4.2) atomos (0.1.3) @@ -247,6 +250,7 @@ GEM multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) + hashie (5.0.0) highline (2.0.3) http-cookie (1.0.5) domain_name (~> 0.5) @@ -264,6 +268,10 @@ GEM mini_magick (4.12.0) mini_mime (1.1.2) mini_portile2 (2.8.2) + minitar (0.8) + minitar-cli (0.8) + minitar (~> 0.8.0) + powerbar (~> 1.0) minitest (5.18.0) molinillo (0.8.0) multi_json (1.15.0) @@ -287,6 +295,8 @@ GEM parser (3.1.2.0) ast (~> 2.4.1) plist (3.7.0) + powerbar (1.0.18) + hashie (>= 1.1.0) progress_bar (1.3.3) highline (>= 1.6, < 3) options (~> 2.3.0) @@ -369,6 +379,7 @@ PLATFORMS ruby DEPENDENCIES + archive-tar-minitar cocoapods (~> 1.11) commonmarker danger (~> 9.3) diff --git a/Gutenberg/.gitignore b/Gutenberg/.gitignore new file mode 100644 index 000000000000..594d7272608b --- /dev/null +++ b/Gutenberg/.gitignore @@ -0,0 +1,4 @@ +# These are the folders where our bespoke automatation downloads and unpacks the XCFrameworks archives. +# Ideally, CocoaPods should do this, but for some reason I haven't yet been able to make it work. +.downloads +.artifacts/ diff --git a/Gutenberg/Gutenberg.podspec b/Gutenberg/Gutenberg.podspec index d6719f94fbb3..6562fdf32567 100644 --- a/Gutenberg/Gutenberg.podspec +++ b/Gutenberg/Gutenberg.podspec @@ -30,19 +30,24 @@ Pod::Spec.new do |s| s.authors = 'Automattic' s.ios.deployment_target = '13.0' # TODO: Read from common source - s.swift_version = '5.0' # TODO: read from common source + s.swift_version = '5.7' # TODO: read from common source s.requires_arc = true # TODO: Can this be omitted? # Tell CocoaPods where to download the XCFramework(s) archive with `source` and what to use from its decompressed contents with `vendored_frameworks`. # # See https://github.com/CocoaPods/CocoaPods/issues/10288 - s.source = { http: xcframework_archive_url } + # + # I thought I got this to work, but it was just that I inadvertenly put the frameworks in the current folder, so that worked... + # + # Next step I guess is try to find out where CP unpacks shit and see why mine isn't found... + # s.source = { http: xcframework_archive_url } + s.source = { http: "file://#{__dir__}/.downloads/Gutenberg-#{gutenberg_version}.tar.gz" } s.vendored_frameworks = [ 'Aztec.xcframework', 'Gutenberg.xcframework', 'React.xcframework', 'RNTAztecView.xcframework', 'yoga.xcframework' - ].map { |f| "Gutenberg/#{f}" } # prefix with the name of the folder generated when unarchiving + ].map { |f| ".artifacts/Frameworks/#{f}" } # prefix with the name of the folder generated when unarchiving end diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb index 7a57c87b00f3..93cd6048afe9 100644 --- a/Gutenberg/cocoapods_helpers.rb +++ b/Gutenberg/cocoapods_helpers.rb @@ -1,5 +1,14 @@ # frozen_string_literal: true +require 'net/http' +require 'zlib' +require 'archive/tar/minitar' +require 'uri' +require 'ruby-progressbar' + +# rubocop:disable Metrics/AbcSize +# rubocop:disable Metrics/MethodLength + # Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods. require_relative './version' @@ -59,7 +68,6 @@ React-bridging ].freeze -# rubocop:disable Metrics/AbcSize def gutenberg_pod(config: GUTENBERG_CONFIG) options = config @@ -87,7 +95,6 @@ def gutenberg_pod(config: GUTENBERG_CONFIG) pod 'Gutenberg', path: File.join(__dir__, 'gutenberg.podspec') end end -# rubocop:enable Metrics/AbcSize def gutenberg_dependencies(options:) if options[:path] @@ -111,3 +118,70 @@ def gutenberg_dependencies(options:) pod pod_name, podspec: "#{podspec_prefix}/#{pod_name}.#{podspec_extension}" end end + +def archive_url(commit:) + xcframework_storage_url = 'https://d2twmm2nzpx3bg.cloudfront.net' + "#{xcframework_storage_url}/Gutenberg-#{commit}.tar.gz" +end + +def gutenberg_pre_install_hook + # FIXME: Automatically switch between commit and tag outside this method + url = archive_url(commit: GUTENBERG_CONFIG[:commit]) + archive_name = File.basename(url) + archive_folder = File.join(__dir__, '.downloads') + archive_path = File.join(archive_folder, archive_name) + + if File.exist?(archive_path) + puts "Skipping download because archive for #{url} exists already at #{archive_path}." + else + puts "Will attempt downloading #{url} to #{archive_name}..." + + FileUtils.mkdir_p(archive_folder) + + # Perform HTTP HEAD request to retrieve file size + uri = URI.parse(url) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true + response = http.head(uri.path) + + # Check if the response is successful and contains Content-Length header + raise "Failed to retrieve file information: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess) && response.key?('Content-Length') + + file_size = response['Content-Length'].to_i + + # Check file size + raise 'File size is 0. Aborting download.' if file_size.zero? + + puts "File size: #{(file_size / (1024.0 * 1024.0)).round(2)} MB" + + progress_bar = ProgressBar.create(title: 'Download', total: file_size, format: '%t |%B| %p%%') + + http.request_get(uri.path) do |archive_response| + File.open(archive_path, 'wb') do |file| + archive_response.read_body do |chunk| + file.write(chunk) + progress_bar.progress += chunk.length + end + end + end + + progress_bar.finish + + puts 'Done downloading' + end + + archive_extraction_folder = File.join(__dir__, '.artifacts') + + FileUtils.rm_rf(archive_extraction_folder) + FileUtils.mkdir_p(archive_extraction_folder) + + puts "Extracting #{archive_name} to #{archive_extraction_folder}..." + + Zlib::GzipReader.open(archive_path) do |gzip_file| + Archive::Tar::Minitar.unpack(gzip_file, archive_extraction_folder) + end + + puts 'Finished extracting.' +end +# rubocop:enable Metrics/AbcSize +# rubocop:enable Metrics/MethodLength diff --git a/Podfile b/Podfile index 6db0110d08fc..5c63de085d6c 100644 --- a/Podfile +++ b/Podfile @@ -336,6 +336,8 @@ pre_install do |installer| end puts "Installing #{static.count} pods as static frameworks" puts "Installing #{dynamic.count} pods as dynamic frameworks" + + gutenberg_pre_install_hook end post_install do |installer|