Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github: workflowRunURL #245

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
6 changes: 6 additions & 0 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
7 changes: 4 additions & 3 deletions src/buildx/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('=');
Expand Down Expand Up @@ -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);
Expand All @@ -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, {
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JwtPayload>(token) as GitHubActionsRuntimeToken) : undefined;
Expand Down
Loading