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

Merge pull request #140 from gradle/cache-disable

Fix Build Scan capture when cache is disabled

With the change to use init-scripts to inject Build Scan capture, this functionality broke when caching was disabled and Gradle User Home wasn't initialized.

This PR fixes a couple of issues and ensures that the Gradle User Home is initialized even when it is not restored from the GitHub Actions cache.

Fixes #138 
Fixes #139
parents a7260b27 4f616f68
Loading
Loading
Loading
Loading
+1 −1
Changes for .github/workflows/failure-cases.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ on:
  workflow_dispatch:

env:
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-

jobs:

+1 −1
Changes for .github/workflows/integTest-action-inputs.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ on:
  workflow_dispatch:

env:
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-

jobs:
  action-inputs:
+45 −2
Changes for .github/workflows/integTest-caching-config.yml: 45 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ on:
  workflow_dispatch:

env:
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-
  GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true

jobs:
@@ -46,7 +46,7 @@ jobs:
    - name: Setup Gradle
      uses: ./
      with:
        # Use the same configuration when restoring state from cache
        # Use the same configuration as used in the seed build
        gradle-home-cache-includes: |
            caches
            enterprise
@@ -57,4 +57,47 @@ jobs:
      working-directory: __tests__/samples/groovy-dsl
      run: ./gradlew test --offline

  # Test that build scans are captured when caching is explicitly disabled
  cache-disabled:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout sources
      uses: actions/checkout@v2
    - name: Setup Gradle
      uses: ./
      with:
        cache-disabled: true
    - name: Run Gradle build
      id: gradle
      working-directory: __tests__/samples/no-wrapper${{ matrix.build-root-suffix }}
      run: gradle help "-DgradleVersionCheck=${{matrix.gradle}}"
    - name: Check build scan url is captured
      if: ${{ !steps.gradle.outputs.build-scan-url }}
      uses: actions/github-script@v3
      with:
        script: |
          core.setFailed('No build scan detected')

  # Test that build scans are captured when caching is disabled because Gradle User Home already exists
  cache-disabled-pre-existing-gradle-home:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout sources
      uses: actions/checkout@v2
    - name: Create dummy Gradle User Home
      run: mkdir -p ~/.gradle/caches
    - name: Setup Gradle
      uses: ./
    - name: Run Gradle build
      id: gradle
      working-directory: __tests__/samples/no-wrapper${{ matrix.build-root-suffix }}
      run: gradle help "-DgradleVersionCheck=${{matrix.gradle}}"
    - name: Check build scan url is captured
      if: ${{ !steps.gradle.outputs.build-scan-url }}
      uses: actions/github-script@v3
      with:
        script: |
          core.setFailed('No build scan detected')
+9 −9
Changes for .github/workflows/integTest-caching-configuration-cache.yml: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ jobs:
  # These builds should start fresh without cache hits, due to the seed injected into the cache key above.
  seed-build-groovy:
    env:
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-groovy-
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-groovy-
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
@@ -30,7 +30,7 @@ jobs:

  configuration-cache-groovy:
    env:
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-groovy-
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-groovy-
    needs: seed-build-groovy
    strategy:
      matrix:
@@ -52,7 +52,7 @@ jobs:
  # Check that the build can run when no extracted cache entries are restored
  no-extracted-cache-entries-restored:
    env:
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-groovy-
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-groovy-
    needs: seed-build-groovy
    strategy:
      matrix:
@@ -73,7 +73,7 @@ jobs:

  seed-build-kotlin:
    env:
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-kotlin-
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-kotlin-
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
@@ -83,13 +83,13 @@ jobs:
      uses: actions/checkout@v2
    - name: Setup Gradle
      uses: ./
    - name: Kotlin build with configuration-cache enabled
    - name: Execute 'help' with configuration-cache enabled
      working-directory: __tests__/samples/kotlin-dsl
      run: ./gradlew help --configuration-cache

  modify-build-kotlin:
    env:
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-kotlin-
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-kotlin-
    needs: seed-build-kotlin
    strategy:
      matrix:
@@ -100,14 +100,14 @@ jobs:
      uses: actions/checkout@v2
    - name: Setup Gradle
      uses: ./
    - name: Kotlin build with configuration-cache enabled
    - name: Execute 'test' with configuration-cache enabled
      working-directory: __tests__/samples/kotlin-dsl
      run: ./gradlew test --configuration-cache

 # Test restore configuration-cache from the third build invocation
  configuration-cache-kotlin:
    env:
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-kotlin-
      GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-kotlin-
    needs: modify-build-kotlin
    strategy:
      matrix:
@@ -120,7 +120,7 @@ jobs:
      uses: ./
      with:
        cache-read-only: true
    - name: Execute Gradle build and verify cached configuration
    - name: Execute 'test' again and verify cached configuration
      env: 
        VERIFY_CACHED_CONFIGURATION: true
      working-directory: __tests__/samples/kotlin-dsl
+1 −1
Changes for .github/workflows/integTest-caching-gradle-home.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ on:
  workflow_dispatch:

env:
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}:${{github.run_attempt}}-

jobs:
  seed-build:
Loading