Unverified Commit 60c43cb5 authored by daz's avatar daz
Browse files

Make it easy to publish to scans.gradle.com

- Allow init-script to publish to scans.gradle.com
- Add paramaters to enable build scan publishing
- Test coverage for build scan publishing
parent 75b3db10
Loading
Loading
Loading
Loading
+40 −3
Changes for .github/workflows/integ-test-inject-develocity.yml: 40 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -19,14 +19,15 @@ env:
  DOWNLOAD_DIST: ${{ inputs.download-dist }}
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: provision-gradle-versions-${{ inputs.cache-key-prefix }}
  GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true

jobs:
  inject-develocity:
    env:
      DEVELOCITY_INJECTION_ENABLED: true
      DEVELOCITY_URL: https://ge.solutions-team.gradle.com
      DEVELOCITY_PLUGIN_VERSION: 3.16.1
      DEVELOCITY_CCUD_PLUGIN_VERSION: 1.12.1
      GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} # This env var has not (yet) been renamed/aliased in GE plugin 3.16.1

jobs:
  inject-develocity:
    strategy:
      matrix:
        gradle: [current, 7.6.2, 6.9.4, 5.6.4]
@@ -58,3 +59,39 @@ jobs:
      with:
        script: |
          core.setFailed('No Build Scan detected')   

  build-scan-publish:
    strategy:
      matrix:
        gradle: [current, 7.6.2, 6.9.4, 5.6.4]
    runs-on: ubuntu-latest
    steps:
    - name: Checkout sources
      uses: actions/checkout@v4
    - name: Download distribution if required
      uses: ./.github/actions/download-dist
    - name: Setup Java
      uses: actions/setup-java@v4
      with:
        distribution: temurin
        java-version: 8
    - name: Setup Gradle
      id: setup-gradle
      uses: ./
      with:
        cache-read-only: false # For testing, allow writing cache entries on non-default branches
        gradle-version: ${{ matrix.gradle }}
        build-scan-publish: true
        build-scan-terms-of-service-url: "https://gradle.com/terms-of-service"
        build-scan-terms-of-service-agree: "yes"
    - name: Run Gradle build
      id: gradle
      working-directory: .github/workflow-samples/no-ge
      run: gradle help
    - name: Check Build Scan url
      if: ${{ !steps.gradle.outputs.build-scan-url }}
      uses: actions/github-script@v7
      with:
        script: |
          core.setFailed('No Build Scan detected')   
+15
Changes for action.yml: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -82,6 +82,21 @@ inputs:
    description: Specifies the number of days to retain any artifacts generated by the action. If not set, the default retention settings for the repository will apply.
    required: false

  build-scan-publish:
    description: |
      Set to 'true' to automatically publish build results as a Build Scan on scans.gradle.com.
      For publication to succeed without user input, you must also provide values for `build-scan-terms-of-service-url` and 'build-scan-terms-of-service-agree'.
    required: false
    default: false

  build-scan-terms-of-service-url:
    description: The URL to the Build Scan® terms of service. This input must be set to 'https://gradle.com/terms-of-service'.
    required: false
  
  build-scan-terms-of-service-agree:
    description: Indicate that you agree to the Build Scan® terms of service. This input value must be "yes".
    required: false

  # DEPRECATED ACTION INPUTS
  arguments:
    description: Gradle command line arguments (supports multi-line input)
+33
Changes for src/build-scan.ts: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
import * as core from '@actions/core'
import {
    getBuildScanPublishEnabled,
    getBuildScanTermsOfServiceUrl,
    getBuildScanTermsOfServiceAgree
} from './input-params'

export function setup(): void {
    if (getBuildScanPublishEnabled() && verifyTermsOfServiceAgreement()) {
        maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true')
        maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.1')
        maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.12.1')
        maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_URL', getBuildScanTermsOfServiceUrl())
        maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_AGREE', getBuildScanTermsOfServiceAgree())
    }
}

function verifyTermsOfServiceAgreement(): boolean {
    if (
        getBuildScanTermsOfServiceUrl() !== 'https://gradle.com/terms-of-service' ||
        getBuildScanTermsOfServiceAgree() !== 'yes'
    ) {
        core.warning(`Terms of service must be agreed in order to publish build scans.`)
        return false
    }
    return true
}

function maybeExportVariable(variableName: string, value: unknown): void {
    if (!process.env[variableName]) {
        core.exportVariable(variableName, value)
    }
}
+12
Changes for src/input-params.ts: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -75,6 +75,18 @@ export function getPRCommentOption(): JobSummaryOption {
    return parseJobSummaryOption('add-job-summary-as-pr-comment')
}

export function getBuildScanPublishEnabled(): boolean {
    return getBooleanInput('build-scan-publish')
}

export function getBuildScanTermsOfServiceUrl(): string {
    return core.getInput('build-scan-terms-of-service-url')
}

export function getBuildScanTermsOfServiceAgree(): string {
    return core.getInput('build-scan-terms-of-service-agree')
}

function parseJobSummaryOption(paramName: string): JobSummaryOption {
    const val = core.getInput(paramName)
    switch (val.toLowerCase().trim()) {
+14 −2
Changes for src/resources/init-scripts/gradle-build-action.inject-develocity.init.gradle: 14 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ def geEnforceUrl = Boolean.parseBoolean(getInputParam('develocity.enforce-url'))
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam('develocity.build-scan.upload-in-background'))
def gePluginVersion = getInputParam('develocity.plugin.version')
def ccudPluginVersion = getInputParam('develocity.ccud-plugin.version')
def buildScanTermsOfServiceUrl = getInputParam('build-scan.terms-of-service.url')
def buildScanTermsOfServiceAgree = getInputParam('build-scan.terms-of-service.agree')

def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')

@@ -103,10 +105,15 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
                }
                if (!scanPluginComponent) {
                    logger.quiet("Applying $BUILD_SCAN_PLUGIN_CLASS via init script")
                    logger.quiet("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer")
                    applyPluginExternally(pluginManager, BUILD_SCAN_PLUGIN_CLASS)
                    if (geUrl) {
                        logger.quiet("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer")
                        buildScan.server = geUrl
                        buildScan.allowUntrustedServer = geAllowUntrustedServer
                    } else if (buildScanTermsOfServiceUrl && buildScanTermsOfServiceAgree) {
                        buildScan.termsOfServiceUrl = buildScanTermsOfServiceUrl
                        buildScan.termsOfServiceAgree = buildScanTermsOfServiceAgree
                    }
                    buildScan.publishAlways()
                    if (buildScan.metaClass.respondsTo(buildScan, 'setUploadInBackground', Boolean)) buildScan.uploadInBackground = buildScanUploadInBackground  // uploadInBackground not available for build-scan-plugin 1.16
                    buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, CI_AUTO_INJECTION_CUSTOM_VALUE_VALUE
@@ -139,11 +146,16 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
        if (gePluginVersion) {
            if (!settings.pluginManager.hasPlugin(DEVELOCITY_PLUGIN_ID)) {
                logger.quiet("Applying $DEVELOCITY_PLUGIN_CLASS via init script")
                logger.quiet("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer")
                applyPluginExternally(settings.pluginManager, DEVELOCITY_PLUGIN_CLASS)
                extensionsWithPublicType(settings, DEVELOCITY_EXTENSION_CLASS).collect { settings[it.name] }.each { ext ->
                    if (geUrl) {
                        logger.quiet("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer")
                        ext.server = geUrl
                        ext.allowUntrustedServer = geAllowUntrustedServer
                    } else if (buildScanTermsOfServiceUrl && buildScanTermsOfServiceAgree) {
                        ext.buildScan.termsOfServiceUrl = buildScanTermsOfServiceUrl
                        ext.buildScan.termsOfServiceAgree = buildScanTermsOfServiceAgree
                    }
                    ext.buildScan.publishAlways()
                    ext.buildScan.uploadInBackground = buildScanUploadInBackground
                    ext.buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, CI_AUTO_INJECTION_CUSTOM_VALUE_VALUE
Loading