Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4560e1

Browse filesBrowse files
authored
Merge pull request actions#288 from luketomlinson/main
Add retry plugin and related options
2 parents c713e51 + d742690 commit d4560e1
Copy full SHA for d4560e1

16 files changed

+4239
-2993
lines changed

‎.licenses/npm/@actions/github.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@actions/github.dep.yml
+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.licenses/npm/@actions/http-client-1.0.11.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@actions/http-client-1.0.11.dep.yml
-32
This file was deleted.

‎.licenses/npm/@actions/http-client-2.0.1.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@actions/http-client-2.0.1.dep.yml
-32
This file was deleted.

‎.licenses/npm/@actions/http-client.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@actions/http-client.dep.yml
+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.licenses/npm/@octokit/core.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@octokit/core.dep.yml
+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.licenses/npm/@octokit/plugin-retry.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@octokit/plugin-retry.dep.yml
+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.licenses/npm/@octokit/request.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@octokit/request.dep.yml
+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.licenses/npm/bottleneck.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/bottleneck.dep.yml
+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md

Copy file name to clipboardExpand all lines: README.md
+46-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
This action makes it easy to quickly write a script in your workflow that
88
uses the GitHub API and the workflow run context.
99

10-
To use this action, provide an input named `script` that contains the body of an asynchronous function call.
10+
To use this action, provide an input named `script` that contains the body of an asynchronous function call.
1111
The following arguments will be provided:
1212

1313
- `github` A pre-authenticated
@@ -83,6 +83,47 @@ output of a github-script step. For some workflows, string encoding is preferred
8383
script: return "I will be string (not JSON) encoded!"
8484
```
8585

86+
## Retries
87+
88+
By default, requests made with the `github` instance will not be retried. You can configure this with the `retries` option:
89+
90+
```yaml
91+
- uses: actions/github-script@v6
92+
id: my-script
93+
with:
94+
result-encoding: string
95+
retries: 3
96+
script: |
97+
github.rest.issues.get({
98+
issue_number: context.issue.number,
99+
owner: context.repo.owner,
100+
repo: context.repo.repo,
101+
})
102+
```
103+
104+
In this example, request failures from `github.rest.issues.get()` will be retried up to 3 times.
105+
106+
You can also configure which status codes should be exempt from retries via the `retry-exempt-status-codes` option:
107+
108+
```yaml
109+
- uses: actions/github-script@v6
110+
id: my-script
111+
with:
112+
result-encoding: string
113+
retries: 3
114+
retry-exempt-status-codes: 400,401
115+
script: |
116+
github.rest.issues.get({
117+
issue_number: context.issue.number,
118+
owner: context.repo.owner,
119+
repo: context.repo.repo,
120+
})
121+
```
122+
123+
By default, the following status codes will not be retried: `400, 401, 403, 404, 422` [(source)](https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14).
124+
125+
These retries are implemented using the [octokit/plugin-retry.js](https://github.com/octokit/plugin-retry.js) plugin. The retries use [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) to space out retries. ([source](https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/error-request.ts#L13))
126+
86127
## Examples
87128

88129
Note that `github-token` is optional in this action, and the input is there
@@ -354,8 +395,11 @@ jobs:
354395
To import an ESM file, you'll need to reference your script by an absolute path and ensure you have a `package.json` file with `"type": "module"` specified.
355396
356397
For a script in your repository `src/print-stuff.js`:
398+
357399
```js
358-
export default function printStuff() { console.log('stuff') }
400+
export default function printStuff() {
401+
console.log('stuff')
402+
}
359403
```
360404

361405
```yaml

‎__test__/get-retry-options.test.ts

Copy file name to clipboard
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
3+
import {getRetryOptions} from '../src/retry-options'
4+
5+
describe('getRequestOptions', () => {
6+
test('retries disabled if retries == 0', async () => {
7+
const [retryOptions, requestOptions] = getRetryOptions(0, [400, 500, 502])
8+
9+
expect(retryOptions.enabled).toBe(false)
10+
expect(retryOptions.doNotRetry).toBeFalsy()
11+
12+
expect(requestOptions.retries).toBeFalsy()
13+
})
14+
15+
test('properties set if retries > 0', async () => {
16+
const [retryOptions, requestOptions] = getRetryOptions(1, [400, 500, 502])
17+
18+
expect(retryOptions.enabled).toBe(true)
19+
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])
20+
21+
expect(requestOptions.retries).toEqual(1)
22+
})
23+
24+
test('properties set if retries > 0', async () => {
25+
const [retryOptions, requestOptions] = getRetryOptions(1, [400, 500, 502])
26+
27+
expect(retryOptions.enabled).toBe(true)
28+
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])
29+
30+
expect(requestOptions.retries).toEqual(1)
31+
})
32+
33+
test('retryOptions.doNotRetry not set if exemptStatusCodes isEmpty', async () => {
34+
const [retryOptions, requestOptions] = getRetryOptions(1, [])
35+
36+
expect(retryOptions.enabled).toBe(true)
37+
expect(retryOptions.doNotRetry).toBeUndefined()
38+
39+
expect(requestOptions.retries).toEqual(1)
40+
})
41+
})

‎action.yml

Copy file name to clipboardExpand all lines: action.yml
+7-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ inputs:
2121
previews:
2222
description: A comma-separated list of API previews to accept
2323
result-encoding:
24-
description: Either "string" or "json" (default "json")—how the result will be encoded
24+
description: Either "string" or "json" (default "json")—how the result will be encoded
2525
default: json
26+
retries:
27+
description: The number of times to retry a request
28+
default: "0"
29+
retry-exempt-status-codes:
30+
description: A comma separated list of status codes that will NOT be retried e.g. "400,500". No effect unless `retries` is set
31+
default: 400,401,403,404,422 # from https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
2632
outputs:
2733
result:
2834
description: The return value of the script, stringified with `JSON.stringify`

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.