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

Add retry plugin and related options #288

Merged
merged 11 commits into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .licenses/npm/@actions/github.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions .licenses/npm/@actions/http-client-1.0.11.dep.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .licenses/npm/@actions/http-client-2.0.1.dep.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .licenses/npm/@actions/http-client.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .licenses/npm/@octokit/core.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .licenses/npm/@octokit/plugin-retry.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions .licenses/npm/@octokit/request.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions .licenses/npm/bottleneck.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions __test__/get-retry-options.test.ts
@@ -0,0 +1,70 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import {getRetryOptions} from '../src/retry-options'

describe('getRequestOptions', () => {
test('retries disabled if retries == 0', async () => {
const [retryOptions, requestOptions] = getRetryOptions(0, 8, [
400,
500,
502
])

expect(retryOptions.enabled).toBe(false)
expect(retryOptions.doNotRetry).toBeFalsy()

expect(requestOptions.retries).toBeFalsy()
})

test('properties set if retries > 0', async () => {
const [retryOptions, requestOptions] = getRetryOptions(1, 8, [
400,
500,
502
])

expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])

expect(requestOptions.retries).toEqual(1)
expect(requestOptions.retryAfter).toEqual(8)
})

test('properties set if retries > 0', async () => {
const [retryOptions, requestOptions] = getRetryOptions(1, 8, [
400,
500,
502
])

expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])

expect(requestOptions.retries).toEqual(1)
expect(requestOptions.retryAfter).toEqual(8)
})

test('retryAfter can be set to zero', async () => {
const [retryOptions, requestOptions] = getRetryOptions(1, 0, [
400,
500,
502
])

expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])

expect(requestOptions.retries).toEqual(1)
expect(requestOptions.retryAfter).toEqual(0)
})

test('retryOptions.doNotRetry not set if doNotRetry isEmpty', async () => {
const [retryOptions, requestOptions] = getRetryOptions(1, 0, [])

expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toBeUndefined()

expect(requestOptions.retries).toEqual(1)
expect(requestOptions.retryAfter).toEqual(0)
})
})
11 changes: 10 additions & 1 deletion action.yml
Expand Up @@ -21,8 +21,17 @@ inputs:
previews:
description: A comma-separated list of API previews to accept
result-encoding:
description: Either "string" or "json" (default "json")—how the result will be encoded
description: Either "string" or "json" (default "json")—how the result will be encoded
default: json
retries:
description: "The number of times to retry a request"
default: "0"
retry-after:
description: "The number of seconds between retries. No effect unless `retries` is set."
luketomlinson marked this conversation as resolved.
Show resolved Hide resolved
default: "0"
luketomlinson marked this conversation as resolved.
Show resolved Hide resolved
do-not-retry:
luketomlinson marked this conversation as resolved.
Show resolved Hide resolved
description: "A comma separated list of status codes that will NOT be retried. Example: '400,500'. No effect unless `retries` is set."
luketomlinson marked this conversation as resolved.
Show resolved Hide resolved
default: ""
outputs:
result:
description: The return value of the script, stringified with `JSON.stringify`
Expand Down