Skip to content
/ action-starter Public template
generated from threeal/nodejs-starter

A minimalist template for starting a new GitHub Action project

License

Notifications You must be signed in to change notification settings

threeal/action-starter

Repository files navigation

Action Starter

A minimalist template for starting a new GitHub Action project.

This template provides a basic GitHub Action project containing a sample JavaScript action written in TypeScript, with built-in support for formatting, linting, testing, and continuous integration.

Key Features

Usage

This guide explains how to use this template to start a new GitHub Action project, from creation to release.

Create a New Project

Follow this link to create a new project based on this template. For more information about creating a repository from a template on GitHub, refer to this documentation.

Alternatively, you can clone this repository locally to begin using this template.

Choose a License

By default, this template is unlicensed. Before modifying this template, replace the LICENSE file with the license to be used by the new project. For more information about licensing a repository, refer to this documentation.

Alternatively, you can remove the LICENSE file or leave it as-is to keep the new project unlicensed.

Update Project Information

To replace the sample information in this template with details about your new project, complete the following steps:

  • Replace the content of this README.md file with a description of the new project. For more information on adding READMEs to a project, refer to this documentation.
  • Modify the action metadata in the action.yml file according to the new project specifications. For more details on the action metadata, refer to this documentation.

Note: You can also search for TODO comments for a list of information that needs to be replaced.

Set Up Tools

It is recommended to use nvm to manage the Node.js version in the project. By default, this template uses the Node.js version specified in the .nvmrc file. Use the following command to install and use the correct Node.js version with nvm:

nvm install

This template uses Yarn with Plug'n'Play support as the package manager. If Yarn is not yet enabled, run the following command:

corepack enable yarn

Then, install the project dependencies with:

yarn install

For more information on Yarn, such as adding dependencies or running tools, refer to this documentation.

Developing the Action

Write the logic for the action in the src/main.ts file according to the project requirements. If you're new to TypeScript, refer to this documentation for guidance.

If the action will support pre- and post-steps, additional files like src/pre.ts and src/post.ts can be added. Just make sure to update the Rollup configuration in the rollup.config.js file and the action metadata in the action.yml file.

Once the code is written, format it with:

yarn format

Then, check linting with:

yarn lint

Lastly, build and bundle the action files with:

yarn build

Testing the Action

Test files in this template are named *.test.ts and typically correspond to the source files being tested. This template uses Jest as the testing framework. For more information on testing with Jest, refer to this documentation.

After creating your test files, run tests with:

yarn test

Additionally, you can test the action by running it directly from the GitHub workflow as specified in the .github/workflows/test.yaml file.

Release the Action

When the project is complete, release and publish it from the project repository page on GitHub. For more information on releasing a project, refer to this documentation. For more information on publishing GitHub actions, refer to this documentation.