mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 16:16:21 +00:00
Merge branch 'main' into joshmgross/node-20
This commit is contained in:
18
README.md
18
README.md
@@ -424,6 +424,24 @@ jobs:
|
|||||||
await printStuff()
|
await printStuff()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Use scripts with jsDoc support
|
||||||
|
|
||||||
|
If you want type support for your scripts, you could use the command below to install the
|
||||||
|
`github-script` type declaration.
|
||||||
|
```sh
|
||||||
|
$ npm i -D @types/github-script@github:actions/github-script
|
||||||
|
```
|
||||||
|
|
||||||
|
And then add the `jsDoc` declaration to your script like this:
|
||||||
|
```js
|
||||||
|
// @ts-check
|
||||||
|
/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
|
||||||
|
export default async ({ core, context }) => {
|
||||||
|
core.debug("Running something at the moment");
|
||||||
|
return context.actor;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### Use env as input
|
### Use env as input
|
||||||
|
|
||||||
You can set env vars to use them in your script:
|
You can set env vars to use them in your script:
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ inputs:
|
|||||||
retry-exempt-status-codes:
|
retry-exempt-status-codes:
|
||||||
description: A comma separated list of status codes that will NOT be retried e.g. "400,500". No effect unless `retries` is set
|
description: A comma separated list of status codes that will NOT be retried e.g. "400,500". No effect unless `retries` is set
|
||||||
default: 400,401,403,404,422 # from https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
|
default: 400,401,403,404,422 # from https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
|
||||||
|
base-url:
|
||||||
|
description: An optional GitHub REST API URL to connect to a different GitHub instance. For example, https://my.github-enterprise-server.com/api/v3
|
||||||
|
required: false
|
||||||
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`
|
||||||
|
|||||||
4
dist/index.js
vendored
4
dist/index.js
vendored
@@ -35500,6 +35500,7 @@ async function main() {
|
|||||||
const debug = core.getBooleanInput('debug');
|
const debug = core.getBooleanInput('debug');
|
||||||
const userAgent = core.getInput('user-agent');
|
const userAgent = core.getInput('user-agent');
|
||||||
const previews = core.getInput('previews');
|
const previews = core.getInput('previews');
|
||||||
|
const baseUrl = core.getInput('base-url');
|
||||||
const retries = parseInt(core.getInput('retries'));
|
const retries = parseInt(core.getInput('retries'));
|
||||||
const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes'));
|
const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes'));
|
||||||
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
|
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
|
||||||
@@ -35508,7 +35509,8 @@ async function main() {
|
|||||||
userAgent: userAgent || undefined,
|
userAgent: userAgent || undefined,
|
||||||
previews: previews ? previews.split(',') : undefined,
|
previews: previews ? previews.split(',') : undefined,
|
||||||
retry: retryOpts,
|
retry: retryOpts,
|
||||||
request: requestOpts
|
request: requestOpts,
|
||||||
|
baseUrl: baseUrl || undefined
|
||||||
};
|
};
|
||||||
const github = (0,lib_github.getOctokit)(token, opts, plugin_retry_dist_node.retry, dist_node.requestLog);
|
const github = (0,lib_github.getOctokit)(token, opts, plugin_retry_dist_node.retry, dist_node.requestLog);
|
||||||
const script = core.getInput('script', { required: true });
|
const script = core.getInput('script', { required: true });
|
||||||
|
|||||||
@@ -5,12 +5,14 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"types": "types/async-function.d.ts",
|
||||||
"private": true,
|
"private": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.0.0 <21.0.0"
|
"node": ">=20.0.0 <21.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build src/main.ts",
|
"build": "npm run build:types && ncc build src/main.ts",
|
||||||
|
"build:types": "tsc src/async-function.ts -t es5 --declaration --allowJs --emitDeclarationOnly --outDir types",
|
||||||
"format:check": "prettier --check src __test__",
|
"format:check": "prettier --check src __test__",
|
||||||
"format:write": "prettier --write src __test__",
|
"format:write": "prettier --write src __test__",
|
||||||
"lint": "eslint src __test__",
|
"lint": "eslint src __test__",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import * as io from '@actions/io'
|
|||||||
|
|
||||||
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor
|
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor
|
||||||
|
|
||||||
type AsyncFunctionArguments = {
|
export declare type AsyncFunctionArguments = {
|
||||||
context: Context
|
context: Context
|
||||||
core: typeof core
|
core: typeof core
|
||||||
github: InstanceType<typeof GitHub>
|
github: InstanceType<typeof GitHub>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ main().catch(handleError)
|
|||||||
type Options = {
|
type Options = {
|
||||||
log?: Console
|
log?: Console
|
||||||
userAgent?: string
|
userAgent?: string
|
||||||
|
baseUrl?: string
|
||||||
previews?: string[]
|
previews?: string[]
|
||||||
retry?: RetryOptions
|
retry?: RetryOptions
|
||||||
request?: RequestRequestOptions
|
request?: RequestRequestOptions
|
||||||
@@ -27,6 +28,7 @@ async function main(): Promise<void> {
|
|||||||
const debug = core.getBooleanInput('debug')
|
const debug = core.getBooleanInput('debug')
|
||||||
const userAgent = core.getInput('user-agent')
|
const userAgent = core.getInput('user-agent')
|
||||||
const previews = core.getInput('previews')
|
const previews = core.getInput('previews')
|
||||||
|
const baseUrl = core.getInput('base-url')
|
||||||
const retries = parseInt(core.getInput('retries'))
|
const retries = parseInt(core.getInput('retries'))
|
||||||
const exemptStatusCodes = parseNumberArray(
|
const exemptStatusCodes = parseNumberArray(
|
||||||
core.getInput('retry-exempt-status-codes')
|
core.getInput('retry-exempt-status-codes')
|
||||||
@@ -42,7 +44,8 @@ async function main(): Promise<void> {
|
|||||||
userAgent: userAgent || undefined,
|
userAgent: userAgent || undefined,
|
||||||
previews: previews ? previews.split(',') : undefined,
|
previews: previews ? previews.split(',') : undefined,
|
||||||
retry: retryOpts,
|
retry: retryOpts,
|
||||||
request: requestOpts
|
request: requestOpts,
|
||||||
|
baseUrl: baseUrl || undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const github = getOctokit(token, opts, retry, requestLog)
|
const github = getOctokit(token, opts, retry, requestLog)
|
||||||
|
|||||||
20
types/async-function.d.ts
vendored
Normal file
20
types/async-function.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/// <reference types="node" />
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
import { Context } from '@actions/github/lib/context';
|
||||||
|
import { GitHub } from '@actions/github/lib/utils';
|
||||||
|
import * as glob from '@actions/glob';
|
||||||
|
import * as io from '@actions/io';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
|
export declare type AsyncFunctionArguments = {
|
||||||
|
context: Context;
|
||||||
|
core: typeof core;
|
||||||
|
github: InstanceType<typeof GitHub>;
|
||||||
|
exec: typeof exec;
|
||||||
|
glob: typeof glob;
|
||||||
|
io: typeof io;
|
||||||
|
fetch: typeof fetch;
|
||||||
|
require: NodeRequire;
|
||||||
|
__original_require__: NodeRequire;
|
||||||
|
};
|
||||||
|
export declare function callAsyncFunction<T>(args: AsyncFunctionArguments, source: string): Promise<T>;
|
||||||
Reference in New Issue
Block a user