Unverified Commit 947a8935 authored by Daz DeBoer's avatar Daz DeBoer Committed by GitHub
Browse files

Merge pull request #97 from gradle/dd/configurable-cache

Add some internal options for fine-tuning the gradle-build-action cache

- Can specify cache-paths to override the default directories cached from Gradle User Home
- Can specify cache-exclude-paths to exclude files from the Gradle User Home cache
- Files under caches/<gradle-version>/kotlin-dsl are now cached as a bundle
parents a94b9252 b99e9f0b
Loading
Loading
Loading
Loading
+71
Changes for .github/workflows/integTest-caching-config.yml: 71 added lines, 0 removed lines.
Original line number Diff line number Diff line
name: Test caching configuration

on:
  pull_request:
  push:
  workflow_dispatch:

env:
  CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
  CACHE_DEBUG_ENABLED: true

jobs:
  # Run initial Gradle builds to push initial cache entries
  # These builds should start fresh without cache hits, due to the seed injected into the cache key above.
  seed-build:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout sources
      uses: actions/checkout@v2
    - name: Build using Gradle wrapper
      uses: ./
      with:
        build-root-directory: __tests__/samples/groovy-dsl
        arguments: test
        # Add "wrapper" to main cache entry and remove 'wrapper-zips' bundle
        # Exclude build-cache from main cache entry
        cache-paths: |
            ["caches", "notifications", "wrapper"]
        cache-exclude-paths: |
            ["caches/build-cache-1"]
        cache-artifact-bundles: |
            [
              ["generated-gradle-jars", "caches/*/generated-gradle-jars/*.jar"],
              ["dependency-jars", "caches/modules-*/files-*/**/*.jar"],
              ["instrumented-jars", "caches/jars-*/*/"],
              ["kotlin-dsl", "caches/*/kotlin-dsl/*/*/"]
            ]

  # Test that the gradle-user-home cache will cache dependencies, by running build with --offline
  verify-build:
    needs: seed-build
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout sources
      uses: actions/checkout@v2
    - name: Execute Gradle build with --offline
      uses: ./
      with:
        build-root-directory: __tests__/samples/groovy-dsl
        arguments: test --offline
        cache-read-only: true
        # Need the same configuration when restoring state from cache
        cache-paths: |
            ["caches", "notifications", "wrapper"]
        cache-exclude-paths: |
            ["caches/build-cache-1"]
        cache-artifact-bundles: |
            [
              ["generated-gradle-jars", "caches/*/generated-gradle-jars/*.jar"],
              ["dependency-jars", "caches/modules-*/files-*/**/*.jar"],
              ["instrumented-jars", "caches/jars-*/*/"],
              ["kotlin-dsl", "caches/*/kotlin-dsl/*/*/"]
            ]

+28 −3
Changes for action.yml: 28 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -7,38 +7,63 @@ inputs:
  gradle-executable:
    description: Path to the Gradle executable
    required: false

  gradle-version:
    description: Gradle version to use
    required: false

  build-root-directory:
    description: Path to the root directory of the build
    required: false

  arguments:
    description: Gradle command line arguments (supports multi-line input)
    required: false

  cache-disabled:
    description: When 'true', all caching is disabled. No entries will be written to or read from the cache.
    required: false
    default: false

  cache-read-only:
    description: When 'true', existing entries will be read from the cache but no entries will be written
    required: false
    # TODO: It might be useful to default to read-only for PRs, or non-main branch.
    default: false 


  # EXPERIMENTAL & INTERNAL CONFIGURATION PROPERTIES
  # The following action properties allow fine-grained tweaking of the action caching behaviour.
  # These properties are not designed for production use, and may change without notice in a subsequent release of `gradle-build-action`.
  # Use at your own risk!
  workflow-job-context:
    description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users.
    description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users (INTERNAL).
    required: false
    default: ${{ toJSON(matrix) }}

  cache-paths:
    description: Paths in Gradle User Home to cache. (EXPERIMENTAL - may be changed/removed without notice)
    required: false
    default: |
        ["caches", "notifications"]

  cache-exclude-paths:
    description: Paths in Gradle User Home to exclude from cache. (EXPERIMENTAL - may be changed/removed without notice)
    required: false
    # eg ["caches/build-cache-1"] will prevent the local build cache from being saved/restored. 
    default: |
        [] 

  cache-artifact-bundles:
    description: Names and patterns of artifact bundles to cache separately. For internal use only.
    description: Names and patterns of artifact bundles to cache separately. (EXPERIMENTAL - may be changed/removed without notice)
    required: false
    default: |
        [
          ["generated-gradle-jars", "caches/*/generated-gradle-jars/*.jar"],
          ["wrapper-zips", "wrapper/dists/*/*/*.zip"],
          ["dependency-jars", "caches/modules-*/files-*/**/*.jar"],
          ["instrumented-jars", "caches/jars-*/*/"]
          ["instrumented-jars", "caches/jars-*/*/"],
          ["kotlin-dsl", "caches/*/kotlin-dsl/*/*/"]
        ]

outputs:
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

Loading