Skip to content

Commit 0509840

Browse files
committed
fix lint job vs google-services.json-example
- 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), the logic to decide when to copy the `google-services.json-example` file had to be adjusted - Also updated the `README.md` accordingly—to suggest external contributors to copy the example file
1 parent 64af453 commit 0509840

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141
1. If you are a developer at Automattic:
4242
1. Make sure you have `git-crypt` installed (`brew install git-crypt`)
4343
1. Search for "WooCommerce Android git-crypt encryption key" in our Secret Store, and copy the Base64 value in your clipboard
44-
1. Run `git-crypt unlock <(pbpaste | base64 -d)` to decrypt the encrypted files (including `secrets.properties`)
44+
1. Run `git-crypt unlock <(pbpaste | base64 -d)` to decrypt the encrypted files (including `secrets.properties` and `WooCommerce/google-services.json`)
4545
1. If you are an external contributor:
4646
1. Generate developer OAuth2 tokens. See the [OAuth2 Authentication](docs/project-overview.md#oauth2-authentication) section for details.
4747
1. Edit `defaults.properties` and adjust the values as needed—especiallyincluding `wp.oauth.*` ones. See the [Configuration Files](docs/project-overview.md#configuration-files) section for a breakdown of the properties.
48+
1. `cp WooCommerce/google-services.json-example WooCommerce/google-services.json` (to replace that encrypted file with placeholder content)
4849
1. In Android Studio, open the project from the local repository. This will auto-generate `local.properties` with the SDK location.
4950
1. Optional: Go to Tools → Device Manager and create an emulated device.
5051
1. Run. (Creates a default virtual device if you skipped the previous step)

WooCommerce/build.gradle

Lines changed: 10 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() || isFileEncrypted(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,13 @@ static def loadPropertiesFromFile(inputFile) {
514515
return properties
515516
}
516517

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

0 commit comments

Comments
 (0)