From d97d29c992b84b5a38722fd8be6f2cb1ceb334ab Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Mon, 29 Jun 2026 11:10:06 -0600 Subject: [PATCH] Include repo identity in the /register link The not-registered job-summary link and the core.notice pointed at the bare /register URL, so the page replied 'owner and repo are required'. Append ?owner=&repo= from GITHUB_REPOSITORY so the backend can resolve the installation. Co-Authored-By: Claude Opus 4.8 (1M context) --- sources/src/caching-report.ts | 31 +++++++++++++--- sources/test/jest/caching-report.test.ts | 46 +++++++++++++++--------- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/sources/src/caching-report.ts b/sources/src/caching-report.ts index 3889dd11..c97d3875 100644 --- a/sources/src/caching-report.ts +++ b/sources/src/caching-report.ts @@ -2,7 +2,21 @@ 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://actions-caching-registration.vercel.app/register' +const REGISTER_BASE = 'https://actions-caching-registration.vercel.app/register' + +/** + * The `/register` link with the current repo's identity appended, so the backend can resolve the + * installation and route to acceptance. Repo identity comes from `GITHUB_REPOSITORY` (`owner/repo`), + * set by the runner; falls back to the bare link if it is somehow unavailable. + */ +function registerUrl(): string { + const repository = process.env.GITHUB_REPOSITORY + if (!repository?.includes('/')) { + return REGISTER_BASE + } + const [owner, repo] = repository.split('/') + return `${REGISTER_BASE}?${new URLSearchParams({owner, repo}).toString()}` +} /** * Identifies the caching provider in use, so the report can attribute the cache @@ -29,10 +43,11 @@ const CLEANUP_COPY: Record = { 'disabled-readonly': `[Cache cleanup](${DOCS}#configuring-cache-cleanup) is always disabled when the cache is read-only.` } -const PROJECT_CACHE_COPY: Record = { +// 'not-registered' is rendered dynamically (see renderProjectCacheLine) because its /register link +// carries the repo identity, so it is intentionally absent from this static map. +const PROJECT_CACHE_COPY: Record, string> = { 'not-enabled': ``, 'trial-expired': `Project state (build-logic and configuration cache) was not cached - the Develocity caching trial has expired.`, - '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.` } @@ -79,8 +94,14 @@ function renderCleanupLine(cleanup?: CacheCleanupStatus): string | undefined { } function renderProjectCacheLine(projectCache?: ProjectCacheStatus): string | undefined { + if (!projectCache) { + return undefined + } + if (projectCache === 'not-registered') { + return `Project state (build-logic and configuration cache) was not cached - this repository is not registered for advanced caching. [Register this repository](${registerUrl()}), or provide a \`develocity-access-key\` and \`develocity-server-url\`.` + } // PROJECT_CACHE_COPY['not-enabled'] is '', which the .filter(Boolean) at the call site drops. - return projectCache ? PROJECT_CACHE_COPY[projectCache] : undefined + return PROJECT_CACHE_COPY[projectCache] } /** @@ -94,7 +115,7 @@ export function renderProjectCacheNotice(projectCache?: ProjectCacheStatus): str } 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 ` + + `is not registered. Register it at ${registerUrl()}, or provide a develocity-access-key and ` + 'develocity-server-url.' ) } diff --git a/sources/test/jest/caching-report.test.ts b/sources/test/jest/caching-report.test.ts index 80188ad4..825dcd78 100644 --- a/sources/test/jest/caching-report.test.ts +++ b/sources/test/jest/caching-report.test.ts @@ -114,18 +114,25 @@ 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) + it('renders the not-registered status with a repo-scoped /register link inside the details', () => { + const saved = process.env.GITHUB_REPOSITORY + process.env.GITHUB_REPOSITORY = 'acme/widgets' + try { + const report: CacheReport = { + status: 'enabled', + cleanup: 'enabled', + projectCache: 'not-registered', + entries: [entry()] + } + const md = renderCachingReport(report, ENHANCED) - const detailsBody = md.slice(md.indexOf('')) - expect(detailsBody).toContain('not registered for advanced caching') - expect(detailsBody).toContain('/register') + const detailsBody = md.slice(md.indexOf('')) + expect(detailsBody).toContain('not registered for advanced caching') + expect(detailsBody).toContain('/register?owner=acme&repo=widgets') + } finally { + if (saved === undefined) delete process.env.GITHUB_REPOSITORY + else process.env.GITHUB_REPOSITORY = saved + } }) it('renders a compact disabled report with no note and no details', () => { @@ -159,11 +166,18 @@ describe('renderCachingReport', () => { }) 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('returns a notice with a repo-scoped /register link for the not-registered status', () => { + const saved = process.env.GITHUB_REPOSITORY + process.env.GITHUB_REPOSITORY = 'acme/widgets' + try { + const notice = renderProjectCacheNotice('not-registered') + expect(notice).toBeDefined() + expect(notice).toContain('not registered') + expect(notice).toContain('/register?owner=acme&repo=widgets') + } finally { + if (saved === undefined) delete process.env.GITHUB_REPOSITORY + else process.env.GITHUB_REPOSITORY = saved + } }) it('is silent for every other status', () => {