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 1 commit
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 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
21 changes: 12 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,20 @@ WordPress/Images.xcassets/AppIcon-Internal.appiconset
/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
jkmassel marked this conversation as resolved.
Show resolved Hide resolved

# Generated Internal Icons
/WordPress/Resources/AppImages.xcassets/AppIcon-Internal.appiconset
/WordPress/Resources/Icons-Internal
Expand Down
18 changes: 13 additions & 5 deletions Scripts/extract-framework-translations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,30 @@
import Foundation

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

let base = cwd
let projectDir = base.appending("/WordPress")
let projectRoot = findProjectRoot()
let projectDir = projectRoot.appending("/WordPress")
AliSoftware marked this conversation as resolved.
Show resolved Hide resolved
let resources = projectDir.appending("/Resources")
let frameworkRoots = [
"WordPressTodayWidget",
"WordPressShareExtension"
].map({ projectDir.appending("/\($0)") })
].map({ projectDir.appending("/\($0)") })

guard fileManager.fileExists(atPath: projectDir) 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() -> String {
var candidate = URL(fileURLWithPath: fileManager.currentDirectoryPath)

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

return candidate.path
}

func projectLanguages() -> [String] {
return (try? fileManager.contentsOfDirectory(atPath: resources)
Expand Down
44 changes: 28 additions & 16 deletions Scripts/update-translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,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 +119,44 @@
langs = ALL_LANGS
end

script_root = __dir__
project_dir = File.dirname(script_root)

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

# 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"
destination = "#{lang_dir}/Localizable#{strings_file_ext}.strings"
backup_destination = "#{destination}.bak"

# Step 2 – Download the new strings
if File.exist? destination
FileUtils.copy destination, backup_destination
end

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

system "curl -fLso #{destination} \"#{url}\"" or begin
system "curl -fgLo #{destination} \"#{url}\"" or begin
jkmassel marked this conversation as resolved.
Show resolved Hide resolved
puts "Error downloading #{code}"
end

if File.size(destination).to_f == 0
abort("\e[31mFatal Error: #{destination} appears to be empty. Exiting.\e[0m")
# 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"
fix_script_path = File.join(script_root, 'fix-translation')

system "#{fix_script_path} #{lang_dir}/Localizable#{strings_file_ext}.strings"
system "plutil -lint #{lang_dir}/Localizable#{strings_file_ext}.strings"
AliSoftware marked this conversation as resolved.
Show resolved Hide resolved
system "grep -a '\\x00\\x20\\x00\\x22\\x00\\x22\\x00\\x3b$' #{lang_dir}/Localizable#{strings_file_ext}.strings"

# Clean up after ourselves
FileUtils.rm destination if File.exist? destination
Copy link
Contributor

Choose a reason for hiding this comment

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

[**] I'm not sure about this. I think this has been added to replace the call to system "rm #{lang_dir}/Localizable#{strings_file_ext}.strings.bak" which has been removed from above, right?

If so, I think we should add .bak to destination, otherwise it looks like to me that this will delete the strings files instead of the temporary backups.

Copy link
Contributor Author

@jkmassel jkmassel Feb 3, 2021

Choose a reason for hiding this comment

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

Resolved in 7f6cded!

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?
Loading