mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 08:06:23 +00:00
Merge pull request #402 from typed-actions/export-types
Expose async-function argument type
This commit is contained in:
18
README.md
18
README.md
@@ -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:
|
||||
|
||||
@@ -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__",
|
||||
|
||||
@@ -8,7 +8,7 @@ import fetch from 'node-fetch'
|
||||
|
||||
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor
|
||||
|
||||
type AsyncFunctionArguments = {
|
||||
export declare type AsyncFunctionArguments = {
|
||||
context: Context
|
||||
core: typeof core
|
||||
github: InstanceType<typeof GitHub>
|
||||
|
||||
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