From 2f3e8c9c6666dbb691702decc551c2f175addd8f Mon Sep 17 00:00:00 2001 From: Hiroyuki Kusu Date: Sat, 9 Mar 2024 12:11:05 +0900 Subject: [PATCH] Update files --- .github/workflows/ci.yml | 9 ++++ README.md | 88 ++++++++++++++++++++++++++++++++++++++-- action.yml | 48 ++++++++++++++++++++-- 3 files changed, 138 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a8e500..5d431d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,3 +23,12 @@ jobs: run: echo "$GITHUB_CONTEXT" - name: Use this action uses: ./ + with: + cache-read-only: false + - name: Check out samlpe project + uses: actions/checkout@v4 + with: + repository: google/iosched + path: sample + - name: Build samlpe project for check + run: cd sample && ./gradlew assembleDebug diff --git a/README.md b/README.md index baad8d3..ef17418 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,92 @@ -[![CI](https://github.com/yumemi-inc/setup-java/actions/workflows/ci.yml/badge.svg)](https://github.com/yumemi-inc/setup-java/actions/workflows/ci.yml) +[![CI](https://github.com/yumemi-inc/setup-java-gradle/actions/workflows/ci.yml/badge.svg)](https://github.com/yumemi-inc/setup-java-gradle/actions/workflows/ci.yml) # Setup Java - Gradle -A GitHub Action that sets up a Java JDK and Gradle environment. -It is a composite action that combines the following actions. +A GitHub Action that sets up a Java and Gradle environment. +It is a composite action that uses the following actions. - [actions/setup-java](https://github.com/actions/setup-java) - [gradle/gradle-build-action](https://github.com/gradle/gradle-build-action) - [yumemi-inc/problem-matchers/kotlin-gradle](https://github.com/yumemi-inc/problem-matchers/tree/main/kotlin-gradle) -Simplify the setup description each time you run a Gradle command, and do not create Gradle caches by default. +Simplify workflow steps and do not write Gradle cache by default. + +## Usage + +See [action.yml](action.yml) for available action inputs. +However, since it is only being passed, refer to the original action's README and action.yml for details. + +Currently, the minimum input items are passed. + +### Basic + +Place this action step before Gradle tasks. + +```yaml +- uses: actions/checkout@v4 +- uses: yumemi-inc/setup-java-gradle@v1 +- run: ./gradlew ... +``` + +By default, the Java version set up is `17`. +Because it is the mainstream in current Android application development. +If you want to change the version, specify it with `java-version` input. + +## About writing cache + +By default, the internally used gradle/gradle-build-action writes cache in workflow on default branch, but to prevent careless writes, this yumemi-inc/setup-java-gradle action does not write cache anywhere by default. + +You can set `cache-read-only` input to `false` when you want to write the cache, but it is simpler to prepare the following workflow. + +```yaml +name: Cache Generation + +on: + schedule: + - cron: '0 */6 * * *' # for example, every 6 hours + +jobs: + cache-generation: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + # with: + # ref: .. # specify if there is a branch other than the default branch where the code is frequently updated + - uses: yumemi-inc/setup-java-gradle@v1 + with: + cache-read-only: false + gradle-home-cache-cleanup: true + - run: ./gradlew dependencies # some Gradle task +``` + +Workflows triggered by [schedule](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule) events run on the default branch, and cache is written to the default branch. +Cache on default branch available for all workflows. +Alternatively, if the default branch is frequently updated, you can trigger [push](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push) events on the default branch rather than schedule events. + +In the above workflow, `true` is specified for `gradle-home-cache-cleanup` input to prevent size increase due to cache accumulation, but if reusability is a priority, specify `false`(default). + +When writing to cache, the Gradle daemon is automatically stopped by internally used gradle/gradle-build-action, so there is no need to explicitly stop it. + +## Using Gradle build cache + +Build cache can be enabled with the `gradle.properties` file or with the following environment variable: + +```yaml +- run: ./gradlew ... + env: + GRADLE_OPTS: '-Dorg.gradle.caching=true' +``` + +Note that this option is required not only when reading the cache, but also when writing it. + +When writing the build cache, it is recommended to run a Gradle task that has many intermediates, such as a build task. + +Some reusable items are used, even if they are intermediates between different Gradle tasks. +Check the Gradle task log to see how much cache is used. + +``` +BUILD SUCCESSFUL in 34s +164 actionable tasks: 64 executed, 100 from cache +``` diff --git a/action.yml b/action.yml index faa0b69..0ab89fb 100644 --- a/action.yml +++ b/action.yml @@ -1,11 +1,53 @@ name: "Setup Java - Gradle" -description: "A GitHub Action that sets up a Java JDK and Gradle environment." +description: "A GitHub Action that sets up a Java and Gradle environment." author: "YUMEMI Inc." branding: icon: "box" color: "blue" +inputs: + java-version: + description: "Java version to use." + required: false + default: "17" + java-distribution: # original name is 'distribution' + description: "Java distribution to use." + required: false + default: "zulu" + cache-disabled: + description: "Whether to read/write Gradle cache." + required: false + default: "false" + cache-read-only: + description: "Whether to only read Gradle cache." + required: false + default: "true" + gradle-home-cache-cleanup: + description: "Whether to remove stale/unused Gradle cache before writing." + required: false + default: "false" + gradle-build-report: # original name is 'add-job-summary' + description: "Whether to display Gradle build reports in Job Summaries." + required: false + default: "always" + kotlin-compiler-report: + description: "Whether to apply Kotlin compiler Problem Matchers." + required: false + default: "true" runs: using: "composite" steps: - - shell: bash - run: echo 'hello' + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: ${{ inputs.java-distribution }} + java-version: ${{ inputs.java-version }} + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + cache-disabled: ${{ inputs.cache-disabled }} + cache-read-only: ${{ inputs.cache-read-only }} + gradle-home-cache-cleanup: ${{ inputs.gradle-home-cache-cleanup }} + add-job-summary: ${{ inputs.gradle-build-report }} + - name: Setup Problem Matchers + if: inputs.kotlin-compiler-report != 'false' + uses: yumemi-inc/problem-matchers/kotlin-gradle@v1