Skip to content

Commit be5c217

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 encrypted
1 parent 64af453 commit be5c217

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

WooCommerce/build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,14 @@ 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() || isFileEncrypted(googleServicesFile)) {
501+
println("WARNING: Copying google-services.json-example file.")
500502
tasks.copyGoogleServicesExampleFile.copy()
501503
}
502504

503505
// Print warning message if example Google services file is used.
504-
if ((file("google-services.json").text) == (file("google-services.json-example").text)) {
506+
if ((googleServicesFile.text) == (file("google-services.json-example").text)) {
505507
println("WARNING: You're using the example google-services.json file. Google login will fail.")
506508
}
507509
}
@@ -514,6 +516,13 @@ static def loadPropertiesFromFile(inputFile) {
514516
return properties
515517
}
516518

519+
static def isFileEncrypted(File file) {
520+
def gitcryptHeader = [0x00, 0x47, 0x49, 0x54, 0x43, 0x52, 0x59, 0x50, 0x54] as byte[] // GITCRYPT header
521+
def header = new byte[gitcryptHeader.length]
522+
file.withInputStream { stream -> stream.read(header) }
523+
return Arrays.equals(header, gitcryptHeader)
524+
}
525+
517526
def isLeakCanaryEnabled() {
518527
return developerProperties.get("enable_leak_canary") ?: true
519528
}

0 commit comments

Comments
 (0)