Skip to content

Commit

Permalink
Merge branch 'main' into joshmgross/node-20
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmgross committed Nov 8, 2023
2 parents 22dcf8a + ecae9eb commit 5349cf9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,24 @@ jobs:
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

You can set env vars to use them in your script:
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ inputs:
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
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:
result:
description: The return value of the script, stringified with `JSON.stringify`
Expand Down
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35500,6 +35500,7 @@ async function main() {
const debug = core.getBooleanInput('debug');
const userAgent = core.getInput('user-agent');
const previews = core.getInput('previews');
const baseUrl = core.getInput('base-url');
const retries = parseInt(core.getInput('retries'));
const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes'));
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
Expand All @@ -35508,7 +35509,8 @@ async function main() {
userAgent: userAgent || undefined,
previews: previews ? previews.split(',') : undefined,
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 script = core.getInput('script', { required: true });
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"author": "GitHub",
"license": "MIT",
"main": "dist/index.js",
"types": "types/async-function.d.ts",
"private": true,
"engines": {
"node": ">=20.0.0 <21.0.0"
},
"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:write": "prettier --write src __test__",
"lint": "eslint src __test__",
Expand Down
2 changes: 1 addition & 1 deletion src/async-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as io from '@actions/io'

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

type AsyncFunctionArguments = {
export declare type AsyncFunctionArguments = {
context: Context
core: typeof core
github: InstanceType<typeof GitHub>
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ main().catch(handleError)
type Options = {
log?: Console
userAgent?: string
baseUrl?: string
previews?: string[]
retry?: RetryOptions
request?: RequestRequestOptions
Expand All @@ -27,6 +28,7 @@ async function main(): Promise<void> {
const debug = core.getBooleanInput('debug')
const userAgent = core.getInput('user-agent')
const previews = core.getInput('previews')
const baseUrl = core.getInput('base-url')
const retries = parseInt(core.getInput('retries'))
const exemptStatusCodes = parseNumberArray(
core.getInput('retry-exempt-status-codes')
Expand All @@ -42,7 +44,8 @@ async function main(): Promise<void> {
userAgent: userAgent || undefined,
previews: previews ? previews.split(',') : undefined,
retry: retryOpts,
request: requestOpts
request: requestOpts,
baseUrl: baseUrl || undefined
}

const github = getOctokit(token, opts, retry, requestLog)
Expand Down
20 changes: 20 additions & 0 deletions types/async-function.d.ts
Original file line number Diff line number Diff line change
@@ -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>;

0 comments on commit 5349cf9

Please sign in to comment.