Skip to content

Commit a79527b

Browse files
committed
Fix lint job
- Before the migration to `git-crypt`, `WooCommerce/google-services.json` file did _not_ exist at all as we didn't run `configure_apply`. In which case the gradle task would take care of copying the `google-services.json-example` file in its place - Now that we migrated to `git-crypt`, the `WooCommerce/google-services.json` file _always_ exists in the repo, albeit encrypted if the repo was not git-crypt-unlocked after being cloned. So the logic had to be adjusted to copy the `google-services.json-example` file if the `google-services.json` file (which always exists now) is unreadable (aka encrypted)
1 parent 64af453 commit a79527b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

WooCommerce/build.gradle

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,13 @@ android.buildTypes.all { buildType ->
496496
}
497497

498498
// If Google services file doesn't exist, copy example file.
499-
if (!file("google-services.json").exists()) {
499+
def googleServicesFile = file("google-services.json")
500+
if (!googleServicesFile.exists() || !canReadPropertiesFile(googleServicesFile)) {
500501
tasks.copyGoogleServicesExampleFile.copy()
501502
}
502503

503504
// Print warning message if example Google services file is used.
504-
if ((file("google-services.json").text) == (file("google-services.json-example").text)) {
505+
if ((googleServicesFile.text) == (file("google-services.json-example").text)) {
505506
println("WARNING: You're using the example google-services.json file. Google login will fail.")
506507
}
507508
}
@@ -514,6 +515,16 @@ static def loadPropertiesFromFile(inputFile) {
514515
return properties
515516
}
516517

518+
static def canReadPropertiesFile(File file) {
519+
try {
520+
loadPropertiesFromFile(file)
521+
return true
522+
} catch (Exception e) {
523+
// Especially when the file is encrypted (git-crypt locked), the file will be unreadable.
524+
return false
525+
}
526+
}
527+
517528
def isLeakCanaryEnabled() {
518529
return developerProperties.get("enable_leak_canary") ?: true
519530
}

0 commit comments

Comments
 (0)