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

Fastlane: Finalize Release #612

Merged
merged 13 commits into from Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/Version.public.xcconfig
@@ -1,5 +1,5 @@
VERSION_SHORT=1.12.0
VERSION_SHORT=2.00
jleandroperez marked this conversation as resolved.
Show resolved Hide resolved

// Public long version example: 1_12_0_1. The last 1 means the first build for
// Public long version example: 2.0.0.1. The last 1 means the first build for
// this version
VERSION_LONG=11202
VERSION_LONG=2.00.0.0
jleandroperez marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions fastlane/Fastfile
Expand Up @@ -9,6 +9,7 @@ ENV[GHHELPER_REPO="Automattic/simplenote-macos"]
ENV["PROJECT_NAME"]="Simplenote"
ENV["PROJECT_ROOT_FOLDER"]="./"
ENV["PUBLIC_CONFIG_FILE"]="./config/Version.Public.xcconfig"
ENV["DOWNLOAD_METADATA"]="./fastlane/download_metadata.swift"

USER_ENV_FILE_PATH = File.join(Dir.home, '.simplenotemacos-env.default')

Expand Down Expand Up @@ -145,6 +146,7 @@ end
desc "Removes all the temp tags and puts the final one"
lane :finalize_release do | options |
ios_finalize_prechecks(options)
ios_update_metadata(options) unless ios_current_branch_is_hotfix
ios_final_tag(options)
end

Expand Down
129 changes: 129 additions & 0 deletions fastlane/download_metadata.swift
@@ -0,0 +1,129 @@
#!/usr/bin/env swift

import Foundation

let glotPressSubtitleKey = "app_store_subtitle"
let glotPressWhatsNewKey = "v1.12-whats-new"
let glotPressDescriptionKey = "app_store_desc"
let glotPressKeywordsKey = "app_store_keywords"
let baseFolder = "./metadata"

// iTunes Connect language code: GlotPress code
let languages = [
"de-DE": "de",
"default": "en-us", // Technically not a real GlotPress language
"en-US": "en-us", // Technically not a real GlotPress language
"es-ES": "es",
"fr-FR": "fr",
"id": "id",
"it": "it",
"ja": "ja",
"ko": "ko",
"nl-NL": "nl",
"pt-BR": "pt-br",
"ru": "ru",
"sv": "sv",
"tr": "tr",
"zh-Hans": "zh-cn",
"zh-Hant": "zh-tw",
]

func downloadTranslation(languageCode: String, folderName: String) {
let languageCodeOverride = languageCode == "en-us" ? "es" : languageCode
let glotPressURL = "https://translate.wordpress.com/projects/simplenote%2Fmacos%2Frelease-notes/\(languageCodeOverride)/default/export-translations?format=json"
let requestURL: URL = URL(string: glotPressURL)!
let urlRequest: URLRequest = URLRequest(url: requestURL)
let session = URLSession.shared

let sema = DispatchSemaphore( value: 0)

print("Downloading Language: \(languageCode)")

let task = session.dataTask(with: urlRequest) {
(data, response, error) -> Void in

defer {
sema.signal()
}

guard let data = data else {
print(" Invalid data downloaded.")
return
}

guard let json = try? JSONSerialization.jsonObject(with: data, options: []),
let jsonDict = json as? [String: Any] else {
print(" JSON was not returned")
return
}

var subtitle: String?
var whatsNew: String?
var keywords: String?
var storeDescription: String?

jsonDict.forEach({ (key: String, value: Any) in

guard let index = key.firstIndex(of: Character(UnicodeScalar(0004))) else {
jleandroperez marked this conversation as resolved.
Show resolved Hide resolved
return
}

let keyFirstPart = String(key[..<index])

guard let value = value as? [String],
let firstValue = value.first else {
print(" No translation for \(keyFirstPart)")
return
}

var originalLanguage = String(key[index...])
originalLanguage.remove(at: originalLanguage.startIndex)
let translation = languageCode == "en-us" ? originalLanguage : firstValue

switch keyFirstPart {
case glotPressSubtitleKey:
subtitle = translation
case glotPressKeywordsKey:
keywords = translation
case glotPressWhatsNewKey:
whatsNew = translation
case glotPressDescriptionKey:
storeDescription = translation
default:
print(" Unknown key: \(keyFirstPart)")
}
})

let languageFolder = "\(baseFolder)/\(folderName)"

let fileManager = FileManager.default
try? fileManager.createDirectory(atPath: languageFolder, withIntermediateDirectories: true, attributes: nil)

do {
try subtitle?.write(toFile: "\(languageFolder)/promotional_text.txt", atomically: true, encoding: .utf8)
try whatsNew?.write(toFile: "\(languageFolder)/release_notes.txt", atomically: true, encoding: .utf8)
try keywords?.write(toFile: "\(languageFolder)/keywords.txt", atomically: true, encoding: .utf8)
try storeDescription?.write(toFile: "\(languageFolder)/description.txt", atomically: true, encoding: .utf8)
} catch {
print(" Error writing: \(error)")
}
}

task.resume()
sema.wait()
}

func deleteExistingMetadata() {
let fileManager = FileManager.default
let url = URL(fileURLWithPath: baseFolder, isDirectory: true)
try? fileManager.removeItem(at: url)
try? fileManager.createDirectory(at: url, withIntermediateDirectories: false)
}


deleteExistingMetadata()

languages.forEach( { (key: String, value: String) in
downloadTranslation(languageCode: value, folderName: key)
})