Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose async-function argument type #402

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"author": "GitHub",
"license": "MIT",
"main": "dist/index.js",
"types": "types/async-function.d.ts",
"private": true,
"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 @@ -8,7 +8,7 @@ import fetch from 'node-fetch'

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

type AsyncFunctionArguments = {
export declare type AsyncFunctionArguments = {
viktorlott marked this conversation as resolved.
Show resolved Hide resolved
context: Context
core: typeof core
github: InstanceType<typeof GitHub>
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>;
Loading