Skip to content

Commit

Permalink
Update files
Browse files Browse the repository at this point in the history
  • Loading branch information
hkusu committed Mar 12, 2024
1 parent 3d482d8 commit 2f3e8c9
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
88 changes: 84 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
48 changes: 45 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2f3e8c9

Please sign in to comment.