From bb4b135ecadfcced86649b23dc384223ee2bb44b Mon Sep 17 00:00:00 2001 From: Thor Andreas Rognan Date: Fri, 26 Nov 2021 02:09:59 +0100 Subject: [PATCH] Replace ./gradlew with gradle-build-action on CI This simplifies running the build using different Gradle versions, and it provides a more efficient caching of Gradle User Home between workflow runs compared to setup-java. GitHub's actions/cache is scoped to the key and branch, where the default branch cache is available to other branches. This means identical cache entries will be stored separately for different branches. To reduce cache usage and cache eviction rate due to cache size constraints, we only write to the cache on the 'main' branch. --- .github/workflows/main.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8813068..f35002c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,10 +10,10 @@ jobs: strategy: matrix: include: - - { os: 'macos-latest', arch: 'x64', java-version: '11' } - - { os: 'ubuntu-latest', arch: 'x64', java-version: '11' } - - { os: 'windows-latest', arch: 'x64', java-version: '11' } - name: Java ${{ matrix.java-version }} on ${{ matrix.os }} (${{ matrix.arch }}) + - { os: 'macos-latest', arch: 'x64', java-version: '11', gradle-version: '7.3' } + - { os: 'ubuntu-latest', arch: 'x64', java-version: '11', gradle-version: '7.3' } + - { os: 'windows-latest', arch: 'x64', java-version: '11', gradle-version: '7.3' } + name: Gradle ${{ matrix.gradle-version }}, Java ${{ matrix.java-version }} on ${{ matrix.os }} (${{ matrix.arch }}) runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -23,8 +23,12 @@ jobs: architecture: ${{ matrix.arch }} distribution: 'temurin' java-version: ${{ matrix.java-version }} - cache: 'gradle' - - run: ./gradlew build --scan --no-daemon + - uses: gradle/gradle-build-action@v2 + with: + # Only write to the cache on the 'main' branch + cache-read-only: ${{ github.ref != 'refs/heads/main' }} + gradle-version: ${{ matrix.gradle-version }} + arguments: build --scan - name: Upload build reports uses: actions/upload-artifact@v2 if: always()