Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might add a default help target to improve discoverability.

diff --git a/Makefile b/Makefile
index ec8f8b3bec..3539ae12d1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,7 @@
-.PHONY: dependencies
+.PHONY: help dependencies
 
-dependencies:
+help: ## Show available targets
+	@grep -E '^[a-zA-Z_-]+:.*##' $(MAKEFILE_LIST) | awk -F ':.*## ' '{printf "  %-20s %s\n", $$1, $$2}'
+
+dependencies: ## Download and cache Gutenberg XCFrameworks
 	./Scripts/download-gutenberg-xcframeworks.sh

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: dependencies

dependencies:
./Scripts/download-gutenberg-xcframeworks.sh
53 changes: 1 addition & 52 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ require 'tmpdir'
require 'rake/clean'
require 'yaml'
require 'digest'
require 'open-uri'
require 'rubygems/package'
require 'zlib'

RUBY_REPO_VERSION = File.read('./.ruby-version').rstrip
XCODE_WORKSPACE = 'WordPress.xcworkspace'
EXPECTED_XCODE_VERSION = File.read('.xcode-version').rstrip
GUTENBERG_VERSION = 'v1.121.0'

PROJECT_DIR = __dir__
abort('Project directory contains one or more spaces – unable to continue.') if PROJECT_DIR.include?(' ')

Expand Down Expand Up @@ -101,53 +96,7 @@ bundle exec fastlane run configure_apply force:true

desc 'Download and extract Gutenberg xcframeworks'
task :gutenberg_xcframeworks do
puts 'Setting up Gutenberg xcframeworks...'

frameworks_dir = 'WordPress/Frameworks'

# Clean the slate
FileUtils.rm_rf(frameworks_dir)
FileUtils.mkdir_p(frameworks_dir)

gutenberg_tar_gz_download_path = "#{frameworks_dir}/Gutenberg.tar.gz"

URI.open("https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-#{GUTENBERG_VERSION}.tar.gz") do |remote_file|
File.binwrite(gutenberg_tar_gz_download_path, remote_file.read)
end

# Extract the archive
Zlib::GzipReader.open(gutenberg_tar_gz_download_path) do |gz|
Gem::Package::TarReader.new(gz) do |tar|
tar.each do |entry|
next unless entry.file?

dest_path = File.join(frameworks_dir, entry.full_name)
FileUtils.mkdir_p(File.dirname(dest_path))

File.binwrite(dest_path, entry.read)
end
end
end

# Move xcframeworks to the correct location
Dir.glob("#{frameworks_dir}/Frameworks/*.xcframework").each do |framework|
FileUtils.mv(framework, frameworks_dir, force: false)
end

# Create dSYMs directories
FileUtils.mkdir_p [
"#{frameworks_dir}/hermes.xcframework/ios-arm64/dSYMs",
"#{frameworks_dir}/hermes.xcframework/ios-arm64_x86_64-simulator/dSYMs"
]

# Cleanup
FileUtils.rm_rf [
gutenberg_tar_gz_download_path,
"#{frameworks_dir}/Frameworks",
"#{frameworks_dir}/dummy.txt"
]

puts 'Gutenberg xcframeworks setup complete'
sh("#{PROJECT_DIR}/Scripts/download-gutenberg-xcframeworks.sh")
end
end

Expand Down
53 changes: 53 additions & 0 deletions Scripts/download-gutenberg-xcframeworks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -euo pipefail
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Apps Infra recently started moving toward a more portable shebang

Suggested change
#!/bin/bash
set -euo pipefail
#!/usr/bin/env bash
set -euo pipefail


# Downloads and installs Gutenberg XCFrameworks with progress and on-disk caching.
#
# Usage: download-gutenberg-xcframeworks.sh [frameworks_dir]
# frameworks_dir defaults to WordPress/Frameworks

VERSION="v1.121.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of making the version an input with fallback, too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... maybe we would be better served by extracting the version in a dedicated file? It's currently duplicated.

➜ g grep v1.121.0
Rakefile:GUTENBERG_VERSION = 'v1.121.0'
fastlane/lanes/localization.rb:GUTENBERG_TAG = 'v1.121.0'

FRAMEWORKS_DIR="${1:-WordPress/Frameworks}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick.

I love that this is can be changed at call time. Nice UX. But neither rake nor make leverages this capability.

Did you consider exposing it? If not, is there value in having it configurable here?

FWIW, I think this is not an issue and we shouldn't get distracted with exposing the config. But maybe there's a good use case for it that I'm not aware of, so I thought I'd call it out.


CACHE_DIR="${HOME}/Library/Caches/WordPress-iOS/Gutenberg/${VERSION}"
DOWNLOAD_URL="https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-${VERSION}.tar.gz"

# Download and extract into the cache if this version isn't cached yet.
if [[ -d "${CACHE_DIR}" ]]; then
echo "Using cached Gutenberg ${VERSION}"
else
echo "Downloading Gutenberg ${VERSION}..."

# Extract into a temp directory first so a partial download doesn't
# leave a corrupt cache that persists across runs.
mkdir -p "$(dirname "${CACHE_DIR}")"
TEMP_DIR="$(mktemp -d "${CACHE_DIR}.XXXXXX")"
trap 'rm -rf "${TEMP_DIR}"' EXIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about trap. Cool!


curl --fail --location --progress-bar "${DOWNLOAD_URL}" \
| tar xzf - -C "${TEMP_DIR}"

# Move contents up from the nested Frameworks/ directory.
if [[ -d "${TEMP_DIR}/Frameworks" ]]; then
mv "${TEMP_DIR}"/Frameworks/* "${TEMP_DIR}/"
rm -rf "${TEMP_DIR}/Frameworks"
fi

# Create dSYMs directories that Xcode expects for hermes.
mkdir -p \
"${TEMP_DIR}/hermes.xcframework/ios-arm64/dSYMs" \
"${TEMP_DIR}/hermes.xcframework/ios-arm64_x86_64-simulator/dSYMs"

# Clean up leftover files from the archive.
rm -f "${TEMP_DIR}/dummy.txt"

# Atomically promote the temp directory to the final cache path.
mv "${TEMP_DIR}" "${CACHE_DIR}"
trap - EXIT
fi

# Copy cached contents into the project.
rm -rf "${FRAMEWORKS_DIR}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The likelihood of someone mistakenly passing / as an argument feels quite low, but given the severe repercussions of doing so, it may be worth guarding as Claude suggested. 😅

Suggested change
rm -rf "${FRAMEWORKS_DIR}"
if [[ -z "${FRAMEWORKS_DIR}" || "${FRAMEWORKS_DIR}" == "/" ]]; then
echo "Error: invalid frameworks directory: '${FRAMEWORKS_DIR}'" >&2
exit 1
fi

cp -a "${CACHE_DIR}" "${FRAMEWORKS_DIR}"

echo "Gutenberg ${VERSION} setup complete."