Add retry plugin

This commit is contained in:
Luke Tomlinson 2022-09-19 16:03:23 -04:00
parent c713e510db
commit 355d8955d8
5 changed files with 2551 additions and 1449 deletions

View file

@ -21,8 +21,17 @@ inputs:
previews: previews:
description: A comma-separated list of API previews to accept description: A comma-separated list of API previews to accept
result-encoding: 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 default: json
retries:
description: "The number of times to retry a request"
default: "0"
retry-after:
description: "The number of seconds between retries"
default: "0"
do-not-retry:
description: "A comma separated list of status codes that will NOT be retried. Example: '400,500'"
default: ""
outputs: outputs:
result: result:
description: The return value of the script, stringified with `JSON.stringify` description: The return value of the script, stringified with `JSON.stringify`

3814
dist/index.js vendored

File diff suppressed because it is too large Load diff

125
package-lock.json generated
View file

@ -16,7 +16,8 @@
"@actions/io": "^1.1.1", "@actions/io": "^1.1.1",
"@octokit/core": "^3.5.1", "@octokit/core": "^3.5.1",
"@octokit/plugin-paginate-rest": "^2.17.0", "@octokit/plugin-paginate-rest": "^2.17.0",
"@octokit/plugin-rest-endpoint-methods": "^6.3.0" "@octokit/plugin-rest-endpoint-methods": "^6.3.0",
"@octokit/plugin-retry": "^3.0.9"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
@ -42,14 +43,6 @@
"uuid": "^8.3.2" "uuid": "^8.3.2"
} }
}, },
"node_modules/@actions/core/node_modules/@actions/http-client": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"dependencies": {
"tunnel": "^0.0.6"
}
},
"node_modules/@actions/exec": { "node_modules/@actions/exec": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.0.tgz",
@ -59,14 +52,14 @@
} }
}, },
"node_modules/@actions/github": { "node_modules/@actions/github": {
"version": "5.0.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/@actions/github/-/github-5.0.0.tgz", "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.0.tgz",
"integrity": "sha512-QvE9eAAfEsS+yOOk0cylLBIO/d6WyWIOvsxxzdrPFaud39G6BOkUwScXZn1iBzQzHyu9SBkkLSWlohDWdsasAQ==", "integrity": "sha512-tuI80F7JQIhg77ZTTgUAPpVD7ZnP9oHSPN8xw7LOwtA4vEMbAjWJNbmLBfV7xua7r016GyjzWLuec5cs8f/a8A==",
"dependencies": { "dependencies": {
"@actions/http-client": "^1.0.11", "@actions/http-client": "^2.0.1",
"@octokit/core": "^3.4.0", "@octokit/core": "^3.6.0",
"@octokit/plugin-paginate-rest": "^2.13.3", "@octokit/plugin-paginate-rest": "^2.17.0",
"@octokit/plugin-rest-endpoint-methods": "^5.1.1" "@octokit/plugin-rest-endpoint-methods": "^5.13.0"
} }
}, },
"node_modules/@actions/github/node_modules/@octokit/plugin-rest-endpoint-methods": { "node_modules/@actions/github/node_modules/@octokit/plugin-rest-endpoint-methods": {
@ -91,11 +84,11 @@
} }
}, },
"node_modules/@actions/http-client": { "node_modules/@actions/http-client": {
"version": "1.0.11", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==", "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"dependencies": { "dependencies": {
"tunnel": "0.0.6" "tunnel": "^0.0.6"
} }
}, },
"node_modules/@actions/io": { "node_modules/@actions/io": {
@ -1081,13 +1074,13 @@
} }
}, },
"node_modules/@octokit/core": { "node_modules/@octokit/core": {
"version": "3.5.1", "version": "3.6.0",
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.5.1.tgz", "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz",
"integrity": "sha512-omncwpLVxMP+GLpLPgeGJBF6IWJFjXDS5flY5VbppePYX9XehevbDykRH9PdCdvqt9TS5AOTiDide7h0qrkHjw==", "integrity": "sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==",
"dependencies": { "dependencies": {
"@octokit/auth-token": "^2.4.4", "@octokit/auth-token": "^2.4.4",
"@octokit/graphql": "^4.5.8", "@octokit/graphql": "^4.5.8",
"@octokit/request": "^5.6.0", "@octokit/request": "^5.6.3",
"@octokit/request-error": "^2.0.5", "@octokit/request-error": "^2.0.5",
"@octokit/types": "^6.0.3", "@octokit/types": "^6.0.3",
"before-after-hook": "^2.2.0", "before-after-hook": "^2.2.0",
@ -1158,16 +1151,25 @@
"@octokit/openapi-types": "^13.1.0" "@octokit/openapi-types": "^13.1.0"
} }
}, },
"node_modules/@octokit/plugin-retry": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-3.0.9.tgz",
"integrity": "sha512-r+fArdP5+TG6l1Rv/C9hVoty6tldw6cE2pRHNGmFPdyfrc696R6JjrQ3d7HdVqGwuzfyrcaLAKD7K8TX8aehUQ==",
"dependencies": {
"@octokit/types": "^6.0.3",
"bottleneck": "^2.15.3"
}
},
"node_modules/@octokit/request": { "node_modules/@octokit/request": {
"version": "5.6.1", "version": "5.6.3",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.1.tgz", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz",
"integrity": "sha512-Ls2cfs1OfXaOKzkcxnqw5MR6drMA/zWX/LIS/p8Yjdz7QKTPQLMsB3R+OvoxE6XnXeXEE2X7xe4G4l4X0gRiKQ==", "integrity": "sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==",
"dependencies": { "dependencies": {
"@octokit/endpoint": "^6.0.1", "@octokit/endpoint": "^6.0.1",
"@octokit/request-error": "^2.1.0", "@octokit/request-error": "^2.1.0",
"@octokit/types": "^6.16.1", "@octokit/types": "^6.16.1",
"is-plain-object": "^5.0.0", "is-plain-object": "^5.0.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.7",
"universal-user-agent": "^6.0.0" "universal-user-agent": "^6.0.0"
} }
}, },
@ -1803,6 +1805,11 @@
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz",
"integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==" "integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ=="
}, },
"node_modules/bottleneck": {
"version": "2.19.5",
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
},
"node_modules/brace-expansion": { "node_modules/brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -6224,16 +6231,6 @@
"requires": { "requires": {
"@actions/http-client": "^2.0.1", "@actions/http-client": "^2.0.1",
"uuid": "^8.3.2" "uuid": "^8.3.2"
},
"dependencies": {
"@actions/http-client": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"requires": {
"tunnel": "^0.0.6"
}
}
} }
}, },
"@actions/exec": { "@actions/exec": {
@ -6245,14 +6242,14 @@
} }
}, },
"@actions/github": { "@actions/github": {
"version": "5.0.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/@actions/github/-/github-5.0.0.tgz", "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.0.tgz",
"integrity": "sha512-QvE9eAAfEsS+yOOk0cylLBIO/d6WyWIOvsxxzdrPFaud39G6BOkUwScXZn1iBzQzHyu9SBkkLSWlohDWdsasAQ==", "integrity": "sha512-tuI80F7JQIhg77ZTTgUAPpVD7ZnP9oHSPN8xw7LOwtA4vEMbAjWJNbmLBfV7xua7r016GyjzWLuec5cs8f/a8A==",
"requires": { "requires": {
"@actions/http-client": "^1.0.11", "@actions/http-client": "^2.0.1",
"@octokit/core": "^3.4.0", "@octokit/core": "^3.6.0",
"@octokit/plugin-paginate-rest": "^2.13.3", "@octokit/plugin-paginate-rest": "^2.17.0",
"@octokit/plugin-rest-endpoint-methods": "^5.1.1" "@octokit/plugin-rest-endpoint-methods": "^5.13.0"
}, },
"dependencies": { "dependencies": {
"@octokit/plugin-rest-endpoint-methods": { "@octokit/plugin-rest-endpoint-methods": {
@ -6276,11 +6273,11 @@
} }
}, },
"@actions/http-client": { "@actions/http-client": {
"version": "1.0.11", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==", "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"requires": { "requires": {
"tunnel": "0.0.6" "tunnel": "^0.0.6"
} }
}, },
"@actions/io": { "@actions/io": {
@ -7046,13 +7043,13 @@
} }
}, },
"@octokit/core": { "@octokit/core": {
"version": "3.5.1", "version": "3.6.0",
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.5.1.tgz", "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz",
"integrity": "sha512-omncwpLVxMP+GLpLPgeGJBF6IWJFjXDS5flY5VbppePYX9XehevbDykRH9PdCdvqt9TS5AOTiDide7h0qrkHjw==", "integrity": "sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==",
"requires": { "requires": {
"@octokit/auth-token": "^2.4.4", "@octokit/auth-token": "^2.4.4",
"@octokit/graphql": "^4.5.8", "@octokit/graphql": "^4.5.8",
"@octokit/request": "^5.6.0", "@octokit/request": "^5.6.3",
"@octokit/request-error": "^2.0.5", "@octokit/request-error": "^2.0.5",
"@octokit/types": "^6.0.3", "@octokit/types": "^6.0.3",
"before-after-hook": "^2.2.0", "before-after-hook": "^2.2.0",
@ -7116,16 +7113,25 @@
} }
} }
}, },
"@octokit/plugin-retry": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-3.0.9.tgz",
"integrity": "sha512-r+fArdP5+TG6l1Rv/C9hVoty6tldw6cE2pRHNGmFPdyfrc696R6JjrQ3d7HdVqGwuzfyrcaLAKD7K8TX8aehUQ==",
"requires": {
"@octokit/types": "^6.0.3",
"bottleneck": "^2.15.3"
}
},
"@octokit/request": { "@octokit/request": {
"version": "5.6.1", "version": "5.6.3",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.1.tgz", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz",
"integrity": "sha512-Ls2cfs1OfXaOKzkcxnqw5MR6drMA/zWX/LIS/p8Yjdz7QKTPQLMsB3R+OvoxE6XnXeXEE2X7xe4G4l4X0gRiKQ==", "integrity": "sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==",
"requires": { "requires": {
"@octokit/endpoint": "^6.0.1", "@octokit/endpoint": "^6.0.1",
"@octokit/request-error": "^2.1.0", "@octokit/request-error": "^2.1.0",
"@octokit/types": "^6.16.1", "@octokit/types": "^6.16.1",
"is-plain-object": "^5.0.0", "is-plain-object": "^5.0.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.7",
"universal-user-agent": "^6.0.0" "universal-user-agent": "^6.0.0"
} }
}, },
@ -7613,6 +7619,11 @@
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz",
"integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==" "integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ=="
}, },
"bottleneck": {
"version": "2.19.5",
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
},
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",

View file

@ -38,7 +38,8 @@
"@actions/io": "^1.1.1", "@actions/io": "^1.1.1",
"@octokit/core": "^3.5.1", "@octokit/core": "^3.5.1",
"@octokit/plugin-paginate-rest": "^2.17.0", "@octokit/plugin-paginate-rest": "^2.17.0",
"@octokit/plugin-rest-endpoint-methods": "^6.3.0" "@octokit/plugin-rest-endpoint-methods": "^6.3.0",
"@octokit/plugin-retry": "^3.0.9"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",

View file

@ -3,6 +3,7 @@ import * as exec from '@actions/exec'
import {context, getOctokit} from '@actions/github' import {context, getOctokit} from '@actions/github'
import * as glob from '@actions/glob' import * as glob from '@actions/glob'
import * as io from '@actions/io' import * as io from '@actions/io'
import {retry} from '@octokit/plugin-retry'
import {callAsyncFunction} from './async-function' import {callAsyncFunction} from './async-function'
import {wrapRequire} from './wrap-require' import {wrapRequire} from './wrap-require'
@ -13,6 +14,14 @@ type Options = {
log?: Console log?: Console
userAgent?: string userAgent?: string
previews?: string[] previews?: string[]
retry?: {
doNotRetry?: number[]
enabled?: boolean
}
request?: {
retries: number
retryAfter: number
}
} }
async function main(): Promise<void> { async function main(): Promise<void> {
@ -20,13 +29,40 @@ async function main(): Promise<void> {
const debug = core.getInput('debug') const debug = core.getInput('debug')
const userAgent = core.getInput('user-agent') const userAgent = core.getInput('user-agent')
const previews = core.getInput('previews') const previews = core.getInput('previews')
const retries = parseInt(core.getInput('retries'))
const retryAfter = parseInt(core.getInput('retry-after'))
const doNotRetry = parseNumberArray(core.getInput('do-not-retry'))
const opts: Options = {} const opts: Options = {}
if (debug === 'true') opts.log = console if (debug === 'true') opts.log = console
if (userAgent != null) opts.userAgent = userAgent if (userAgent != null) opts.userAgent = userAgent
if (previews != null) opts.previews = previews.split(',') if (previews != null) opts.previews = previews.split(',')
const github = getOctokit(token, opts) if (retries > 0) {
if (doNotRetry.length > 0) {
opts.retry = {doNotRetry}
}
opts.request = {
retries,
retryAfter
}
core.info(
`GitHub client configured with: (retries: ${retries}, retryAfter: ${retryAfter}, doNotRetry: ${
doNotRetry.length == 0
? 'octokit default: [400, 401, 403, 404, 422]'
: doNotRetry
})`
)
} else {
opts.retry = {
enabled: false
}
}
const github = getOctokit(token, opts, retry)
const script = core.getInput('script', {required: true}) const script = core.getInput('script', {required: true})
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
@ -68,3 +104,12 @@ function handleError(err: any): void {
console.error(err) console.error(err)
core.setFailed(`Unhandled error: ${err}`) core.setFailed(`Unhandled error: ${err}`)
} }
function parseNumberArray(listString: string): number[] {
if (!listString) {
return []
}
const split = listString.trim().split(',')
return split.map(x => parseInt(x))
}