taction
v0.2.0
Published
Taction is a CLI utility to make authoring GitHub Actions easier and more type-safe. It parses an action.yml file and generates typescript types for the inputs and outputs. More commands may be added in the future.
Downloads
10
Maintainers
Readme
Taction
Taction is a CLI utility to make authoring GitHub Actions easier and more type-safe. It parses an action.yml file and generates typescript types for the inputs and outputs. More commands may be added in the future.
Installation
npm install -g taction
# or
yarn global add taction
# or
pnpm add -g tactionWithout Global Install
npm install --save-dev taction
# or
yarn add --dev taction
# or
pnpm add --dev tactionWithout Installing
npx taction types ./action.yml ./src/typed-core.ts
# or
pnpm dlx taction types ./action.yml ./src/typed-core.tsUsage
taction types <infile> <outfile>
Parse an action.yml file and generate typescript types for the inputs and outputs
taction types action.yml typed-core.tsArguments
infile: path of action.yml file to parseoutfile: path of typed core file to output
Importing the Typed Core
Import the typed core in your typescript file and use it instead of the core module. The keys will now be typed and will error out if you misspell a key or try to use one that is not an input or output.
import typedCore from "./typed-core";
const myInput = typedCore.getInput("myInput");
const myBooleanInput = typedCore.getBooleanInput("myBooleanInput");
typedCore.setOutput("myOutput", "value");Typed Core
The typed core is a wrapper of the core module with the following modifications:
getInput(inputName: StringInputs): stringgetBooleanInput(inputName: BooleanInputs): booleangetNumberInput(inputName: StringInputs): numbergetChoiceInput<T extends keyof IChoiceInputs>(inputName: T): IChoiceInputs[T]setOutput(outputName: Outputs, value: any)
StringInputs and BooleanInputs are the union of all the inputs that are strings and booleans respectively.
IChoiceInputs is an interface with the keys of all the choice inputs and the types for the keys are the union of all the options for that input.
Outputs is the union of all the outputs.
License
MIT © Chris Griffing
