Skip to content

Commit

Permalink
Merge pull request #87 from gradle/dd/gradle-versions
Browse files Browse the repository at this point in the history
Fix build-scan link detection with older build-scan plugins

Fixes #86
  • Loading branch information
bigdaz committed Sep 29, 2021
2 parents 21dee71 + 6ff4981 commit c000a0b
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 51 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/integTest-caching.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
- name: Build using Gradle wrapper
uses: ./
with:
build-root-directory: __tests__/samples/basic
build-root-directory: __tests__/samples/groovy-dsl
arguments: test
- name: Build with configuration-cache enabled
uses: ./
with:
build-root-directory: __tests__/samples/basic
build-root-directory: __tests__/samples/groovy-dsl
arguments: test --configuration-cache

# Test that the gradle-user-home cache will cache dependencies, by running build with --offline
Expand All @@ -43,7 +43,7 @@ jobs:
- name: Execute Gradle build with --offline
uses: ./
with:
build-root-directory: __tests__/samples/basic
build-root-directory: __tests__/samples/groovy-dsl
arguments: test --offline
cache-read-only: true

Expand All @@ -60,7 +60,7 @@ jobs:
- name: Execute Gradle build and verify tasks from cache
uses: ./
with:
build-root-directory: __tests__/samples/basic
build-root-directory: __tests__/samples/groovy-dsl
arguments: test -DverifyCachedBuild=true
cache-read-only: true

Expand All @@ -79,6 +79,6 @@ jobs:
env:
VERIFY_CACHED_CONFIGURATION: true
with:
build-root-directory: __tests__/samples/basic
build-root-directory: __tests__/samples/groovy-dsl
arguments: test --configuration-cache
cache-read-only: true
69 changes: 67 additions & 2 deletions .github/workflows/integTest-execution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,71 @@ jobs:
- name: Test use defined Gradle executable
uses: ./
with:
gradle-executable: __tests__/samples/basic/gradlew${{ matrix.script-suffix }}
gradle-executable: __tests__/samples/groovy-dsl/gradlew${{ matrix.script-suffix }}
build-root-directory: __tests__/samples/no-wrapper
arguments: help -DgradleVersionCheck=7.1.1
arguments: help -DgradleVersionCheck=7.1.1

gradle-versions:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: windows-latest
script-suffix: '.bat'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Test Gradle 7
uses: ./
id: gradle7
with:
gradle-version: 7.2
build-root-directory: __tests__/samples/no-wrapper
arguments: help -DgradleVersionCheck=7.2
- name: Check Gradle 7 scan
if: ${{ !steps.gradle7.outputs.build-scan-url }}
uses: actions/github-script@v3
with:
script: |
core.setFailed('No build scan detected')
- name: Test Gradle 6
uses: ./
id: gradle6
with:
gradle-version: 6.9
build-root-directory: __tests__/samples/no-wrapper
arguments: help -DgradleVersionCheck=6.9
- name: Check Gradle 6 scan
if: ${{ !steps.gradle6.outputs.build-scan-url }}
uses: actions/github-script@v3
with:
script: |
core.setFailed('No build scan detected')
- name: Test Gradle 5
uses: ./
id: gradle5
with:
gradle-version: 5.6.4
build-root-directory: __tests__/samples/no-wrapper-gradle-5
arguments: help -DgradleVersionCheck=5.6.4
- name: Check Gradle 5 scan
if: ${{ !steps.gradle5.outputs.build-scan-url }}
uses: actions/github-script@v3
with:
script: |
core.setFailed('No build scan detected')
- name: Test Gradle 4
uses: ./
id: gradle4
with:
gradle-version: 4.10.3
build-root-directory: __tests__/samples/no-wrapper-gradle-4
arguments: help -DgradleVersionCheck=4.10.3
- name: Check Gradle 4 scan
if: ${{ !steps.gradle4.outputs.build-scan-url }}
uses: actions/github-script@v3
with:
script: |
core.setFailed('No build scan detected')
6 changes: 3 additions & 3 deletions .github/workflows/integTest-gradle-user-home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Build using Gradle wrapper
uses: ./
with:
build-root-directory: __tests__/samples/basic
build-root-directory: __tests__/samples/groovy-dsl
arguments: test

# Test that the gradle-user-home cache will cache dependencies, by running build with --offline
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Execute Gradle build with --offline
uses: ./
with:
build-root-directory: __tests__/samples/basic
build-root-directory: __tests__/samples/groovy-dsl
arguments: test --offline
cache-read-only: true

Expand All @@ -47,6 +47,6 @@ jobs:
- name: Execute Gradle build and verify tasks from cache
uses: ./
with:
build-root-directory: __tests__/samples/basic
build-root-directory: __tests__/samples/groovy-dsl
arguments: test -DverifyCachedBuild=true
cache-read-only: true
File renamed without changes.
6 changes: 0 additions & 6 deletions __tests__/samples/basic/.gitattributes

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions __tests__/samples/kotlin-dsl/.gitattributes

This file was deleted.

5 changes: 0 additions & 5 deletions __tests__/samples/kotlin-dsl/.gitignore

This file was deleted.

10 changes: 10 additions & 0 deletions __tests__/samples/no-wrapper-gradle-4/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id "com.gradle.build-scan" version "1.16"
}

buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
publishAlways()
}

8 changes: 8 additions & 0 deletions __tests__/samples/no-wrapper-gradle-4/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rootProject.name = 'no-wrapper'

println "Using Gradle version: ${gradle.gradleVersion}"

def gradleVersionCheck = System.properties.gradleVersionCheck
if (gradleVersionCheck && gradle.gradleVersion != gradleVersionCheck) {
throw new RuntimeException("Got the wrong version: expected ${gradleVersionCheck} but was ${gradle.gradleVersion}")
}
12 changes: 12 additions & 0 deletions __tests__/samples/no-wrapper-gradle-5/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("com.gradle.build-scan") version("3.7")
}

gradleEnterprise {
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
publishAlways()
uploadInBackground = false
}
}
8 changes: 8 additions & 0 deletions __tests__/samples/no-wrapper-gradle-5/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rootProject.name = 'no-wrapper'

println "Using Gradle version: ${gradle.gradleVersion}"

def gradleVersionCheck = System.properties.gradleVersionCheck
if (gradleVersionCheck && gradle.gradleVersion != gradleVersionCheck) {
throw new RuntimeException("Got the wrong version: expected ${gradleVersionCheck} but was ${gradle.gradleVersion}")
}
6 changes: 0 additions & 6 deletions __tests__/samples/no-wrapper/.gitattributes

This file was deleted.

5 changes: 0 additions & 5 deletions __tests__/samples/no-wrapper/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions src/build-scan-capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,29 @@ import org.gradle.util.GradleVersion
def isTopLevelBuild = gradle.getParent() == null
if (isTopLevelBuild) {
def version = GradleVersion.current().baseVersion
def atLeastGradle5 = version >= GradleVersion.version("5.0")
def atLeastGradle4 = version >= GradleVersion.version("4.0")
def atLeastGradle6 = version >= GradleVersion.version("6.0")
if (atLeastGradle6) {
settingsEvaluated { settings ->
if (settings.pluginManager.hasPlugin("com.gradle.enterprise")) {
registerCallbacks(settings.extensions["gradleEnterprise"], settings.rootProject.name)
registerCallbacks(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject.name)
}
}
} else if (atLeastGradle5) {
} else if (atLeastGradle4) {
projectsEvaluated { gradle ->
if (gradle.rootProject.pluginManager.hasPlugin("com.gradle.build-scan")) {
registerCallbacks(gradle.rootProject.extensions["gradleEnterprise"], gradle.rootProject.name)
registerCallbacks(gradle.rootProject.extensions["buildScan"], gradle.rootProject.name)
}
}
}
}
def registerCallbacks(gradleEnterprise, rootProjectName) {
gradleEnterprise.with {
buildScan {
def scanFile = new File("gradle-build-scan.txt")
buildScanPublished { buildScan ->
scanFile.text = buildScan.buildScanUri
}
def registerCallbacks(buildScanExtension, rootProjectName) {
buildScanExtension.with {
def scanFile = new File("gradle-build-scan.txt")
buildScanPublished { buildScan ->
scanFile.text = buildScan.buildScanUri
}
}
}
Expand Down

0 comments on commit c000a0b

Please sign in to comment.