@teamhive/core-actions

This library contains private GitHub Actions for TeamHive monorepos.

Usage no npm install needed!

<script type="module">
  import teamhiveCoreActions from 'https://cdn.skypack.dev/@teamhive/core-actions';
</script>

README

@teamhive/core-actions

This library contains private GitHub Actions for TeamHive monorepos.

Actions

Usage

Installation

To use actions, install the package with npm or as a dev dependency

yarn add @teamhive/core-actions --dev
npm i --save-dev @teamhive/core-actions

After installation, this will create a folder relative to the root of the directory at .github/actions/core-actions. Our recommendation is that this folder should be treated like compiled code. You should not edit the code in this folder as it will be overridden on a re-installation or update of the package. Additionally, the folder should be gitignored. This will prevent the action from being run without installing the package first in the GitHub Actions container.

Calling actions

In a workflow yml file, you can use a relative path from the root of the repository to reference the actions in the core-actions directory.

Example:

- name: Build Apps
    uses: ./.github/actions/core-actions/build-node-apps
    with:
        dockerBuildArgs: '["--build-arg", "TAG=loop-lxp-deps"]'
        environment: 'next'
        ecrRegistry: ${{ steps.login-ecr.outputs.registry }}

Contributing

To create a new action, create a new folder in the src/actions directory with the name of the action in kebab case. Within that directory, create an action.yml file and named for the action, such as action-name.action.ts. In action.yml, you define and document all of the inputs of an action following the specifications given by GitHub. This action.yml will be copied into the .github/actions/core-actions folder upon installation.

Action Class

To implement your action you must create and export a class that extends AbstractAction. This class should define an async run function, as well as define its actionName and dirName. If the action has inputs, you should define the arguments for the action as well.

Action Arguments

The arguments for an action are typed through a static class. This has the benefit of providing a type abstraction on top of the core.getInput function. To create an argument class, simply create a class with static properties and decorate them with the @ActionArg() decorator.

Example

// hello.action.ts
import { AbstractAction } from '../../classes';
import { ActionNames } from '../../constants';
import { Action } from '../../decorator';
import { HelloArg } from './hello-args;

@Action()
export class HelloAction extends AbstractAction {
    static actionName: ActionNames = 'Hello';
    static dirName: string = __dirname;

    args: typeof HelloArgs = HelloArgs;

    async run() {
        console.log(`Hello, ${this.args.name}`);
    }
}
// hello.args.ts
import { ActionArg } from '../../decorator/action-arg.dec';

export class BuildNodeAppsArgs {
    @ActionArg()
    static name: string;
}