Execute your Gradle build and trigger dependency submission
Find a file
Paul Merlin 12e24e843d Fix for Windows
Merge branch 'eskatos/fix-windows'
2020-06-14 12:39:47 +02:00
.github/workflows Simplify CI 2020-06-14 12:36:06 +02:00
__tests__ Compute wrapper cache key 2020-06-13 15:51:58 +02:00
dist Locate user home in an OS agnostic way 2020-06-14 12:28:17 +02:00
src Locate user home in an OS agnostic way 2020-06-14 12:28:17 +02:00
.eslintignore Add various js build configs 2020-06-13 12:46:29 +02:00
.eslintrc.json Lint 2020-06-13 13:58:25 +02:00
.gitignore Fix build 2020-06-13 13:03:18 +02:00
.prettierignore Add various js build configs 2020-06-13 12:46:29 +02:00
.prettierrc.json Format 2020-06-13 13:44:30 +02:00
action.yml Split action, step 2 2020-06-13 13:34:07 +02:00
CODE_OF_CONDUCT.md add code of conduct 2019-09-21 20:57:04 +02:00
jest.config.js Add various js build configs 2020-06-13 12:46:29 +02:00
jest.setup.js Add various js build configs 2020-06-13 12:46:29 +02:00
LICENSE Initial commit 2019-09-20 23:06:59 +02:00
package-lock.json Add @action/cache 2020-06-13 13:42:27 +02:00
package.json Run lint on CI 2020-06-13 14:33:04 +02:00
README.md Refine README 2020-06-13 12:45:21 +02:00
tsconfig.json Split action, step 1 2020-06-13 13:30:20 +02:00

Execute Gradle commands in GitHub Actions workflows

This GitHub Action can be used to run arbitrary Gradle commands on any platform supported by GitHub Actions.

You might also be interested by the related Gradle Plugin that allows your build to easily get GitHub Actions environment and tag Gradle Build Scans accordingly.

Usage

The following workflow will run ./gradlew build using the wrapper from the repository on ubuntu, macos and windows. The only prerequisite is to have Java installed, you can define the version you need to run the build using the actions/setup-java action.

# .github/workflows/gradle-build-pr.yml
name: Run Gradle on PRs
on: pull_request
jobs:
  gradle:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-java@v1
      with:
        java-version: 11
    - uses: eskatos/gradle-command-action@v1
      with:
        arguments: build

Gradle arguments

The arguments input can used to pass arbitrary arguments to the gradle command line.

Here are some valid examples:

arguments: build
arguments: check --scan
arguments: some arbitrary tasks
arguments: build -PgradleProperty=foo
arguments: build -DsystemProperty=bar
....

See gradle --help for more information.

If you need to pass environment variables, simply use the GitHub Actions workflow syntax:

- uses: eskatos/gradle-command-action@v1
  env:
    CI: true

Run a build from a different directory

- uses: eskatos/gradle-command-action@v1
  with:
    build-root-directory: some/subdirectory

Use a Gradle wrapper from a different directory

 - uses: eskatos/gradle-command-action@v1
   with:
     wrapper-directory: path/to/wrapper-directory

Use a specific gradle executable

 - uses: eskatos/gradle-command-action@v1
   with:
     gradle-executable: path/to/gradle

Setup and use a declared Gradle version

 - uses: eskatos/gradle-command-action@v1
   with:
     gradle-version: 5.6.2

gradle-version can be set to any valid Gradle version.

Moreover, you can use the following aliases:

Alias Selects
wrapper The Gradle wrapper's version (default, useful for matrix builds)
current The current stable release
rc The current release candidate if any, otherwise fallback to current
nightly The latest nightly, fails if none.
release-nightly The latest release nightly, fails if none.

This can be handy to, for example, automatically test your build with the next Gradle version once a release candidate is out:

# .github/workflows/test-gradle-rc.yml
name: Test latest Gradle RC
on:
  schedule:
    - cron: 0 0 * * * # daily
jobs:
  gradle-rc:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-java@v1
      with:
        java-version: 11
    - uses: eskatos/gradle-command-action@v1
      with:
        gradle-version: rc
        arguments: build --dry-run # just test build configuration

Build scans

If your build publishes a build scan the gradle-command-action action will emit the link to the published build scan as an output named build-scan-url.

You can then use that link in subsequent actions of your workflow.

For example:

# .github/workflows/gradle-build-pr.yml
name: Run Gradle on PRs
on: pull_request
jobs:
  gradle:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-java@v1
      with:
        java-version: 11
    - uses: eskatos/gradle-command-action@v1
      with:
        arguments: build
      id: gradle
    - uses: example/action-that-comments-on-the-pr@v0
      if: failure()
      with:
        comment: Build failed ${{ steps.gradle.outputs.build-scan-url }}