mirror of
https://code.forgejo.org/docker/actions-toolkit.git
synced 2025-06-25 07:08:22 -04:00
github: workflowRunURL
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
26949f5f39
commit
11cc7c697d
4 changed files with 14 additions and 9 deletions
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue