← Back

Building GitHub Actions in Node.js

Hey! You there! Heard all about these new fan-dangled GitHub Actions, and want to go out and build one? Well then let’s do it!

This post will serve as a guide to building a run-of-the-mill GitHub Action in Node.js. You can build Actions in whatever language/runtime you want - I’m choosing Node.js because JavaScript is the largest language on GitHub and because Node.js is bae 😍

Before we dive in

I’ll assume that you’ve built some things in Node before - this post won’t cover Node.js fundamentals, just the things specific to Actions.

If you aren’t at all familiar with Actions, check out @jessfraz’s excellent post on the life of an Action - it should help you wrap your head around the concept, because this post is really about building the thing.

What we’re building

As a thought experiment, let’s build @jessfraz’s branch-cleanup-action Action. It deletes branches whose pull requests have been merged. If you just want to use the thing, you should use hers - we’re porting it to Node for fun!

Let’s do it

We’ll start by preparing our Dockerfile. Every Action runs in a Docker container, so we need to describe that container. The below code should suffice for most (but not all) Node.js GitHub Actions. Docker is an amazing technology, but if your goal is just to build your Action you shouldn’t need to learn it all.

FROM node:slim

# A bunch of `LABEL` fields for GitHub to index
LABEL "com.github.actions.name"="Delete merged branches"
LABEL "com.github.actions.description"="Cleans up merged branches."
LABEL "com.github.actions.icon"="gear"
LABEL "com.github.actions.color"="red"
LABEL "repository"="https://github.com/JasonEtco/node-branch-cleanup-action"
LABEL "homepage"="https://github.com/JasonEtco/node-branch-cleanup-action"