Skip to content

Commit

Permalink
Merge pull request #245 from crazy-max/gh-workflow-run-url
Browse files Browse the repository at this point in the history
github: workflowRunURL
  • Loading branch information
crazy-max committed Feb 4, 2024
2 parents 26949f5 + 11cc7c6 commit 012b121
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
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

0 comments on commit 012b121

Please sign in to comment.