Commit 682d7347 authored by Paul Merlin's avatar Paul Merlin
Browse files

Optional dependencies cache

and bonus configuration cache

Merge branch 'eskatos/caching'
parents e8885a31 3c43b652
Loading
Loading
Loading
Loading
+1 −1
Changes for .eslintrc.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
      "@typescript-eslint/prefer-includes": "error",
      "@typescript-eslint/prefer-string-starts-ends-with": "error",
      "@typescript-eslint/promise-function-async": "error",
      "@typescript-eslint/require-array-sort-compare": "error",
      "@typescript-eslint/require-array-sort-compare": ["error", {"ignoreStringArrays":  true}],
      "@typescript-eslint/restrict-plus-operands": "error",
      "semi": "off",
      "@typescript-eslint/semi": ["error", "never"],
+7 −3
Changes for .github/workflows/dev.yml: 7 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -22,10 +22,14 @@ jobs:
      with:
        wrapper-directory: __tests__/data/basic
        build-root-directory: __tests__/data/basic
        arguments: help
        dependencies-cache-enabled: true
        configuration-cache-enabled: true
        arguments: test
    - name: Test dist download
      uses: ./
      with:
        gradle-version: 6.5
        gradle-version: 6.6-milestone-1
        build-root-directory: __tests__/data/basic
        arguments: help
        dependencies-cache-enabled: true
        configuration-cache-enabled: true
        arguments: test --configuration-cache
+7 −3
Changes for .github/workflows/prod.yml: 7 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -21,10 +21,14 @@ jobs:
      with:
        wrapper-directory: __tests__/data/basic
        build-root-directory: __tests__/data/basic
        arguments: help
        dependencies-cache-enabled: true
        configuration-cache-enabled: true
        arguments: test
    - name: Test dist download
      uses: ./
      with:
        gradle-version: 6.5
        gradle-version: 6.6-milestone-1
        build-root-directory: __tests__/data/basic
        arguments: help
        dependencies-cache-enabled: true
        configuration-cache-enabled: true
        arguments: test --configuration-cache
+62 −3
Changes for README.md: 62 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@ You might also be interested by the related [Gradle Plugin](https://github.com/e

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.



```yaml
# .github/workflows/gradle-build-pr.yml
name: Run Gradle on PRs
@@ -120,7 +118,68 @@ jobs:
        arguments: build --dry-run # just test build configuration
```

# Build scans
## Caching

This action provides 3 levels of caching to help speed up your GitHub Actions:

- `wrapper` caches the local [wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) installation, saving time downloading and unpacking Gradle distributions ;
- `dependencies` caches the [dependencies](https://docs.gradle.org/current/userguide/dependency_resolution.html#sub:cache_copy), saving time downloading dependencies ;
- `configuration` caches the [build configuration](https://docs.gradle.org/nightly/userguide/configuration_cache.html), saving time configuring the build.

Only the first one, caching the wrapper installation, is enabled by default.
Future versions of this action will enable all caching by default.

You can control which level is enabled as follows:

```yaml
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
```

The wrapper installation cache is simple and can't be configured further.

The dependencies and configuration cache will compute a cache key in a best effort manner.
Keep reading to learn how to better control how they work.

### Configuring the dependencies and configuration caches

Both the dependencies and configuration caches use the same default configuration:

They use the following inputs to calculate the cache key:
```text


```

They restore cached state even if there isn't an exact match.

If the defaults don't suit your needs you can override them with the following inputs:

```yaml
dependencies-cache-key: |
  **/gradle.properties
  gradle/dependency-locking/**
dependencies-cache-exact: true
configuration-cache-key: |
  **/gradle.properties
  gradle/dependency-locking/**
configuration-cache-exact: true
```

Coming up with a good cache key isn't trivial and depends on your build.
The above example isn't realistic.
Stick to the defaults unless you know what you are doing.

If you happen to use Gradle [dependency locking](https://docs.gradle.org/current/userguide/dependency_locking.html) you can make the dependencies cache more precise with the following configuration:

```yaml
dependencies-cache-enabled: true
dependencies-cache-key: gradle/dependency-locking/**
dependencies-cache-exact: true
```

## Build scans

If your build publishes a [build scan](https://gradle.com/build-scans/) the `gradle-command-action` action will emit the link to the published build scan as an output named `build-scan-url`.

+5 −5
Changes for __tests__/cache-wrapper.test.ts: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
import * as cache from '../src/cache'
import * as cacheWrapper from '../src/cache-wrapper'
import * as path from 'path'

describe('cache', () => {
    describe('can extract gradle wrapper slug', () => {
        it('from wrapper properties file', async () => {
            const version = cache.extractGradleWrapperSlugFrom(
            const version = cacheWrapper.extractGradleWrapperSlugFrom(
                path.resolve(
                    '__tests__/data/basic/gradle/wrapper/gradle-wrapper.properties'
                )
@@ -12,19 +12,19 @@ describe('cache', () => {
            expect(version).toBe('6.5-bin')
        })
        it('for -bin dist', async () => {
            const version = cache.extractGradleWrapperSlugFromDistUri(
            const version = cacheWrapper.extractGradleWrapperSlugFromDistUri(
                'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.5-bin.zip'
            )
            expect(version).toBe('6.5-bin')
        })
        it('for -all dist', async () => {
            const version = cache.extractGradleWrapperSlugFromDistUri(
            const version = cacheWrapper.extractGradleWrapperSlugFromDistUri(
                'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.5-all.zip'
            )
            expect(version).toBe('6.5-all')
        })
        it('for milestone', async () => {
            const version = cache.extractGradleWrapperSlugFromDistUri(
            const version = cacheWrapper.extractGradleWrapperSlugFromDistUri(
                'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.6-milestone-1-all.zip'
            )
            expect(version).toBe('6.6-milestone-1-all')
Loading