How I Create My First Action and Deployed to Github Actions Marketplace

José Daniel
The Startup
Published in
4 min readSep 2, 2020

Recently I start a new project called DevData Tools what is an online tool that provides a set of tools useful for specific necessities, the core of the project was a tool with utilities to easily create use cases description and test cases description and export to PDF as table format, the tool is useful to who not deal easily with Word files and tables in there, but this is subject enough to write another article…

In this context I was deploying the front-end application to Firebase hosting and the back-end application to the Heroku, with the front-end was easily configured with file .yml for the workflow of github action, the Firebase Action made all the proccess of deploy, being necessary only the token, that I stored in a secret of the Github Repo.

Until now all was fine, but the point is when I went deploy the back-end application that’s I write in Golang, all the setup and file was fine, the problem was in my devdatatools-firebase-adminsdk.json file that I added they on my .gitignore file in the root of the repo when I uploading to the Github, but this was intentional.

Ignoring my devdatatools-firebase-adminsdk.json

This file have to be ignored, why have some private keys about admin sdk of Firebase, so when I deployed locally all was fine, because was there, but in CI the heroku action was getting the HEAD of the branch, in this case master and deploying to heroku without this file. The point is that I had to create this file in runtime of workflow to deploy to Heroku. In this point my .yml file of workflow it was like this:

All the actions in the Github Marketplace didn’t handle my need very well,
the one that came closest was create-env-json but I needed to create the .json file in a subfolder src and also with a more dynamic way, like pass all the json in a secret of the repo or in a string of the action attribute.

So I started to search how actions works, and I discovered that I could use my Javascript Knowledge to write a action using Node Environment, the first reading was about the core dependencie, what have the core functionality to get deal when you are running your action.

Creating a simple npm project with git init and adding as dependency, all the environment to execute the writing of the .json file was in my hands. There were many tests to understand how env variables of an action was receiveid, the docs of github help me a lot:

You can view the code of action on this repository:

The deploy of an action is very easy, when you respect all the requirements of action.yml file describing the action and the index.js file with the funcionality declared as entry point in the package.json file, only remains to create a new release, on the Github Repository.

And now if you need to create a json file in runtime of your workflow, you can easily add this action on your .yml file of workflow.

In the final my workflow file was using my recently published action to work properly:

All the tests of both action and my deploy on Heroku, takes two days of my weekend, but worth it a lot!

--

--

José Daniel
The Startup

Always learning! When not learning, consider yourself challenged!