Skip to content

Commit

Permalink
Migrate from gradle-build-action to setup-gradle GitHub Action (#803)
Browse files Browse the repository at this point in the history
A new way of consuming Gradle Actions is coming in v3.
There are no significant changes to the action logic,
the v3 version and the new action is a drop-in replacement.

Setting up AND running Gradle in the same step is deprecated,
so the steps are split into two: setup-gradle + `run:`.

Because `run:` uses different shells on different OSs,
the `-Pa=b` Gradle params are moved to `ORG_GRADLE_PROJECT_a: b`
environment variables, because that approach is fully cross platform.

Removed `cache: 'gradle'` from setup-java,
because setup-gradle is doing the same, and more.

PR: #803
  • Loading branch information
TWiStErRob committed Feb 6, 2024
1 parent 9919bf9 commit e9f160e
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions .github/workflows/build.yml
Expand Up @@ -63,11 +63,10 @@ jobs:
with:
java-version: 11
distribution: temurin
cache: 'gradle'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Gradle build
uses: gradle/gradle-build-action@v2
with:
arguments: --refresh-dependencies --stacktrace --scan clean build -x spotlessCheck
run: ./gradlew --refresh-dependencies --stacktrace --scan clean build -x spotlessCheck

# SonarCloud analysis
sonar-cloud-analysis:
Expand All @@ -86,16 +85,15 @@ jobs:
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Cache SonarCloud results
uses: actions/cache@v4
with:
path: ~/.sonar/cache/
key: ubuntu-sonar
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Gradle build
uses: gradle/gradle-build-action@v2
with:
arguments: --refresh-dependencies --stacktrace --scan clean build -x spotlessCheck
run: ./gradlew --refresh-dependencies --stacktrace --scan clean build -x spotlessCheck
- name: SonarCloud analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -116,11 +114,10 @@ jobs:
with:
java-version: 11
distribution: temurin
cache: 'gradle'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Spotless check
uses: gradle/gradle-build-action@v2
with:
arguments: --scan spotlessCheck
run: ./gradlew --scan spotlessCheck

# Our full integration job, which will build for a matrix out of our
# supported Java versions, operating systems and various JUnit versions.
Expand All @@ -145,11 +142,12 @@ jobs:
with:
java-version: ${{ matrix.java }}
distribution: temurin
cache: 'gradle'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Gradle build
uses: gradle/gradle-build-action@v2
with:
arguments: --refresh-dependencies -PjunitVersion=${{ matrix.junit-version }} --stacktrace --scan clean build -x spotlessCheck
env:
ORG_GRADLE_PROJECT_junitVersion: ${{ matrix.junit-version }}
run: ./gradlew --refresh-dependencies --stacktrace --scan clean build -x spotlessCheck

# We want to be up-to-date and know issues with future Java versions as soon as possible.
# Furthermore, we also would love to see our build working with the latest Gradle version.
Expand Down Expand Up @@ -183,17 +181,23 @@ jobs:
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Gradle toolchains
uses: gradle/gradle-build-action@v2
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: release-candidate
arguments: -Porg.gradle.java.installations.auto-download=false javaToolchains

- name: Gradle version
run: gradle --version
- name: Gradle toolchains
env:
ORG_GRADLE_PROJECT_org.gradle.java.installations.auto-download: false
run: gradle javaToolchains
- name: Gradle build
uses: gradle/gradle-build-action@v2
with:
gradle-version: release-candidate
arguments: --refresh-dependencies -PexperimentalJavaVersion=${{ env.EXPERIMENTAL_JAVA }} -PjunitVersion=${{ matrix.junit-version }} -Porg.gradle.java.installations.auto-download=false --stacktrace --scan clean build -x spotlessCheck
env:
ORG_GRADLE_PROJECT_experimentalJavaVersion: ${{ env.EXPERIMENTAL_JAVA }}
ORG_GRADLE_PROJECT_junitVersion: ${{ matrix.junit-version }}
ORG_GRADLE_PROJECT_org.gradle.java.installations.auto-download: false
run: gradle --refresh-dependencies --stacktrace --scan clean build -x spotlessCheck

# A release will be created if there is a `version` defined and `releasing` is set to `true`.
# If not, this stage will be ignored.
Expand All @@ -218,8 +222,9 @@ jobs:
21
11
distribution: temurin
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Perform release
uses: gradle/gradle-build-action@v2
env:
# used to trigger website build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -231,8 +236,7 @@ jobs:
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.NEXUS_TOKEN_PASSWORD }}
# defines released version according to GitHub Action input
ORG_GRADLE_PROJECT_version: ${{ github.event.inputs.version }}
with:
arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository githubRelease
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository githubRelease

# After our release, we also need to trigger an update for our website build
update-website:
Expand Down

0 comments on commit e9f160e

Please sign in to comment.