Unverified Commit bc54cf57 authored by Daz DeBoer's avatar Daz DeBoer
Browse files

Support repo-registration as a second enablement path for project-entry caching

Configuration-cache store/restore is now enabled when EITHER a valid Develocity
JWT OR per-repo registration (a GitHub App installation that accepted the T&C) is
present. The gate itself lives in the vendored gradle-actions-caching library
(refreshed to 0.9.1); this repo wires up the reporting and notice.

- ProjectCacheStatus: 'trial-not-licensed' -> 'not-registered'.
- caching-report: render the 'not-registered' line with a /register link, and add
  renderProjectCacheNotice() for a prominent core.notice.
- setup-gradle: emit the notice from complete() only when withheld via the
  registration path; quiet when enabled by either path.
- Refresh vendored gradle-actions-caching to 0.9.1.

Co-Authored-By: default avatarClaude Opus 4.8 (1M context) <[email protected]>
parent b128da9b
Loading
Loading
Loading
Loading
+2 −2
Changes for sources/src/cache-service.ts: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -32,9 +32,9 @@ export type CacheCleanupStatus =
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
    | 'not-registered' // neither entitlement path satisfied (no Develocity trial token, repo not registered)
    | 'no-encryption-key' // Cannot store due to missing encryption key
    | 'enabled' // Trial in effect: will attempt to save project state
    | 'enabled' // Entitled: will attempt to save project state

export interface CacheEntryReport {
    entryName: string
+18 −1
Changes for sources/src/caching-report.ts: 18 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import {CacheCleanupStatus, CacheEntryReport, CacheReport, CacheStatus, ProjectC

const DOCS = 'https://github.com/gradle/actions/blob/main/docs/setup-gradle.md'
const DISTRIBUTION = 'https://github.com/gradle/actions/blob/main/DISTRIBUTION.md'
const REGISTER = 'https://gradle-actions-caching-registration.vercel.app/register'

/**
 * Identifies the caching provider in use, so the report can attribute the cache
@@ -31,7 +32,7 @@ const CLEANUP_COPY: Record<CacheCleanupStatus, string> = {
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.`,
    'not-registered': `Project state (build-logic and configuration cache) was not cached - this repository is not registered for advanced caching. [Register this repository](${REGISTER}), or provide a \`develocity-access-key\` and \`develocity-server-url\`.`,
    '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.`
}
@@ -82,6 +83,22 @@ function renderProjectCacheLine(projectCache?: ProjectCacheStatus): string | und
    return projectCache ? PROJECT_CACHE_COPY[projectCache] : undefined
}

/**
 * A plain-text log notice (no markdown) surfaced when advanced caching was withheld because the
 * repository is not registered. Returns `undefined` for every other status, so callers stay quiet
 * when the feature is enabled, disabled, or simply not opted in.
 */
export function renderProjectCacheNotice(projectCache?: ProjectCacheStatus): string | undefined {
    if (projectCache !== 'not-registered') {
        return undefined
    }
    return (
        'Advanced caching (build-logic and configuration cache) was not enabled: this repository ' +
        `is not registered. Register it at ${REGISTER}, or provide a develocity-access-key and ` +
        'develocity-server-url.'
    )
}

function renderProviderNote(providerNote?: ProviderNote): string | undefined {
    if (!providerNote) {
        return undefined
+9
Changes for sources/src/setup-gradle.ts: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import {setupToken} from './develocity/short-lived-token'

import {loadBuildResults, markBuildResultsProcessed} from './build-results'
import {getCacheService, getProviderNote} from './cache-service-loader'
import {renderProjectCacheNotice} from './caching-report'
import {CacheOptions} from './cache-service'
import {
    DevelocityConfig,
@@ -85,6 +86,14 @@ export async function complete(
        buildResults,
        cacheOptionsFrom(cacheConfig, develocityServerUrl, cacheToken)
    )

    // Surface a prominent notice (with the /register link) only when advanced caching was withheld
    // because the repo is not registered; stay quiet when enabled by either path.
    const registrationNotice = renderProjectCacheNotice(cacheReport.projectCache)
    if (registrationNotice) {
        core.notice(registrationNotice)
    }

    await jobSummary.generateJobSummary(buildResults, cacheReport, getProviderNote(cacheConfig), summaryConfig)

    markBuildResultsProcessed()
+32 −1
Changes for sources/test/jest/caching-report.test.ts: 32 added lines, 1 removed line.
Original line number Diff line number Diff line
import {describe, expect, it} from '@jest/globals'

import {CacheReport} from '../../src/cache-service'
import {renderCachingReport} from '../../src/caching-report'
import {renderCachingReport, renderProjectCacheNotice} from '../../src/caching-report'

const ENHANCED = {kind: 'enhanced'} as const
const BASIC = {kind: 'basic'} as const
@@ -114,6 +114,20 @@ describe('renderCachingReport', () => {
        expect(md).not.toContain('Project state')
    })

    it('renders the not-registered status with a /register link inside the details', () => {
        const report: CacheReport = {
            status: 'enabled',
            cleanup: 'enabled',
            projectCache: 'not-registered',
            entries: [entry()]
        }
        const md = renderCachingReport(report, ENHANCED)

        const detailsBody = md.slice(md.indexOf('</summary>'))
        expect(detailsBody).toContain('not registered for advanced caching')
        expect(detailsBody).toContain('/register')
    })

    it('renders a compact disabled report with no note and no details', () => {
        const report: CacheReport = {status: 'disabled', entries: []}
        const md = renderCachingReport(report, undefined)
@@ -143,3 +157,20 @@ describe('renderCachingReport', () => {
        expect(md).not.toContain('<details>')
    })
})

describe('renderProjectCacheNotice', () => {
    it('returns a notice with the /register link for the not-registered status', () => {
        const notice = renderProjectCacheNotice('not-registered')
        expect(notice).toBeDefined()
        expect(notice).toContain('not registered')
        expect(notice).toContain('/register')
    })

    it('is silent for every other status', () => {
        expect(renderProjectCacheNotice('enabled')).toBeUndefined()
        expect(renderProjectCacheNotice('not-enabled')).toBeUndefined()
        expect(renderProjectCacheNotice('trial-expired')).toBeUndefined()
        expect(renderProjectCacheNotice('no-encryption-key')).toBeUndefined()
        expect(renderProjectCacheNotice(undefined)).toBeUndefined()
    })
})
+3 −3
Changes for sources/vendor/gradle-actions-caching/index.d.ts: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -56,12 +56,12 @@ export declare type CacheStatus = 'enabled' | 'read-only' | 'write-only' | 'disa

/**
 * Status of project-entry caching (build-logic artifacts + configuration-cache data) for a run.
 * The first three are set on restore (always ungated); the rest are set on save and reflect the
 * two-tier gate (opt-in + Develocity trial, then encryption key + Gradle version). Still beta.
 * Set as the gate is evaluated: opt-in, then trial expiry, then entitlement (Develocity trial
 * license OR repo registration), then encryption key. Still beta.
 *
 * @public
 */
declare type ProjectCacheStatus = 'not-enabled' | 'trial-expired' | 'trial-not-licensed' | 'no-encryption-key' | 'enabled';
declare type ProjectCacheStatus = 'not-enabled' | 'trial-expired' | 'not-registered' | 'no-encryption-key' | 'enabled';

/** @public */
export declare function restore(gradleUserHome: string, cacheOptions: CacheOptions): Promise<void>;
Loading