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

Use gradle configure plugin #3661

Closed
wants to merge 3 commits into from
Closed

Use gradle configure plugin #3661

wants to merge 3 commits into from

Conversation

jkmassel
Copy link
Contributor

@jkmassel jkmassel commented Mar 4, 2021

This PR uses the gradle configure plugin instead of bundler, which should remove the need for a ruby toolchain for day-to-day development of WCAndroid.

To Test:

  • Ensure all CI things pass
  • Check out the repo from scratch, then switch to this branch. Run ./gradlew applyConfiguration. Note that it fails with the error "Build configuration file gradle.properties doesn't exist, follow README instructions". Copy gradle.properties-example to gradle.properties, then run ./gradlew applyConfiguration. This should replace the default values with the proper ones.

Note: @oguzkocer and I discussed having a more automatic solution that doesn't require duplicating the template file, but there are a lot of technical hurdles to overcome there, so for now this is likely the simplest solution for both OSS and internal contributors.

Update release notes:

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@jkmassel jkmassel added the category: tooling Anything that involves building & maintaining the project, including scripts, `Fastfile`, etc. label Mar 4, 2021
@jkmassel jkmassel added this to the 6.2 milestone Mar 4, 2021
@jkmassel jkmassel self-assigned this Mar 4, 2021
@jkmassel jkmassel force-pushed the use/binary-configure branch 5 times, most recently from f7a11f2 to 472b9ff Compare March 5, 2021 06:38
@peril-woocommerce
Copy link

peril-woocommerce bot commented Mar 5, 2021

You can test the changes on this Pull Request by downloading the APK here.

Copy link
Contributor

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

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

Did not actually test this yet (did not checkout and run the task, only reviewed the diff on github), but posting my initial feedback anyway

@@ -1,45 +1,35 @@
{
"project_name": "woocommerce-android",
"project_name": "wc-android",
Copy link
Contributor

Choose a reason for hiding this comment

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

I have to admit I don't know what this key is used for in the configure tooling… but why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This key defines which encryption key from keys.json to use – it needs to be changed here in order to avoid breaking mobile secrets while I do this work.

At some point after this PR lands (once any branches using the old project_name land, we can roll it back to the proper name if we like

.configure Show resolved Hide resolved
.gitignore Show resolved Hide resolved
secrets.properties-example Outdated Show resolved Hide resolved
WooCommerce/build.gradle Outdated Show resolved Hide resolved
WooCommerce/build.gradle Outdated Show resolved Hide resolved
@jkmassel jkmassel force-pushed the use/binary-configure branch 4 times, most recently from cb7a7cf to 697c47b Compare March 5, 2021 20:12
@jkmassel jkmassel marked this pull request as ready for review March 5, 2021 20:35
@jkmassel jkmassel requested review from oguzkocer and loremattei March 5, 2021 20:55
@jkmassel jkmassel force-pushed the use/binary-configure branch from b804587 to 75a7c88 Compare March 5, 2021 22:01
@jkmassel jkmassel changed the title Use Gradle Configuration Use gradle configure plugin Mar 6, 2021
Copy link
Contributor

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

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

Tried this today and on the first try I was able to make rust be "panicked"…

10:56:58 [DEBUG] (1) configure::fs: Reading keys from "/Users/olivier/.mobile-secrets/keys.json"
thread 'main' panicked at 'Unable to decrypt and copy files: MissingProjectKey', src/configure.rs:193:53
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I quickly figured that this was due to my mobile-secrets not being up-to-date and not having pulled the latest keys (though a more explicit error message could have been nice), so doing a git pull in ~/.mobile-secrets then re-trying finally made the task pass…

But then when I looked at .configure-files, only one file (upload.jks) were un-encrypted, all the other files were .enc files (despite the logs saying that it stored other decrypted files during the process). So seems like it didn't work all the way?

$ ls -l .configure-files
total 64
-rw-r--r--  1 olivier  staff  2144 Mar  8 11:47 automattic_upload.jks.enc
-rw-r--r--  1 olivier  staff  1264 Mar  8 11:47 debug.keystore.enc
-rw-r--r--  1 olivier  staff  3903 Mar  8 11:48 google-services.json.enc
-rw-r--r--  1 olivier  staff  2402 Mar  8 11:48 google-upload-credentials.json.enc
-rw-r--r--  1 olivier  staff  2123 Mar  8 11:48 gradle.properties.enc
-rw-r--r--  1 olivier  staff   170 Mar  8 11:48 sentry.properties.enc
-rw-r--r--  1 olivier  staff  2142 Mar  8 12:02 upload.jks
-rw-r--r--  1 olivier  staff  2182 Mar  8 11:48 upload.jks.enc

I also think it could be nice to improve a couple of things here:

  1. Probably reduce the verbosity of the output, as it's printing a lot of [DEBUG] (1) configure:… lines when running that could make it a bit scary for end-users. Maybe only print those debug lines if DEBUG=1 env var is set or something like that?
  2. Would be very nice to have a better error message when the decryption key is not found, to suggest users to update their mobile-secrets repo and retry.

Log Details

Step 1: Fresh clone the repo.
$ git clone git@github.com:woocommerce/woocommerce-android.git woocommerce-android-clean
…
$ cd woocommerce-android-clean 
$ git checkout use/binary-configure 
Step 2: ./gradlew applyConfiguration fail as expected.
$ ./gradlew applyConfiguration
Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :
Copying git-hooks scripts from tools/team-props/git-hooks to .git/hooks
Checking whether `configure` binary is present
Downloading `configure` binary
Detected current OS: macos
Detected plugin version: 0.5.0
200
OK

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/olivier/Documents/Dev/woocommerce-android-clean/WooCommerce/build.gradle' line: 347

* What went wrong:
A problem occurred evaluating project ':WooCommerce'.
> Build configuration file gradle.properties doesn't exist, follow README instructions

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Step 3: Creating gradle.properties then re-running applyConfiguration: panic!
$ cp gradle.properties-example gradle.properties         
$ ./gradlew applyConfiguration                  
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

> Configure project :
Copying git-hooks scripts from tools/team-props/git-hooks to .git/hooks

> Configure project :WooCommerce
WARNING: You're using the example google-services.json file. Google login will fail.
WARNING: You're using the example google-services.json file. Google login will fail.
Could not find google-services.json while looking in [src/wasabi/debug, src/debug/wasabi, src/wasabi, src/debug, src/wasabiDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/jalapeno/debug, src/debug/jalapeno, src/jalapeno, src/debug, src/jalapenoDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/vanilla/debug, src/debug/vanilla, src/vanilla, src/debug, src/vanillaDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/wasabi/release, src/release/wasabi, src/wasabi, src/release, src/wasabiRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/jalapeno/release, src/release/jalapeno, src/jalapeno, src/release, src/jalapenoRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/vanilla/release, src/release/vanilla, src/vanilla, src/release, src/vanillaRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
WARNING: API 'variant.getMappingFile()' is obsolete and has been replaced with 'variant.getMappingFileProvider()'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getMappingFile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.

> Configure project :
Checking whether `configure` binary is present

> Task :applyConfiguration FAILED
10:56:58 [DEBUG] (1) configure: libconfigure initialized
10:56:58 [DEBUG] (1) configure: libConfigure initializing encryption
10:56:58 [DEBUG] (1) configure: libConfigure encryption initialization successful
10:56:58 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
10:56:58 [DEBUG] (1) configure::fs: Configure file found at: "/Users/olivier/Documents/Dev/woocommerce-android-clean/.configure"
10:56:58 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
10:56:58 [DEBUG] (1) configure::fs: Keys file found at: "/Users/olivier/.mobile-secrets/keys.json"
10:56:58 [DEBUG] (1) configure::fs: Reading keys from "/Users/olivier/.mobile-secrets/keys.json"
thread 'main' panicked at 'Unable to decrypt and copy files: MissingProjectKey', src/configure.rs:193:53
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':applyConfiguration'.
> Process 'command '/Users/olivier/Documents/Dev/woocommerce-android-clean/vendor/configure/configure'' finished with non-zero exit value 101

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s
1 actionable task: 1 executed
Step 4: Updating ~/mobile-secrets and re-running applyConfiguration: task succeeds...
$ cd ~/.mobile-secrets
$ git pull
…
$ cd -
$ ./gradlew applyConfiguration

> Configure project :WooCommerce
WARNING: You're using the example google-services.json file. Google login will fail.
WARNING: You're using the example google-services.json file. Google login will fail.
Could not find google-services.json while looking in [src/wasabi/debug, src/debug/wasabi, src/wasabi, src/debug, src/wasabiDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/jalapeno/debug, src/debug/jalapeno, src/jalapeno, src/debug, src/jalapenoDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/vanilla/debug, src/debug/vanilla, src/vanilla, src/debug, src/vanillaDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/wasabi/release, src/release/wasabi, src/wasabi, src/release, src/wasabiRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/jalapeno/release, src/release/jalapeno, src/jalapeno, src/release, src/jalapenoRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Could not find google-services.json while looking in [src/vanilla/release, src/release/vanilla, src/vanilla, src/release, src/vanillaRelease]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
WARNING: API 'variant.getMappingFile()' is obsolete and has been replaced with 'variant.getMappingFileProvider()'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getMappingFile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.

> Configure project :
Copying git-hooks scripts from tools/team-props/git-hooks to .git/hooks
Checking whether `configure` binary is present

> Task :applyConfiguration
11:02:17 [DEBUG] (1) configure: libconfigure initialized
11:02:17 [DEBUG] (1) configure: libConfigure initializing encryption
11:02:17 [DEBUG] (1) configure: libConfigure encryption initialization successful
11:02:17 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
11:02:17 [DEBUG] (1) configure::fs: Configure file found at: "/Users/olivier/Documents/Dev/woocommerce-android-clean/.configure"
11:02:17 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
11:02:17 [DEBUG] (1) configure::fs: Keys file found at: "/Users/olivier/.mobile-secrets/keys.json"
11:02:17 [DEBUG] (1) configure::fs: Reading keys from "/Users/olivier/.mobile-secrets/keys.json"
11:02:17 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
11:02:17 [DEBUG] (1) configure::fs: "/Users/olivier/Documents/Dev/woocommerce-android-clean/gradle.properties" already exists – making a backup at "/Users/olivier/Documents/Dev/woocommerce-android-clean/gradle-2021-03-08-11-02-17.properties.bak"
11:02:17 [DEBUG] (1) configure::fs: Encrypting file at "/Users/olivier/Documents/Dev/woocommerce-android-clean/.configure-files/gradle.properties.enc" and storing contents at "/Users/olivier/Documents/Dev/woocommerce-android-clean/gradle.properties"
11:02:17 [DEBUG] (1) configure::fs: Original File Hash: Ok("7e29gZCJ4n8ShY7NVNm8H5pTbywfUK6ZyS6GFdjM2zQ=")
11:02:17 [DEBUG] (1) configure::fs: New File hash: Ok("KwZ2aI7uyjloXi3kvdh4bsztdX0pP01/N9zME7reNLY=")
11:02:17 [DEBUG] (1) configure::fs: Keeping backup file because it differs from the original
11:02:17 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
11:02:17 [DEBUG] (1) configure::fs: "/Users/olivier/Documents/Dev/woocommerce-android-clean/WooCommerce/google-services.json" already exists – making a backup at "/Users/olivier/Documents/Dev/woocommerce-android-clean/WooCommerce/google-services-2021-03-08-11-02-17.json.bak"
11:02:17 [DEBUG] (1) configure::fs: Encrypting file at "/Users/olivier/Documents/Dev/woocommerce-android-clean/.configure-files/google-services.json.enc" and storing contents at "/Users/olivier/Documents/Dev/woocommerce-android-clean/WooCommerce/google-services.json"
11:02:17 [DEBUG] (1) configure::fs: Original File Hash: Ok("9wyjUznr4ktWFCnVSIHFrzPV7nJdk0ydRI39Fry1eS8=")
11:02:17 [DEBUG] (1) configure::fs: New File hash: Ok("RDY9r9jRjWh2CDME2u4cyCAzb6fKzncHPvRviTrXiX4=")
11:02:17 [DEBUG] (1) configure::fs: Keeping backup file because it differs from the original
11:02:17 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
11:02:17 [DEBUG] (1) configure::fs: Encrypting file at "/Users/olivier/Documents/Dev/woocommerce-android-clean/.configure-files/sentry.properties.enc" and storing contents at "/Users/olivier/Documents/Dev/woocommerce-android-clean/sentry.properties"
11:02:17 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
11:02:17 [DEBUG] (1) configure::fs: Encrypting file at "/Users/olivier/Documents/Dev/woocommerce-android-clean/.configure-files/upload.jks.enc" and storing contents at "/Users/olivier/Documents/Dev/woocommerce-android-clean/.configure-files/upload.jks"
11:02:17 [DEBUG] (1) configure::fs: Discovered Repository at "/Users/olivier/Documents/Dev/woocommerce-android-clean"
11:02:17 [DEBUG] (1) configure::fs: Encrypting file at "/Users/olivier/Documents/Dev/woocommerce-android-clean/.configure-files/google-upload-credentials.json.enc" and storing contents at "/Users/olivier/Documents/Dev/woocommerce-android-clean/google-upload-credentials.json"
11:02:17 [DEBUG] (1) configure::configure: All Files Copied!
11:02:17 [ INFO] Done

BUILD SUCCESSFUL in 987ms
1 actionable task: 1 executed
… but only one decrypted file in .configure-files 😞
$ ls -l .configure-files
total 64
-rw-r--r--  1 olivier  staff  2144 Mar  8 11:47 automattic_upload.jks.enc
-rw-r--r--  1 olivier  staff  1264 Mar  8 11:47 debug.keystore.enc
-rw-r--r--  1 olivier  staff  3903 Mar  8 11:48 google-services.json.enc
-rw-r--r--  1 olivier  staff  2402 Mar  8 11:48 google-upload-credentials.json.enc
-rw-r--r--  1 olivier  staff  2123 Mar  8 11:48 gradle.properties.enc
-rw-r--r--  1 olivier  staff   170 Mar  8 11:48 sentry.properties.enc
-rw-r--r--  1 olivier  staff  2142 Mar  8 12:02 upload.jks
-rw-r--r--  1 olivier  staff  2182 Mar  8 11:48 upload.jks.enc

PS: I tried to git clean -dxn the working copy, even rm -rf .configure-files then git restore .configure-files, then re-run ./gradlew applyConfiguration again, and got the same result (= upload.jks being the only unencrypted file present in .configure-files after that).

@AliSoftware AliSoftware modified the milestones: 6.2, 6.3 Mar 8, 2021
@AliSoftware
Copy link
Contributor

@jkmassel any luck on making progress on the issues highlighted above? Wondering if I could get this tested during next code freeze on Monday 🤔

@AliSoftware AliSoftware modified the milestones: 6.3, 6.4 Mar 22, 2021
@AliSoftware AliSoftware modified the milestones: 6.4, 6.5 Apr 6, 2021
@AliSoftware
Copy link
Contributor

@jkmassel: moved the milestone of this PR once again (since I'm doing the code freeze of 6.4 today).

@jkmassel jkmassel modified the milestones: 6.5, 6.7 Apr 15, 2021
@AliSoftware
Copy link
Contributor

Another sprint, another milestone move 😅 (We'll get there! 🤞 )

@AliSoftware AliSoftware modified the milestones: 6.7, 6.8 May 17, 2021
@AliSoftware AliSoftware modified the milestones: 6.8, 7.0 May 31, 2021
@jkmassel jkmassel modified the milestones: 7.0, 7.3 Jun 25, 2021
@malinajirka malinajirka requested review from malinajirka and removed request for malinajirka July 12, 2021 07:36
@jkmassel jkmassel modified the milestones: 7.3, 7.4 Aug 9, 2021
@jkmassel jkmassel removed this from the 7.4 milestone Aug 23, 2021
@astralbodies
Copy link
Contributor

@jkmassel Should we move this to a draft status?

@jkmassel jkmassel marked this pull request as draft November 2, 2021 15:09
@wzieba
Copy link
Contributor

wzieba commented Nov 15, 2024

I'll allow myself to close this PR - it updates CircleCI config that we don't use anymore. Tasks removed here are also discussed in #12934

@wzieba wzieba closed this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: tooling Anything that involves building & maintaining the project, including scripts, `Fastfile`, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants