Skip to content

Commit d4560e1

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

16 files changed

+4239
-2993
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 32 deletions
This file was deleted.

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

Lines changed: 0 additions & 32 deletions
This file was deleted.

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

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/npm/bottleneck.dep.yml

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 46 additions & 2 deletions
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

Lines changed: 41 additions & 0 deletions
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+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy