Automated Testing with GitHub Actions: Simplifying the Process

Have you ever been hesitant to try something new because it seemed complex and time-consuming? I recently found myself in that situation when considering automated testing for my game engine, Hazel. Initially, I dismissed the idea of using GitHub Actions, thinking it would be too complicated and require additional setup. However, after some careful evaluation and a reminder to give it a fair chance, I decided to explore GitHub Actions further. And boy, was I pleasantly surprised!

In this article, I’ll share my experience with automated testing using GitHub Actions and how it turned out to be much simpler than I anticipated. I’ll explain the process of setting up a self-hosted runner, creating workflows, and running tests. So, let’s dive in!

Automated Testing with GitHub Actions: Simplifying the Process
Automated Testing with GitHub Actions: Simplifying the Process

Setting Up GitHub Actions

Before we get into the details, let me give you a quick overview of GitHub Actions. It’s a powerful platform that allows you to automate your software development workflows. By defining workflow files, you can specify the actions to be taken when specific events occur, such as code pushes or pull requests.

To use GitHub Actions, you’ll need to enable it for your repository. Simply go to the Settings tab, select Actions, and enable it. Additionally, you’ll need to set up a self-hosted runner, which acts as a device to execute the workflows on your local machine or server. By using a self-hosted runner, you have more flexibility and control over the testing environment.

To set up a self-hosted runner, you’ll need to follow a few simple steps:

  1. Download the GitHub Actions Runner application from the GitHub Actions Runner repository.
  2. Configure the runner by running the provided commands, such as downloading and extracting the installer.
  3. Once configured, the runner will act as a service, continuously listening for events and executing workflows.
Further reading:  Safety in Modern C++: Ensuring Code Reliability

Creating Workflows

Now that we have the runner set up, let’s create our first workflow. Workflows are defined using YAML files that specify the steps and actions to be performed. Here’s an example workflow file to get you started:

name: Build
on:
  push:
    branches:
      - dev

env:
  solution_file_path: Hazel.sln

jobs:
  build:
    runs-on: [self-hosted, windows-latest]

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Add MSBuild to Path
        uses: microsoft/setup-msbuild@v1

      - name: Setup
        working-directory: ${{ env.solution_file_path }}
        run: |
          python setup.py

      - name: Build
        working-directory: ${{ env.solution_file_path }}
        run: |
          msbuild "${{ github.workspace }}/${{ env.solution_file_path }}" /m /p:Configuration=${{ matrix.build_configuration }} > build_log.txt

Let’s take a closer look at what’s happening in this workflow:

  1. The workflow is triggered by a push event to the dev branch. You can modify this to suit your needs.
  2. The environment section specifies the solution file path, which you’ll need to provide.
  3. The build job runs on a self-hosted runner on Windows. You can customize this to match your runner configuration.
  4. The steps section defines the actions to be performed.
  5. First, we checkout the repository using the actions/checkout action.
  6. Next, we add MSBuild to the system’s path using the microsoft/setup-msbuild action.
  7. Then, we run the setup script for our project, which can be customized based on your requirements.
  8. Finally, we build the project using MSBuild, specifying the build configuration based on the matrix.

Testing and Analyzing Results

With the workflow set up, every time a push event occurs on the specified branch, GitHub Actions will automatically trigger the defined steps. The entire process will be executed on the self-hosted runner, and you’ll be able to monitor the progress and results through the GitHub Actions tab.

Further reading:  Techal: Update on Repentance Achieved

Once the workflow run is complete, you can access the logs and view the details of each step. This provides valuable insights into the success or failure of the tests and helps identify potential issues. You can also configure the workflow to run different tests based on specific configurations, allowing you to thoroughly test your code across various scenarios.

Conclusion

Automated testing can save valuable time and resources for software development projects. With GitHub Actions, the process becomes even simpler and more efficient. By setting up a self-hosted runner and defining workflows, you can automate the testing process and gain valuable insights into the success of your code changes.

Don’t be afraid to explore new technologies and give them a fair evaluation before dismissing them. Sometimes, what seems complex at first can turn out to be surprisingly easy and beneficial. So, why not give GitHub Actions a try?

To learn more about GitHub Actions and how to set up your own workflows, visit the official GitHub Actions documentation.

For more insightful content about the ever-evolving world of technology, visit Techal.

FAQs

Q: Can I use GitHub Actions on different platforms like Linux and macOS?
A: Yes, GitHub Actions supports various operating systems, including Windows, Linux, and macOS. You can set up self-hosted runners on these platforms to run your workflows.

Q: How much does it cost to use GitHub Actions?
A: GitHub Actions provides a certain number of free minutes for running workflows on GitHub-hosted runners. However, self-hosted runners, like the ones we discussed in this article, are free to use as you provide the hardware.

Further reading:  An Introduction to PCF and Slope-Scaling in Hardware 3D

Q: Can multiple team members access the logs and results of the tests?
A: Yes, the logs and results of the tests are accessible to anyone with access to the repository. This allows team members to collaborate, analyze the test results, and troubleshoot any issues together.

Q: Can I run different types of tests, such as unit tests and integration tests, using GitHub Actions?
A: Absolutely! GitHub Actions provides great flexibility, allowing you to customize your workflows to run any type of tests you require. By defining the appropriate steps and actions in your workflow file, you can automate the execution of different tests.

Q: Are the workflow runs parallelized for faster testing?
A: By default, GitHub Actions runs the steps in a workflow sequentially. However, you can configure certain steps to run in parallel using the jobs.<job_id>.strategy.matrix configuration. This allows for faster testing, especially when testing multiple configurations simultaneously.

Conclusion

Automated testing can save valuable time and resources for software development projects. With GitHub Actions, the process becomes even simpler and more efficient. By setting up a self-hosted runner and defining workflows, you can automate the testing process and gain valuable insights into the success of your code changes.

Don’t be afraid to explore new technologies and give them a fair evaluation before dismissing them. Sometimes, what seems complex at first can turn out to be surprisingly easy and beneficial. So, why not give GitHub Actions a try?

To learn more about GitHub Actions and how to set up your own workflows, visit the official GitHub Actions documentation.

For more insightful content about the ever-evolving world of technology, visit Techal.