Skip to content

Ready to use template to create Github Actions using Typescript.

License

Notifications You must be signed in to change notification settings

nelsoncanarinho/renewed-typescript-action

Repository files navigation

renewed typescript action

License: MIT ci semantic-release: angular

Create awesome Github Actions with Typescript 😎

This is a ready to use Typescript template for create Github Actions.

This template includes compilation support, tests, a validation workflow, publishing, and versioning.

It's based on actions/typescript-action with some tweaks.

Tweaks

  • Uses pnpm as package manager;
  • Uses eslint and prettier with minimal configuration;
  • Up to date dependencies;
  • Simpler build configuration;
  • Easy to customize composable workflow;
  • Automatic release workflow;

Create an action from this template

Click the Use this Template and provide the new repo details for your action.

Make sure you have nodejs and pnpm installed on your machine.

Code in Main

Install the dependencies

pnpm install

Build the typescript and package it for distribution

pnpm build

Run the tests ✅:

$ pnpm test

 PASS  ./wait.test.js
  ✓ throws invalid number (3ms)
  ✓ wait 500 ms (504ms)
  ✓ test runs (95ms)

Change action.yml

The action.yml defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the documentation

Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

import * as core from '@actions/core';
...

async function run() {
  try {
      ...
  }
  catch (error) {
    core.setFailed(error.message);
  }
}

See the toolkit documentation for the various packages.

Publish to a distribution branch

Push code to main triggers a continuous integration pipeline that will take care of validate the source code, generate build artifacts and a new release based on the commits.

It's recommended to follow conventional commits guidelines to have a meaningfully commit history and to take advantage of semantic-release automatic versioning.