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

Support experimental project-entry caching (configuration-cache + build-logic) (#994)

Pass develocityAccessToken and develocityServerUrl the
`gradle-actions-caching`: required to support project-entry caching
(build-logic + configuration-cache), which has experimental support in
'[email protected]. This support is not yet released and will
be available as a restricted trial.

---------

Co-authored-by: default avatarClaude Opus 4.8 (1M context) <[email protected]>
parent bbaaec0d
Loading
Loading
Loading
Loading
+2 −2
Changes for sources/src/actions/dependency-submission/post.ts: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
import * as setupGradle from '../../setup-gradle'

import {CacheConfig, SummaryConfig} from '../../configuration'
import {CacheConfig, DevelocityConfig, SummaryConfig} from '../../configuration'
import {handlePostActionError} from '../../errors'
import {forceExit} from '../../force-exit'

@@ -14,7 +14,7 @@ process.on('uncaughtException', e => handlePostActionError(e))
 */
export async function run(): Promise<void> {
    try {
        await setupGradle.complete(new CacheConfig(), new SummaryConfig())
        await setupGradle.complete(new CacheConfig(), new DevelocityConfig(), new SummaryConfig())
    } catch (error) {
        handlePostActionError(error)
    }
+2 −2
Changes for sources/src/actions/setup-gradle/post.ts: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
import * as setupGradle from '../../setup-gradle'
import * as dependencyGraph from '../../dependency-graph'

import {CacheConfig, DependencyGraphConfig, SummaryConfig} from '../../configuration'
import {CacheConfig, DependencyGraphConfig, DevelocityConfig, SummaryConfig} from '../../configuration'
import {handlePostActionError} from '../../errors'
import {emitDeprecationWarnings, restoreDeprecationState} from '../../deprecation-collector'
import {forceExit} from '../../force-exit'
@@ -19,7 +19,7 @@ export async function run(): Promise<void> {
        restoreDeprecationState()
        emitDeprecationWarnings()

        if (await setupGradle.complete(new CacheConfig(), new SummaryConfig())) {
        if (await setupGradle.complete(new CacheConfig(), new DevelocityConfig(), new SummaryConfig())) {
            // Only submit the dependency graphs once per job
            await dependencyGraph.complete(new DependencyGraphConfig())
        }
+9 −2
Changes for sources/src/cache-service.ts: 9 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ export interface CacheOptions {
    strictMatch: boolean
    cleanup: string
    encryptionKey?: string
    develocityAccessToken?: string
    develocityServerUrl?: string
    includes: string[]
    excludes: string[]
}
@@ -27,7 +29,12 @@ export type CacheCleanupStatus =
    | 'disabled-config-cache-hit'
    | 'disabled-readonly'

export type ConfigurationCacheStatus = 'not-active' | 'restored' | 'not-restored' | 'restore-incomplete'
export type ProjectCacheStatus =
    | 'not-enabled' // the hidden opt-in env var was not set (rendered as nothing)
    | 'trial-expired' // past the hard trial expiry
    | 'trial-not-licensed' // Develocity trial token missing or invalid
    | 'no-encryption-key' // Cannot store due to missing encryption key
    | 'enabled' // Trial in effect: will attempt to save project state

export interface CacheEntryReport {
    entryName: string
@@ -49,7 +56,7 @@ export interface CacheEntryReport {
export interface CacheReport {
    status: CacheStatus
    cleanup?: CacheCleanupStatus
    configurationCache?: ConfigurationCacheStatus
    projectCache?: ProjectCacheStatus
    entries: CacheEntryReport[]
}

+12 −10
Changes for sources/src/caching-report.ts: 12 added lines, 10 removed lines.
Original line number Diff line number Diff line
import {CacheCleanupStatus, CacheEntryReport, CacheReport, CacheStatus, ConfigurationCacheStatus} from './cache-service'
import {CacheCleanupStatus, CacheEntryReport, CacheReport, CacheStatus, ProjectCacheStatus} from './cache-service'

const DOCS = 'https://github.com/gradle/actions/blob/main/docs/setup-gradle.md'
const DISTRIBUTION = 'https://github.com/gradle/actions/blob/main/DISTRIBUTION.md'
@@ -28,11 +28,12 @@ const CLEANUP_COPY: Record<CacheCleanupStatus, string> = {
    'disabled-readonly': `[Cache cleanup](${DOCS}#configuring-cache-cleanup) is always disabled when the cache is read-only.`
}

const CONFIG_CACHE_COPY: Record<ConfigurationCacheStatus, string> = {
    'not-active': `Configuration cache state was not cached — set a [cache-encryption-key](${DOCS}#cache-encryption-key) to enable configuration-cache caching.`,
    restored: `Configuration cache state was restored from the cache.`,
    'not-restored': `Configuration cache state was not restored — no cached data was available (e.g. the first run for this cache key).`,
    'restore-incomplete': `Configuration cache state was not restored — the Gradle User Home was not fully restored.`
const PROJECT_CACHE_COPY: Record<ProjectCacheStatus, string> = {
    'not-enabled': ``,
    'trial-expired': `Project state (build-logic and configuration cache) was not cached - the Develocity caching trial has expired.`,
    'trial-not-licensed': `Project state (build-logic and configuration cache) was not cached - a develocity-access-key and develocity-server-url is required.`,
    'no-encryption-key': `Project state (build-logic and configuration cache) was not cached - a [cache-encryption-key](${DOCS}#cache-encryption-key) is required.`,
    enabled: `Caching of project state (build-logic and configuration cache) was enabled.`
}

/**
@@ -76,8 +77,9 @@ function renderCleanupLine(cleanup?: CacheCleanupStatus): string | undefined {
    return cleanup ? CLEANUP_COPY[cleanup] : undefined
}

function renderConfigCacheLine(configurationCache?: ConfigurationCacheStatus): string | undefined {
    return configurationCache ? CONFIG_CACHE_COPY[configurationCache] : undefined
function renderProjectCacheLine(projectCache?: ProjectCacheStatus): string | undefined {
    // PROJECT_CACHE_COPY['not-enabled'] is '', which the .filter(Boolean) at the call site drops.
    return projectCache ? PROJECT_CACHE_COPY[projectCache] : undefined
}

function renderProviderNote(providerNote?: ProviderNote): string | undefined {
@@ -99,10 +101,10 @@ function renderDetails(report: CacheReport): string {
        : `Entries: ${restored} restored, ${saved} saved - Expand for more details`

    const cleanup = report.status === 'enabled' ? renderCleanupLine(report.cleanup) : undefined
    const configCache = renderConfigCacheLine(report.configurationCache)
    const projectCache = renderProjectCacheLine(report.projectCache)
    const table = renderEntryTable(report.entries)
    const pre = `<pre>\n${renderEntryDetails(report.entries)}</pre>`
    const body = [STATUS_COPY[report.status], cleanup, configCache, table, pre].filter(Boolean).join('\n\n')
    const body = [STATUS_COPY[report.status], cleanup, projectCache, table, pre].filter(Boolean).join('\n\n')

    return `<details>
<summary>${summary}</summary>
+1 −8
Changes for sources/src/develocity/build-scan.ts: 1 added line, 8 removed lines.
Original line number Diff line number Diff line
import * as core from '@actions/core'
import {DevelocityConfig} from '../configuration'
import {setupToken} from './short-lived-token'

export async function setup(config: DevelocityConfig): Promise<void> {
export function setup(config: DevelocityConfig): void {
    maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle')
    maybeExportVariable('DEVELOCITY_INJECTION_CUSTOM_VALUE', 'gradle-actions')

@@ -39,12 +38,6 @@ export async function setup(config: DevelocityConfig): Promise<void> {
        maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_URL', config.getTermsOfUseUrl())
        maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_AGREE', config.getTermsOfUseAgree())
    }

    return setupToken(
        config.getDevelocityAccessKey(),
        config.getDevelocityAllowUntrustedServer(),
        config.getDevelocityTokenExpiry()
    )
}

function maybeExportVariable(variableName: string, value: unknown): void {
Loading