Skip to content

Commit 5349cf9

Browse files
committed
Merge branch 'main' into joshmgross/node-20
2 parents 22dcf8a + ecae9eb commit 5349cf9

7 files changed

+52
-4
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,24 @@ jobs:
424424
await printStuff()
425425
```
426426

427+
### Use scripts with jsDoc support
428+
429+
If you want type support for your scripts, you could use the command below to install the
430+
`github-script` type declaration.
431+
```sh
432+
$ npm i -D @types/github-script@github:actions/github-script
433+
```
434+
435+
And then add the `jsDoc` declaration to your script like this:
436+
```js
437+
// @ts-check
438+
/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
439+
export default async ({ core, context }) => {
440+
core.debug("Running something at the moment");
441+
return context.actor;
442+
};
443+
```
444+
427445
### Use env as input
428446

429447
You can set env vars to use them in your script:

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ inputs:
2929
retry-exempt-status-codes:
3030
description: A comma separated list of status codes that will NOT be retried e.g. "400,500". No effect unless `retries` is set
3131
default: 400,401,403,404,422 # from https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
32+
base-url:
33+
description: An optional GitHub REST API URL to connect to a different GitHub instance. For example, https://my.github-enterprise-server.com/api/v3
34+
required: false
3235
outputs:
3336
result:
3437
description: The return value of the script, stringified with `JSON.stringify`

dist/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -35500,6 +35500,7 @@ async function main() {
3550035500
const debug = core.getBooleanInput('debug');
3550135501
const userAgent = core.getInput('user-agent');
3550235502
const previews = core.getInput('previews');
35503+
const baseUrl = core.getInput('base-url');
3550335504
const retries = parseInt(core.getInput('retries'));
3550435505
const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes'));
3550535506
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
@@ -35508,7 +35509,8 @@ async function main() {
3550835509
userAgent: userAgent || undefined,
3550935510
previews: previews ? previews.split(',') : undefined,
3551035511
retry: retryOpts,
35511-
request: requestOpts
35512+
request: requestOpts,
35513+
baseUrl: baseUrl || undefined
3551235514
};
3551335515
const github = (0,lib_github.getOctokit)(token, opts, plugin_retry_dist_node.retry, dist_node.requestLog);
3551435516
const script = core.getInput('script', { required: true });

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"author": "GitHub",
66
"license": "MIT",
77
"main": "dist/index.js",
8+
"types": "types/async-function.d.ts",
89
"private": true,
910
"engines": {
1011
"node": ">=20.0.0 <21.0.0"
1112
},
1213
"scripts": {
13-
"build": "ncc build src/main.ts",
14+
"build": "npm run build:types && ncc build src/main.ts",
15+
"build:types": "tsc src/async-function.ts -t es5 --declaration --allowJs --emitDeclarationOnly --outDir types",
1416
"format:check": "prettier --check src __test__",
1517
"format:write": "prettier --write src __test__",
1618
"lint": "eslint src __test__",

src/async-function.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as io from '@actions/io'
77

88
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor
99

10-
type AsyncFunctionArguments = {
10+
export declare type AsyncFunctionArguments = {
1111
context: Context
1212
core: typeof core
1313
github: InstanceType<typeof GitHub>

src/main.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ main().catch(handleError)
1717
type Options = {
1818
log?: Console
1919
userAgent?: string
20+
baseUrl?: string
2021
previews?: string[]
2122
retry?: RetryOptions
2223
request?: RequestRequestOptions
@@ -27,6 +28,7 @@ async function main(): Promise<void> {
2728
const debug = core.getBooleanInput('debug')
2829
const userAgent = core.getInput('user-agent')
2930
const previews = core.getInput('previews')
31+
const baseUrl = core.getInput('base-url')
3032
const retries = parseInt(core.getInput('retries'))
3133
const exemptStatusCodes = parseNumberArray(
3234
core.getInput('retry-exempt-status-codes')
@@ -42,7 +44,8 @@ async function main(): Promise<void> {
4244
userAgent: userAgent || undefined,
4345
previews: previews ? previews.split(',') : undefined,
4446
retry: retryOpts,
45-
request: requestOpts
47+
request: requestOpts,
48+
baseUrl: baseUrl || undefined
4649
}
4750

4851
const github = getOctokit(token, opts, retry, requestLog)

types/async-function.d.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference types="node" />
2+
import * as core from '@actions/core';
3+
import * as exec from '@actions/exec';
4+
import { Context } from '@actions/github/lib/context';
5+
import { GitHub } from '@actions/github/lib/utils';
6+
import * as glob from '@actions/glob';
7+
import * as io from '@actions/io';
8+
import fetch from 'node-fetch';
9+
export declare type AsyncFunctionArguments = {
10+
context: Context;
11+
core: typeof core;
12+
github: InstanceType<typeof GitHub>;
13+
exec: typeof exec;
14+
glob: typeof glob;
15+
io: typeof io;
16+
fetch: typeof fetch;
17+
require: NodeRequire;
18+
__original_require__: NodeRequire;
19+
};
20+
export declare function callAsyncFunction<T>(args: AsyncFunctionArguments, source: string): Promise<T>;

0 commit comments

Comments
 (0)