Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Basic CI/CD: Autorun Tests with GitHub Actions

Premium
5 min read

Ok, so we have automated tests that check our code for potential bugs. But we need to run those tests manually every time. Wouldn't it be cool to automate that process?

This is a part of the so-called CI/CD process, automating some checks before deployment or merging the Pull Request.

One of the most common and easy-to-setup procedures is running tests automatically on each Pull Request. Then, the author of the PR immediately knows there's something to fix before the merging person (which may be the same developer) comes to approve the Pull Request.

The easiest tool to set it up is GitHub Actions. In this lesson, I will show you how to configure automated tests, and in the following lessons, we will add more automatic checks to this process.


Setting up GitHub Actions

GitHub Actions has a limited free version, you can find all the pricing on this official GitHub page.

To enable GitHub actions, we need only add a .github/workflows/[whatever_name].yml file with instructions to GitHub.

That .yml should contain the commands that would be executed on the virtual GitHub environment: setting up PHP, cloning our project's branch, and running the tests.

In our project, we did it in a few "attempts", let me show you step-by-step.

First, we create the GitHub issue to add GitHub Actions:

Then, we create a feature branch for this:

git checkout -b feature/github-actions

And now, we can push the code into that feature branch.

Get used to this process of issue -> branch -> push -> pull request -> merge, I want it to become a habit for you.

Next, here's the example of the initial...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (31 h 16 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

A
Aleksandr ✓ Link copied!

Few additions, when we finish working on the feature branch in the previous lesson shouldn't we switch to dev and pull the latest changes from the Github?

While on the feature branch we can do:

git checkout dev
git pull origin dev

To set the upstream

git branch --set-upstream-to=origin/dev dev

Next time we can run git pull while working on dev branch

Hope it helps someone.