Skip to content

Commit ee6e7bb

Browse files
authored
Merge pull request #358 from crazy-max/fix-workflow-run
github: make attempts optional in workflowRunURL
2 parents 1bf4b58 + fe58cc2 commit ee6e7bb

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

__tests__/github.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ describe('repository', () => {
9797

9898
describe('workflowRunURL', () => {
9999
it('returns 2188748038', async () => {
100-
expect(GitHub.workflowRunURL).toEqual('https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2');
100+
expect(GitHub.workflowRunURL()).toEqual('https://github.com/docker/actions-toolkit/actions/runs/2188748038');
101+
});
102+
it('returns 2188748038 with attempts 2', async () => {
103+
expect(GitHub.workflowRunURL(true)).toEqual('https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2');
101104
});
102105
});
103106

src/buildx/build.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class Build {
131131
return input;
132132
}
133133
try {
134-
return core.getBooleanInput(name) ? `builder-id=${GitHub.workflowRunURL}` : 'false';
134+
return core.getBooleanInput(name) ? `builder-id=${GitHub.workflowRunURL(true)}` : 'false';
135135
} catch (err) {
136136
// not a valid boolean, so we assume it's a string
137137
return Build.resolveProvenanceAttrs(input);
@@ -140,7 +140,7 @@ export class Build {
140140

141141
public static resolveProvenanceAttrs(input: string): string {
142142
if (!input) {
143-
return `builder-id=${GitHub.workflowRunURL}`;
143+
return `builder-id=${GitHub.workflowRunURL(true)}`;
144144
}
145145
// parse attributes from input
146146
const fields = parse(input, {
@@ -158,7 +158,7 @@ export class Build {
158158
}
159159
}
160160
// if not add builder-id attribute
161-
return `${input},builder-id=${GitHub.workflowRunURL}`;
161+
return `${input},builder-id=${GitHub.workflowRunURL(true)}`;
162162
}
163163

164164
public static resolveCacheToAttrs(input: string, githubToken?: string): string {

src/github.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ export class GitHub {
6868
return `${github.context.repo.owner}/${github.context.repo.repo}`;
6969
}
7070

71-
static get workflowRunURL(): string {
72-
const runID = process.env.GITHUB_RUN_ID || github.context.runId;
73-
const runAttempt = process.env.GITHUB_RUN_ATTEMPT || 1;
74-
return `${GitHub.serverURL}/${GitHub.repository}/actions/runs/${runID}/attempts/${runAttempt}`;
71+
public static workflowRunURL(setAttempts?: boolean): string {
72+
// TODO: runAttempt is not yet part of github.context but will be in a
73+
// future release of @actions/github package: https://github.com/actions/toolkit/commit/faa425440f86f9c16587a19dfb59491253a2c92a
74+
return `${GitHub.serverURL}/${GitHub.repository}/actions/runs/${github.context.runId}${setAttempts ? `/attempts/${process.env.GITHUB_RUN_ATTEMPT || 1}` : ''}`;
7575
}
7676

7777
static get actionsRuntimeToken(): GitHubActionsRuntimeToken | undefined {
@@ -191,7 +191,7 @@ export class GitHub {
191191
const artifactId = BigInt(finalizeArtifactResp.artifactId);
192192
core.info(`Artifact successfully finalized (${artifactId})`);
193193

194-
const artifactURL = `${GitHub.workflowRunURL}/artifacts/${artifactId}`;
194+
const artifactURL = `${GitHub.workflowRunURL()}/artifacts/${artifactId}`;
195195
core.info(`Artifact download URL: ${artifactURL}`);
196196

197197
return {

0 commit comments

Comments
 (0)