From 11cc7c697d69eb5c0f955b7a2d26246c99748bb2 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 4 Feb 2024 11:08:41 +0100 Subject: [PATCH] github: workflowRunURL Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/context.test.ts | 6 ------ __tests__/github.test.ts | 6 ++++++ src/buildx/inputs.ts | 7 ++++--- src/github.ts | 4 ++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 94257c45..7833e00a 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -55,9 +55,3 @@ describe('gitContext', () => { expect(Context.gitContext()).toEqual('https://github.com/docker/actions-toolkit.git#refs/heads/master'); }); }); - -describe('provenanceBuilderID', () => { - it('returns 123', async () => { - expect(Context.provenanceBuilderID()).toEqual('https://github.com/docker/actions-toolkit/actions/runs/123'); - }); -}); diff --git a/__tests__/github.test.ts b/__tests__/github.test.ts index c065cca2..93d05027 100644 --- a/__tests__/github.test.ts +++ b/__tests__/github.test.ts @@ -89,6 +89,12 @@ describe('apiURL', () => { }); }); +describe('workflowRunURL', () => { + it('returns 123', async () => { + expect(GitHub.workflowRunURL).toEqual('https://github.com/docker/actions-toolkit/actions/runs/123'); + }); +}); + describe('actionsRuntimeToken', () => { const originalEnv = process.env; beforeEach(() => { diff --git a/src/buildx/inputs.ts b/src/buildx/inputs.ts index 1e1c4c04..b77c00b4 100644 --- a/src/buildx/inputs.ts +++ b/src/buildx/inputs.ts @@ -20,6 +20,7 @@ import * as core from '@actions/core'; import {parse} from 'csv-parse/sync'; import {Context} from '../context'; +import {GitHub} from '../github'; const parseKvp = (kvp: string): [string, string] => { const delimiterIndex = kvp.indexOf('='); @@ -111,7 +112,7 @@ export class Inputs { return input; } try { - return core.getBooleanInput(name) ? `builder-id=${Context.provenanceBuilderID()}` : 'false'; + return core.getBooleanInput(name) ? `builder-id=${GitHub.workflowRunURL}` : 'false'; } catch (err) { // not a valid boolean, so we assume it's a string return Inputs.resolveProvenanceAttrs(input); @@ -120,7 +121,7 @@ export class Inputs { public static resolveProvenanceAttrs(input: string): string { if (!input) { - return `builder-id=${Context.provenanceBuilderID()}`; + return `builder-id=${GitHub.workflowRunURL}`; } // parse attributes from input const fields = parse(input, { @@ -138,7 +139,7 @@ export class Inputs { } } // if not add builder-id attribute - return `${input},builder-id=${Context.provenanceBuilderID()}`; + return `${input},builder-id=${GitHub.workflowRunURL}`; } public static hasLocalExporter(exporters: string[]): boolean { diff --git a/src/github.ts b/src/github.ts index d49f0ac3..27d9a731 100644 --- a/src/github.ts +++ b/src/github.ts @@ -49,6 +49,10 @@ export class GitHub { return process.env.GITHUB_API_URL || 'https://api.github.com'; } + static get workflowRunURL(): string { + return `${GitHub.serverURL}/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`; + } + static get actionsRuntimeToken(): GitHubActionsRuntimeToken | undefined { const token = process.env['ACTIONS_RUNTIME_TOKEN'] || ''; return token ? (jwtDecode(token) as GitHubActionsRuntimeToken) : undefined;