Page MenuHomePhabricator

[CI] Clear unused NDKs from Android GitHub CI jobs before proceeding
ClosedPublic

Authored by ashoat on Oct 12 2023, 5:28 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 10, 10:55 AM
Unknown Object (File)
Sun, Nov 10, 2:55 AM
Unknown Object (File)
Sun, Nov 10, 1:02 AM
Unknown Object (File)
Sun, Nov 10, 12:06 AM
Unknown Object (File)
Sun, Nov 3, 7:23 PM
Unknown Object (File)
Oct 19 2024, 3:29 AM
Unknown Object (File)
Oct 19 2024, 3:20 AM
Unknown Object (File)
Oct 19 2024, 1:33 AM
Subscribers

Details

Summary

I was able to SSH into a GitHub runner using tmate. After playing around a bit, I realized a bunch of time and disk space was spent installing the Android NDK.

React Native 0.70 uses uses an ancient version of the Android NDK (21.4.7075529) that is no longer preinstalled on GitHub runner images. As a result, the Gradle build has to install that Android NDK. During installation a large amount of disk space is used (about 5 GB or so), which is later partially freed after the installation succeeds.

In fact the GitHub runner comes with 4 NDKs preinstalled. They take up a lot of disk space. This diff deletes the NDKs that we don't use. (Actually it keeps 24 around because React Native 0.70 mentions two NDKs... 24 for Apple silicon and ancient 21 for the rest.)

Worth noting that React Native 0.71 and 0.72 move to using NDK 23 (for both Apple silicon and other), and 0.73 moves to NDK 25 (fairly recent). As a result we hopefully won't need to download an NDK during GitHub CI build in the future.

Test Plan

I forked the Comm repo, added the necessary GitHub secrets, and enabled GitHub Actions on the fork. I was able to test this diff on the work and confirm that it worked to fix the Android CI build (4.3 GB free at the end of the build). I haven't tested the release action, but I suspect it's relatively similar.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

.github/workflows/android_ci.yml
28 ↗(On Diff #31962)

From my research, $ANDROID_NDK_HOME was deprecated at some point in favor of using $ANDROID_SDK_ROOT/ndk

29 ↗(On Diff #31962)

I personally find awk a bit more sensible for this use case than bash, so I wrote it using awk. I'm open to rewriting if people feel strongly.

The opening curly braces here tell awk to do the things inside the curly braces for each line that it gets.

30 ↗(On Diff #31962)

Some pointers here:

  1. Whitespace does concatentation in awk
  2. $0 is the whole individual input line in awk
  3. system returns the exit code of the program it runs
  4. git grep returns 0 for success, or 1 if it doesn't find anything
  5. > /dev/null silences output, which otherwise awk prints to the screen
31 ↗(On Diff #31962)

I close and reopen the single-string quotation here so I can access a bash variable. I also double-quote the bash variable invocation, which is considered good practice in bash

Thanks for explaining, I think using awk is reasonable/practical in this limited use case.


FWIW, popped it into ChatGPT to ask for equivalent one-liners and it came up with:

find "$ANDROID_SDK_ROOT/ndk" -type d -exec sh -c 'git grep -qs "$1" || rm -rf "$1"' _ {} \;

f4c310.png (800×1 px, 207 KB)

This revision is now accepted and ready to land.Oct 12 2023, 6:36 AM

Yeahhhh I considered that sort of approach but I personally find it less readable with all the special characters at the end