usilo
usilo

Reputation: 365

github actions, split gradle calls accross jobs

In my github actions jobs I would like to have n jobs.

The idea is that the project is built in job1 while job2 to job n would reuse what was already built in job1 and only build the tests (that are made by a task run by connectedCheck). This is in order to avoid having everything built from scratch in job2 to job n.

I already:

I tried to touch the files in app/build & app/.cxx before running gradle again (so that I'm sure the files are all older than the source files).

But this still doesn't permit to gain in build time. In other words, the system still rebuilds everything, gradle runs the tasks that were done in job1 again.

Any idea on how to achieve this?

Upvotes: 2

Views: 224

Answers (1)

usilo
usilo

Reputation: 365

I found that:

  • touch was useless
  • the source files must have the same timestamps across the jobs. If github gets the repo with a git checkout, the files will have the timestamp of the time of the checkout. So to have always the same timestamp, you may use git-restore-mtime. There is a github actions chetan/git-restore-mtime-action@v1 for it.
  • I also had to add the $PROJECT_DIR/.gradle directory.

In addition to that, by running:

  • gradle with -i option
  • ninja with -d explain -v options

I found that:

  • I had other build/ dirs in other places than just in app/build/. Typically in some of the libraries I use. For example in additional_lib/my_lib/build/
  • this file is also needed: ~/.android/debug.keystore
  • the files & dirs in ANDROID_SDK_ROOT/ndk/<version> and ANDROID_SDK_ROOT/cmake/<version> must have the same timestamp across the jobs.

So in the job you have to:

  1. be sure that the source files have the same timestamp across the jobs

    • set fetch-depth to 0
        - name: checkout
          uses: actions/checkout@v3
          with:
            fetch-depth: 0
      
    • use chetan/git-restore-mtime-action@v1
        - name: restore timestamps
          uses: chetan/git-restore-mtime-action@v1
      
  2. be sure that files in these dirs have the same timestamp across the jobs.

    • ANDROID_SDK_ROOT/ndk/
    • ANDROID_SDK_ROOT/cmake/
  3. cache these folders:

    • .gradle/
    • app/build/
    • app/.cxx/
    • additional_lib/my_lib/build/
    • ~/.gradle/
    • ~/.android/debug.keystore

Note: I also added ~/.gradle in the cache, but this is probably not mandatory

Upvotes: 0

Related Questions