Godfrey Odenigbo
8 min readJun 2, 2023

Getting Started with GitHub Actions: A Beginner’s Guide

Abstract

“Getting Started with GitHub Actions: A Beginner’s Guide” provides a comprehensive introduction to GitHub Actions for beginners. The article covers essential topics such as the definition of GitHub, the concept of GitHub Actions, and a brief history of its development. The guide also explores practical aspects of using GitHub Actions, including building a basic NodeJS Express application and an introduction to YAML files, which are crucial for configuring workflows. The article further explains key terminologies in GitHub Actions, ensuring a solid understanding of the terminology used in the platform. Pros and cons of GitHub Actions are presented to help readers assess its suitability for their projects. To inspire readers, real-life production projects that leverage GitHub Actions are highlighted. By the end of the article, beginners will have a solid foundation and be equipped with the knowledge needed to start utilizing GitHub Actions effectively in their own projects.

In conclusion, GitHub Actions offers a powerful and streamlined solution for automating development workflows, making it an excellent choice for developers seeking to enhance their CI/CD pipelines and unlock automation possibilities with ease.

Introduction

First and foremost let’s discuss briefly, What is Github?

GitHub is a web-based platform that provides a centralized location for version control, collaboration, and code hosting. It allows developers to manage and track changes to their code, collaborate with others, and host their projects, making it a popular choice for software development teams.

Whereas, GitHub Actions is an incredibly powerful automation tool offered by GitHub, designed to streamline your development workflows. Whether you’re a beginner taking your first steps or an experienced developer, GitHub Actions can boost your productivity by automating repetitive tasks, running tests, deploying applications, and more. In this article, we’ll provide a comprehensive beginner’s guide to GitHub Actions, taking you through the process of setting up and utilizing workflows to establish CI/CD pipelines.

Table of Contents:

  1. What is GitHub Actions?
  2. GitHub Actions: A Brief History
  3. Building a Basic NodeJS Express Application
  4. A Brief Introduction to YAML Files
  5. Key Terminologies in GitHub Actions
  6. Pros and Cons of GitHub Actions
  7. Real-Life Production Projects Using GitHub Actions

What is GitHub Actions?

GitHub Actions serves as a CI/CD platform built on top of GitHub, enabling you to automate your software development workflows by executing tasks in response to events such as push events, pull request events, and release events.

GitHub Actions adopts a YAML-based workflow approach to CI/CD, where a workflow represents a collection of tasks executed sequentially or in parallel. Each task can be as simple as running a test or building your code, or more complex, like deploying your application to production environments such as AWS or Virtual Private Computers/Servers (VPC/VPS).

a simple Github actions workflow file

GitHub Actions: A Brief History

Launched in 2018 as a beta feature, GitHub Actions has quickly become one of the most popular CI/CD platforms available. Workflow automation and CI/CD have long been favored in the software development community, and GitHub Actions aimed to bring this capability directly into the GitHub ecosystem. It allows developers to automate their workflows without relying on external services or tools.

GitHub Actions leverages GitHub’s existing infrastructure, ensuring ease of use and seamless integration with other GitHub features. It enables automation of various tasks that are typically performed manually, including code building, test running, and application deployment.

Here’s a brief timeline of GitHub Actions:

- 2018: GitHub Actions is launched in beta.

- 2019: GitHub Actions becomes generally available.

- 2020: GitHub Actions introduces support for parallel jobs.

- 2021: GitHub Actions adds support for GitHub Packages.

- 2022: GitHub Actions includes support for GitHub Copilot.

Building a Basic Express JS Application

To illustrate the capabilities of GitHub Actions, let’s consider a basic Express JS application with a single GET endpoint that returns “Hello, World”. We’ll also include a simple unit test as part of the final workflow.

Moving forward, the GitHub Actions workflow file (YAML) should be created and saved in the root directory of the project, inside a folder titled “.github/workflows”. This directory structure ensures proper organization and accessibility.

A basic Expressjs application with one endpoint on the index

A Brief Introduction to YAML Files

YAML, short for “YAML Ain’t Markup Language,” is a human-readable data serialization language widely used for configuration files and data exchange. YAML’s simplicity and readability make it a preferred choice over formats like JSON or XML.

Here are some key points to understand about YAML files:

- Structure: YAML files utilize indentation and whitespace to define data structure and hierarchy. Consistent indentation is crucial for proper interpretation.

  • Data Types: YAML supports various data types, including strings, numbers, booleans, arrays, and objects (mappings/dictionaries). Data types can be nested to represent complex structures.
    - Key-Value Pairs: YAML represents data as key-value pairs. Each key is followed by a colon (:) and its corresponding value. Key-value pairs are separated by new lines.
    - Lists and Arrays: YAML allows the representation of lists and arrays
    using a hyphen (-) followed by the list item or array element. Lists can contain any data type, including nested lists or objects.
    - Comments: YAML supports comments, denoted by the hash symbol (#). Comments are ignored during parsing and serve as explanatory or additional information.
A basic YAML File

Key Terminologies in GitHub Actions

To effectively navigate GitHub Actions, it’s essential to understand the following terminologies:

  1. Workflow: A workflow is an automated process defined in a YAML file. It comprises one or more jobs executed sequentially or in parallel.
  2. Job: A job is a set of steps executed on the same runner. Jobs can run concurrently or depend on the completion of other jobs.
  3. Step: A step represents an individual task within a job. Steps can be commands, actions, or a combination of both.
  4. Action: An action is a reusable code snippet that performs a specific task. GitHub or the community creates actions, and they can be referenced in workflows to automate various tasks.
  5. Event: An event acts as a trigger that initiates a workflow. Events can be actions like code pushes, pull request creations, or scheduled intervals.
  6. Runner: A runner is a virtual machine or container where jobs are executed. GitHub provides hosted runners, while self-hosted runners offer more control and customization.
  7. Environment Variable: Environment variables store values accessible within workflows and steps. They can be used to pass data or configure actions.

Github Actions Secrets

What is a Github Actions Secret you may ask, GitHub Actions Secrets are a secure and convenient way to store sensitive information, such as API keys, tokens, and passwords, used in your GitHub Actions workflows. I will walk you through the process of using GitHub Actions Secrets, ensuring the protection of your sensitive data and enabling seamless integration with your workflows

Step 1: Create a Secret

- Go to the repository in which you want to use the secret.

- Click on the “Settings” tab.

- In the left sidebar, click on “Secrets and variables”.

- Click on “Actions”

- Click on “New repository secret”.

- Provide a name for the secret, for this workflow, we need “SSH_HOST”, “SSH_USERNAME”, “SSH_PASSWORD”, “SSH_PORT”.

- Enter the value for the secret, which could be an access token, password, or any sensitive information you need to use in your workflow.

- Click on “Add secret” to save each one.

Step 2: Access the Secret in a Workflow.

- To use it in a secrets directly, reference it using the secrets context e.g “secrets.SSH_HOST”

Now that you have accessed the secret, you can use it within your workflow as needed.

Please note, Secrets are encrypted and can only be used in the repository they are created in. They are not visible in logs or exposed to actions running in public repositories.

Our final CICD file would be something similar to this

Final Github Actions workflow file

Pros and Cons of Using GitHub Actions

Now, let’s weigh the pros and cons of utilizing GitHub Actions:

Pros:

1. Tight Integration with GitHub: GitHub Actions seamlessly integrates with GitHub repositories, allowing developers to automate workflows directly within the GitHub platform. This integration fosters a familiar environment and eliminates the need for external CI/CD services.

2. Vast Ecosystem: GitHub Actions benefits from a thriving ecosystem of actions available in the GitHub Marketplace. Developers can find pre-built actions for various tasks, simplifying the incorporation and reuse of existing solutions within their workflows. The community aspect promotes collaboration and knowledge sharing.

3. Simplified Setup: GitHub Actions provides pre-configured runners, alleviating the burden of managing infrastructure. Hosted runners are readily available, and self-hosted runners offer more control for specific requirements. This simplifies the setup process, allowing developers to focus on workflows rather than infrastructure management.

Cons:

1. Learning Curve: While GitHub Actions employs YAML-based syntax to enhance accessibility, beginners may encounter a learning curve when unfamiliar with YAML or automation concepts. Acquiring an understanding of YAML structure, workflow configuration, and available actions may require some initial effort.

2. Potential Costs: Although GitHub Actions offers a free tier, additional costs may arise from specific features like using self-hosted runners or exceeding usage limits. Organizations with substantial automation needs should consider potential cost implications.

3. Dependence on GitHub: GitHub Actions’ tight integration with GitHub introduces a degree of dependence on the GitHub platform. Organizations or individuals heavily relying on GitHub Actions should evaluate the implications of vendor lock-in and explore alternative solutions.

Real-Life Production Projects Using GitHub Actions

GitHub Actions is widely adopted by numerous real-life production projects across various domains. Here are a few notable examples:

1. Microsoft VS Code: GitHub Actions workflows used by VS Code can be found in their public GitHub repository:

Repository: https://github.com/microsoft/vscode

2. Facebook React Native: The React Native GitHub repository includes GitHub Actions workflows for continuous integration and testing:

Repository: https://github.com/facebook/react-native

3. Netflix Dispatch: The GitHub repository for Netflix Dispatch provides insights into their use of GitHub Actions for CI/CD:

Repository: https://github.com/Netflix/dispatch

By examining these projects, beginners can gain practical insights into how GitHub Actions are implemented and leverage the knowledge to enhance their own workflows.

In conclusion, GitHub Actions is a powerful automation tool that can revolutionize your development workflows. With its tight integration with GitHub, vast ecosystem of actions, simplified setup process, and real-life production project endorsements, GitHub Actions is an excellent choice for developers looking to automate their CI/CD pipelines. By following the steps outlined in this guide, beginners can quickly get started with GitHub Actions and unlock a world of automation possibilities.

Remember, embracing automation can save time, boost productivity, and enable you to focus on what truly matters: building amazing software. So, why not dive into GitHub Actions and experience the benefits firsthand? Happy automating!

You can access the code from this Github Repository.

Godfrey Odenigbo

Full Stack Engineer | NodeJs | .Net | Containers | Mongo | Postgres