Skip to content

Commit

Permalink
Merge pull request #346 from crazy-max/gh-workflow-run-retries
Browse files Browse the repository at this point in the history
github: set attempts to workflowRunURL
  • Loading branch information
crazy-max committed May 28, 2024
2 parents d344961 + 760d0c2 commit 2941f52
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion __mocks__/@actions/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const context = {
repo: 'actions-toolkit'
},
ref: 'refs/heads/master',
runId: 123,
runId: 2188748038,
runNumber: 15,
payload: {
after: '860c1904a1ce19322e91ac35af1ab07466440c37',
base_ref: null,
Expand Down
12 changes: 6 additions & 6 deletions __tests__/buildx/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ describe('getProvenanceInput', () => {
test.each([
[
'true',
'builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
'builder-id=https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2'
],
[
'false',
'false'
],
[
'mode=min',
'mode=min,builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
'mode=min,builder-id=https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2'
],
[
'mode=max',
'mode=max,builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
'mode=max,builder-id=https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2'
],
[
'builder-id=foo',
Expand All @@ -137,11 +137,11 @@ describe('resolveProvenanceAttrs', () => {
test.each([
[
'mode=min',
'mode=min,builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
'mode=min,builder-id=https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2'
],
[
'mode=max',
'mode=max,builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
'mode=max,builder-id=https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2'
],
[
'builder-id=foo',
Expand All @@ -153,7 +153,7 @@ describe('resolveProvenanceAttrs', () => {
],
[
'',
'builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
'builder-id=https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2'
],
])('given %p', async (input: string, expected: string) => {
expect(Build.resolveProvenanceAttrs(input)).toEqual(expected);
Expand Down
4 changes: 2 additions & 2 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ describe('apiURL', () => {
});

describe('workflowRunURL', () => {
it('returns 123', async () => {
expect(GitHub.workflowRunURL).toEqual('https://github.com/docker/actions-toolkit/actions/runs/123');
it('returns 2188748038', async () => {
expect(GitHub.workflowRunURL).toEqual('https://github.com/docker/actions-toolkit/actions/runs/2188748038/attempts/2');
});
});

Expand Down
3 changes: 3 additions & 0 deletions jest.config.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-actions-toolkit-'))
process.env = Object.assign({}, process.env, {
TEMP: tmpDir,
GITHUB_REPOSITORY: 'docker/actions-toolkit',
GITHUB_RUN_ATTEMPT: 2,
GITHUB_RUN_ID: 2188748038,
GITHUB_RUN_NUMBER: 15,
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
}) as {
Expand Down
3 changes: 3 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-actions-toolkit-'))
process.env = Object.assign({}, process.env, {
TEMP: tmpDir,
GITHUB_REPOSITORY: 'docker/actions-toolkit',
GITHUB_RUN_ATTEMPT: 2,
GITHUB_RUN_ID: 2188748038,
GITHUB_RUN_NUMBER: 15,
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
}) as {
Expand Down
4 changes: 3 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export class GitHub {
}

static get workflowRunURL(): string {
return `${GitHub.serverURL}/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`;
const runID = process.env.GITHUB_RUN_ID || github.context.runId;
const runAttempt = process.env.GITHUB_RUN_ATTEMPT || 1;
return `${GitHub.serverURL}/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${runID}/attempts/${runAttempt}`;
}

static get actionsRuntimeToken(): GitHubActionsRuntimeToken | undefined {
Expand Down

0 comments on commit 2941f52

Please sign in to comment.