Back

How We Built our own GitHub Action

How We Built our own GitHub Action
TD
Thibault Le Ouay Ducasse
3 min read
engineering

A couple of weeks ago, when we released our CLI, we wanted to use it to run our own Synthetics Tests in a GitHub Action. We aimed to have a simple way to run our tests on every push to our main branch or on a schedule.

There are three ways to build a GitHub Action:

  • Composite actions
  • Javascript actions
  • Docker container actions

Our CLI is built in Golang, and we publish every new version as a binary. It made sense to go with the Docker container actions. This way we could use our CLI to run the tests.

We needed to have a way to pass the API key and the configuration file to the action.

Let's start our speedrun on building our own custom Docker GitHub Action.

Create a Dockerfile

Our Docker file is pretty simple. We use the alpine image and install curl to download the CLI. We then extract the CLI and set the entrypoint to the entrypoint.sh file.

It results in a small image of around 25 MB, which is perfect for a GitHub Action.

To download the latest version of the CLI we use the following URL.

Our entrypoint.sh file is also quite simple. We just run the CLI with the API key and the configuration file.

Create the action.yml file

Our action.yml file

That's all you need to build your own Docker custom GitHub Action.

I struggle a bit with the GitHub action because the docker image was being built on the fly. I had to push the image to the GitHub Container Registry to be able to use it in the action. You can use any other container registry but GitHub Container Registry is free for public repositories.

The solution was to change the image in the action.yml file to the image in the GitHub Container Registry.

From:

To:

Publish it to the GitHub marketplace

Add branding to your action and your action is ready. You can publish it to the GitHub Marketplace.

Conclusion

Building a GitHub Action is pretty simple. We choose to use a Docker container action because we wanted to use our CLI to run the tests.

If you want to start using our action you can find it in the GitHub Marketplace.

https://github.com/marketplace/actions/openstatus-synthetics-ci

If you want to see a GitHub repository with the action you can find it here.

https://github.com/openstatusHQ/github-action-tester/actions

Create an account on OpenStatus and start running your own Synthetics Tests in your GitHub Actions.