Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Fastlane to Project Root #15706

Merged
merged 26 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fc80c04
Move fastlane to the project root
jkmassel Jan 25, 2021
3397b7c
Update Tooling to use new paths
jkmassel Jan 30, 2021
b00b031
Fix translation builds
jkmassel Jan 30, 2021
71959eb
Pathing fix
jkmassel Feb 1, 2021
bb46c20
Use safe `system` calls
jkmassel Feb 1, 2021
32241c0
Ensure the PROJECT_ROOT_FOLDER is always correct
jkmassel Feb 1, 2021
868f344
Clean up `sh` usage
jkmassel Feb 1, 2021
42ad53a
Use proper path building for itc lane
jkmassel Feb 1, 2021
9ecb9f5
Better path safety in Swift, too
jkmassel Feb 1, 2021
38c660e
Ensure ENV[“PROJECT_ROOT”FOLDER”] is set
jkmassel Feb 2, 2021
7f6cded
Selectively delete translation files
jkmassel Feb 3, 2021
f090c57
Keep the output of `update-translations.rb` quiet
jkmassel Feb 3, 2021
b15122e
Align local output paths to the `Artifacts` dir
jkmassel Feb 3, 2021
bf2ccf6
Update .gitignore pathing
jkmassel Feb 3, 2021
6ba7874
Merge branch 'release/16.7' into move/fastlane
jkmassel Feb 8, 2021
99c53c1
Improve curl error handling
jkmassel Feb 11, 2021
9c5e87d
Explain the really strange escape sequence
jkmassel Feb 11, 2021
8efddd9
Fix parens
jkmassel Feb 11, 2021
d76a8e6
Remove promo screenshots
jkmassel Feb 11, 2021
d9e55ae
Delete files that should’ve been ignored
jkmassel Feb 11, 2021
e2f41e5
Remove fastlane-specific .gitignore file
jkmassel Feb 11, 2021
6848df3
Fix indentation weirdness
jkmassel Feb 11, 2021
821f074
More spacing fixes
jkmassel Feb 11, 2021
574dbe3
Another indentation fix
jkmassel Feb 11, 2021
911537f
Fix ruby error
jkmassel Feb 11, 2021
6f0d189
Don’t delete strings
jkmassel Feb 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 5 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
command: rake dependencies
- run:
name: Build for Testing
command: cd ./Scripts && bundle exec fastlane build_for_testing device:'<< parameters.device >>' ios-version:'<< parameters.ios-version >>'
command: bundle exec fastlane build_for_testing device:'<< parameters.device >>' ios-version:'<< parameters.ios-version >>'
- persist_to_workspace:
root: ./
paths:
Expand Down Expand Up @@ -94,7 +94,6 @@ jobs:
command: bundle --path vendor/bundle
- run:
name: Run Unit Tests
working_directory: Scripts
command: bundle exec fastlane test_without_building name:WordPressUnitTests try_count:3 device:'<< parameters.device >>' ios-version:'<< parameters.ios-version >>'
- ios/save-xcodebuild-artifacts:
result-bundle-path: build/results
Expand Down Expand Up @@ -127,7 +126,6 @@ jobs:
background: true
- run:
name: Run UI Tests
working_directory: Scripts
command: bundle exec fastlane test_without_building name:WordPressUITests try_count:3 device:'<< parameters.device >>' ios-version:'<< parameters.ios-version >>'
- ios/save-xcodebuild-artifacts:
result-bundle-path: build/results
Expand Down Expand Up @@ -161,13 +159,12 @@ jobs:
command: bundle exec fastlane run configure_apply
- run:
name: Build
working_directory: Scripts
command: "bundle exec fastlane build_and_upload_installable_build build_number:$CIRCLE_BUILD_NUM"
- run:
name: Prepare Artifacts
command: |
mkdir -p Artifacts
mv "Scripts/fastlane/comment.json" "Artifacts/comment.json"
mv "fastlane/comment.json" "Artifacts/comment.json"
- store_artifacts:
path: Artifacts
destination: Artifacts
Expand Down Expand Up @@ -199,7 +196,6 @@ jobs:
curl -sL https://sentry.io/get-cli/ | bash
- run:
name: Build
working_directory: Scripts
command: |
APP_VERSION=$(cat ../config/Version.Public.xcconfig | grep "^VERSION_LONG" | cut -d "=" -f2)
echo "export SLACK_FAILURE_MESSAGE=':red_circle: Build for WordPress iOS $APP_VERSION failed!'" >> $BASH_ENV
Expand Down Expand Up @@ -232,28 +228,20 @@ jobs:
- run:
name: Install other tools
command: |
brew unlink python@2
brew install imagemagick
brew install ghostscript
curl -sL https://sentry.io/get-cli/ | bash
- run:
name: Build
working_directory: Scripts
command: |
orig_version=`cat ../config/Version.internal.xcconfig | grep VERSION_SHORT | cut -d'=' -f2`
sed -i '' "$(awk '/^VERSION_SHORT/{ print NR; exit }' "../config/Version.internal.xcconfig")s/=.*/="${orig_version}"-`date +"%Y%d%m"`-"${CIRCLE_BUILD_NUM}"/" "../config/Version.internal.xcconfig"
bundle exec fastlane build_for_translation_review
orig_version=`cat config/Version.internal.xcconfig | grep VERSION_SHORT | cut -d'=' -f2`
sed -i '' "$(awk '/^VERSION_SHORT/{ print NR; exit }' "config/Version.internal.xcconfig")s/=.*/="${orig_version}"-`date +"%Y%d%m"`-"${CIRCLE_BUILD_NUM}"/" "config/Version.internal.xcconfig"
jkmassel marked this conversation as resolved.
Show resolved Hide resolved

VERSION_NAME="all-lang-build-${CIRCLE_BUILD_NUM}"
echo "export VERSION_NAME=$VERSION_NAME" >> $BASH_ENV

mkdir -p ../Artifacts
mv /var/tmp/Debug-iphonesimulator/WordPress.zip "../Artifacts/WordPress-${VERSION_NAME}.zip"
bundle exec fastlane build_for_translation_review version_name:$VERSION_NAME
no_output_timeout: 60m
- run:
name: Upload APP
command: |
curl --http1.1 https://${APPET_TOKEN}@api.appetize.io/v1/apps/${APPET_APPID} -F "file=@Artifacts/WordPress-${VERSION_NAME}.zip" -F "platform=ios"
- store_artifacts:
path: Artifacts
destination: Artifacts
Expand Down
30 changes: 16 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,29 @@ WordPress/Derived Sources/
WordPress/Images.xcassets/AppIcon-Internal.appiconset

# Bundler
/vendor/bundle/
.bundle/
.bundle

# Dependencies
/vendor/
vendor

# Fastlane
Scripts/fastlane/Preview.html
Scripts/fastlane/report.xml
Scripts/fastlane/README.md
Scripts/Preview.html
Scripts/fastlane/test_output/
Scripts/fastlane/google_cloud_keys.json
Scripts/fastlane/promo_screenshots
/Scripts/fastlane/metadata/review_information
/Scripts/default.profraw
fastlane/Preview.html
fastlane/report.xml
fastlane/README.md
Preview.html
fastlane/test_output/
jkmassel marked this conversation as resolved.
Show resolved Hide resolved
fastlane/google_cloud_keys.json
fastlane/promo_screenshots
jkmassel marked this conversation as resolved.
Show resolved Hide resolved
fastlane/metadata/review_information
default.profraw
derived-data/

# CI Artifacts Location
Artifacts

# Generated Internal Icons
/WordPress/Resources/AppImages.xcassets/AppIcon-Internal.appiconset
/WordPress/Resources/Icons-Internal
WordPress/Resources/AppImages.xcassets/AppIcon-Internal.appiconset
WordPress/Resources/Icons-Internal

# All secrets should be stored under .configure-files
# Everything without a .enc extension is ignored
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ source 'https://rubygems.org' do
gem 'commonmarker'
end

plugins_path = File.join(File.dirname(__FILE__), 'Scripts/fastlane', 'Pluginfile')
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ GEM
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3)
fastlane-plugin-appcenter (1.11.0)
fastlane-plugin-sentry (1.7.0)
fastlane-plugin-test_center (3.14.8)
fastlane-plugin-sentry (1.8.0)
fastlane-plugin-test_center (3.15.2)
colorize
json
plist
Expand Down Expand Up @@ -230,7 +230,7 @@ GEM
octokit (4.19.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
oj (3.10.18)
oj (3.11.1)
optimist (3.0.1)
options (2.3.2)
os (1.1.1)
Expand Down
26 changes: 17 additions & 9 deletions Scripts/extract-framework-translations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@
import Foundation

let fileManager = FileManager.default
let cwd = fileManager.currentDirectoryPath
let script = CommandLine.arguments[0]

let base = cwd
let projectDir = base.appending("/WordPress")
let resources = projectDir.appending("/Resources")
let projectRoot = findProjectRoot()
let projectDir = projectRoot.appendingPathComponent("WordPress")
let resources = projectDir.appendingPathComponent("Resources")
let frameworkRoots = [
"WordPressTodayWidget",
"WordPressShareExtension"
].map({ projectDir.appending("/\($0)") })
].map({ projectDir.appendingPathComponent($0).path })

guard fileManager.fileExists(atPath: projectDir) else {
guard fileManager.fileExists(atPath: projectDir.path) else {
print("Must run script from project root folder")
exit(1)
}

/// Crawl our way up the project tree until we find the root
func findProjectRoot() -> URL {
var candidate = URL(fileURLWithPath: fileManager.currentDirectoryPath)

while !fileManager.fileExists(atPath: candidate.appendingPathComponent(".git").path) && candidate.path != "/" {
candidate.deleteLastPathComponent()
}

return candidate
}

func projectLanguages() -> [String] {
return (try? fileManager.contentsOfDirectory(atPath: resources)
return (try? fileManager.contentsOfDirectory(atPath: resources.path)
.filter({ $0.hasSuffix(".lproj") })
.map({ $0.replacingOccurrences(of: ".lproj", with: "") })
.filter({ $0 != "en" })
Expand All @@ -45,7 +53,7 @@ func sourceStrings(framework: String) -> [String: String] {
}

func readProjectTranslations(for language: String) -> [String: String] {
let path = resources.appending("/\(language).lproj/Localizable.strings")
let path = resources.appendingPathComponent("\(language).lproj/Localizable.strings").path
return readStrings(path: path)
}

Expand Down
3 changes: 0 additions & 3 deletions Scripts/fastlane/.gitignore

This file was deleted.

58 changes: 38 additions & 20 deletions Scripts/update-translations.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
# encoding: utf-8

require 'fileutils'

# Supported languages:
# ar,ca,cs,cy,da,de,el,en,en-CA,en-GB,es,fi,fr,he,hr,hu,id,it,ja,ko,ms,nb,nl,pl,pt,pt-PT,ro,ru,sk,sv,th,tr,uk,vi,zh-Hans,zh-Hant
# * Arabic
Expand Down Expand Up @@ -40,11 +42,6 @@
# * Chinese (Taiwan) [zh-Hant]
# * Welsh

if Dir.pwd =~ /Scripts/
puts "Must run script from root folder"
exit
end

ALL_LANGS={
'ar' => 'ar', # Arabic
'bg' => 'bg', # Bulgarian
Expand Down Expand Up @@ -124,27 +121,48 @@
langs = ALL_LANGS
end

langs.each do |code,local|
lang_dir = File.join('WordPress', 'Resources', "#{local}.lproj")
puts "Updating #{code}"
system "mkdir -p #{lang_dir}"
script_root = __dir__
project_dir = File.dirname(script_root)

# Download for production
system "if [ -e #{lang_dir}/Localizable#{strings_file_ext}.strings ]; then cp #{lang_dir}/Localizable#{strings_file_ext}.strings #{lang_dir}/Localizable#{strings_file_ext}.strings.bak; fi"
langs.each do |code,local|
lang_dir = File.join(project_dir, 'WordPress', 'Resources', "#{local}.lproj")
puts "Updating #{code} in #{lang_dir}"
system "mkdir", "-p", lang_dir

url = "#{download_url}/#{code}/default/export-translations?#{strings_filter}format=strings"
destination = "#{lang_dir}/Localizable#{strings_file_ext}.strings"
backup_destination = "#{destination}.bak"

system "curl -fLso #{destination} \"#{url}\"" or begin
puts "Error downloading #{code}"
# Step 2 – Download the new strings
if File.exist? destination
FileUtils.copy destination, backup_destination
end

if File.size(destination).to_f == 0
abort("\e[31mFatal Error: #{destination} appears to be empty. Exiting.\e[0m")
url = "#{download_url}/#{code}/default/export-translations?#{strings_filter}format=strings"

system("curl", "-fgsLo", destination, url) or raise "Error downloading #{url}"

# Step 3 – Validate the new file
if !File.exist?(destination) or File.size(destination).to_f == 0
puts "\e[31mFatal Error: #{destination} appears to be empty. Exiting.\e[0m"
abort()
end

system "./Scripts/fix-translation #{lang_dir}/Localizable#{strings_file_ext}.strings"
system "plutil -lint #{lang_dir}/Localizable#{strings_file_ext}.strings" and system "rm #{lang_dir}/Localizable#{strings_file_ext}.strings.bak"
system "grep -a '\\x00\\x20\\x00\\x22\\x00\\x22\\x00\\x3b$' #{lang_dir}/Localizable#{strings_file_ext}.strings"
fix_script_path = File.join(script_root, 'fix-translation')

# References a file like: "#{lang_dir}.Localizable-old.strings" where strings_file_ext == "old"
strings_file_path = File.join(lang_dir, "Localizable#{strings_file_ext}.strings")

system fix_script_path, strings_file_path
system "plutil", "-lint", strings_file_path
# The fix-translations script is supposed to have replaced all strings with empty translations, to use the key (aka English copy)
# as the translation instead, as a fallback. So after that pass we should not have any more empty translations left,
# but just as a control, let's grep for lines ending with the UTF-16 sequence ` "";` to ensure there's none left.
system "grep", "-a", "\\x00\\x20\\x00\\x22\\x00\\x22\\x00\\x3b$", strings_file_path
jkmassel marked this conversation as resolved.
Show resolved Hide resolved

# Clean up after ourselves
FileUtils.rm_f backup_destination
end
system "Scripts/extract-framework-translations.swift" if strings_filter.empty?

extract_framework_translations_script_path = File.join(script_root, 'extract-framework-translations.swift')

system extract_framework_translations_script_path if strings_filter.empty?
File renamed without changes.
Loading