taction
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

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 taction

Without Global Install

npm install --save-dev taction
# or
yarn add --dev taction
# or
pnpm add --dev taction

Without Installing

npx taction types ./action.yml ./src/typed-core.ts
# or
pnpm dlx taction types ./action.yml ./src/typed-core.ts

Usage

taction types <infile> <outfile>

Parse an action.yml file and generate typescript types for the inputs and outputs

taction types action.yml typed-core.ts

Arguments

  • infile: path of action.yml file to parse
  • outfile: 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): string
  • getBooleanInput(inputName: BooleanInputs): boolean
  • getNumberInput(inputName: StringInputs): number
  • getChoiceInput<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

Package Sidebar

Install

npm i taction

Weekly Downloads

4

Version

0.2.0

License

MIT

Unpacked Size

15.2 kB

Total Files

11

Last publish

Collaborators

  • cmgriffing