Create a New Github Action That Logs Hello World with Javascript and NodeJS

Colby Fayock
InstructorColby Fayock
Share this video with your friends

Social Share Links

Send Tweet

In this lesson, you'll learn how to create a brand new Github Action from scratch using Javascript. Running on Nodejs, we'll create a new script that logs "Hello, world!", configure the Action registration information, and initialize it as an npm package so that we can prepare to publish it to the world.

Colby Fayock: [0:00] We're going to start off with an empty GitHub repository. Once we open our code editor, we can see that we have absolutely no files to start. Our goal, we'll build and create a simple node script using JavaScript that says, "Hello, world!"

[0:09] To start that we first need a file, so let's open a new file. We can name it index.js. Inside we can console.log('Hello, world!'). To test this out, we can open up our terminal and run node index.js, and see it say "Hello, world!"

[0:24] Now, we have the script that we want to run, but now we have to make in an npm package. Inside our terminal we want to run npm init. Once you run init, it will ask you a few questions, and we could probably use most of the defaults here. Once you're at the end, you can type yes for Is it OK? Once you're done, you can see that it created a package.json for us with all of our information.

[0:41] The last file that we'll need for our action is an action.yml. Let's go ahead and create a new file. We can save it as action.yml. Inside we want to add a few attributes. We want to add name, which we'll call Hello World and a description, which we can say Saying hello to the world! You can even put your author name. For me, I'm Colby Fayock. My email is hello@colbyfayock.com.

[1:05] For the important part, we want to add a runs attribute. The first property we want add is using. This is our environment, so we want to say node12. We also want to specify a main, which is index.js file.

[1:16] Once you add these files, commit them and push them, we can see them in our repo where we now see it Publish this Action to Marketplace.

[1:22] In review, we started off by creating a script that logs 'Hello, world!' Next, we used npm to initialize our package. Finally, to register our Action, we created an action.yml file where we specified our configuration. Once we pushed those files to GitHub, we're now ready to use our Action.