JavaScript actions

JavaScript actions 1

We place actions in the .github/actions directory. Each action should have its own sub-directory.


Each action requires an action.yml file. In this file we'll declare the name, author, and description of the action. Next we can add objects to the inputs and outputs keywords. Each elements of the inputs object is itself an object too, with a description, required flag, and a default value. Each element of the outputs object takes a description.


Below that we need to include the runs keyword. In it we specify the version of node in the using keyword, and the location of the file with the action in the main keyword.


To include this action in a workflow, first we'll need to checkout the repository and then pass the action path to the uses keyword.


When our actions use external packages we need to compile our code so that the packages are available in the virtual machine. To do this, we can use the vercel/ncc package. To install it locally we run npm i -D @vercel/ncc. Once installed we can use it by running

npx ncc build path/to/file.js -o path/to/output/dist

Once the dist is generated we just have to update the main keyword in our workflow so that it points to it (for example main: 'dist/index.js').

JavaScript actions 2