[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Automate UnitTest with GitHub Actions

Hello!

My name is Matsuki from the System Development Department.

Continuing from the previous article on GitHub Actions, this time we will be talking about GitHub Actions.

This time, the topic is ``Let's automate PHP's UnitTest by leaving it to GitHub Actions!''

Points to note

In this article, we will proceed with the article assuming that you are building a Laravel environment using Docker.

| |- docker | |- mysql | | |- Dockerfile | | |- my.cnf | | | |- php | |- Dockerfile | |- php.ini | |- docker-compose.yml | |- src

What are GitHub Actions?

This is briefly explained in a previous article, so please take a look there.

Automate Larastan with GitHub Actions!

Automate Larastan with GitHub Actions!

environment

Docker: 23.0.1

Laravel: 10.x

PHP: 8.2

MySQL: 8.0

Code content

The code we will use this time is as follows.

The code below is written in "/.github/workflows/unitTest.yml".

name: UnitTest on: push: jobs: unitTest: runs-on: ubuntu-latest steps: - name: Check out code uses: actions/ [email protected] - name: Set up Docker Compose run: docker compose up -d working- directory: ${{ github.workspace }} # Specify the root directory of the repository - name: composer install run: docker compose exec -i -t php-fpm composer install - name: thirty seconds sleep run: sleep 30 - name: Run PHPUnit run: docker compose exec -i -t php-fpm vendor/bin/phpunit

Based on the above code, we will explain the mechanism by which UnitTest runs automatically.

This article also reiterates what was discussed in the previous Larastan article.

name:

This field describes the name of the workflow to be registered in GitHub Actions.

By entering this, it will be displayed on the GitHub Actions screen.

Here, the name "UnitTest" is registered.

If not registered, the relative path of the file will be registered.

In this case, it will be registered with the name "./.github/workflows/UnitTest.yml".

on:

You can decide which actions trigger the workflow.

This is called a "trigger".

In the code used this time, "Push to GitHub" is the trigger to run UnitTest.

In addition to the push timing, you can also set triggers in detail, such as triggering when a pull request is created, or only when a specified branch is pushed.

jobs:

This is an item where you write the processes that will be executed within the workflow.

For example, to run UnitTest, you need execution commands such as starting Docker and installing composer.

This item describes such operations.

unitTest:

Job creation and job name.

You can use the name key in a job to set the name that will be displayed in GitHub's UI, but if you don't set it, it will be replaced with the job's name.

runs-on:

Define the virtual machine type.

When setting up a virtual machine,

you can choose from three options: GitHub hosted runner
, runner larger than GitHub hosted runner
, and self-hosted runner

This time we will use the first GitHub hosted runner (hereinafter referred to as runner).

There are several types of runners, and you can choose from three: Linux, Windows, and macOS.

Basically, I think there is no problem with using Linux, but please choose according to your environment.

This time I am using the latest version of Ubuntu as a virtual machine.

uses:

Specify the action to perform.

The action used here is a module called "actions/checkout".

The role is used to use code from the repository.

run: (1st)

Here we are running the docker compose up -d

Since this time we will be building an environment using docker, we will start docker here.

working-directory:

This specifies the directory in which to work.

This time I am writing ${{ github.workspace }}

This allows you to get the absolute path from the default working directory.

Starting docker with the obtained path.

run: (second)

The second run installs composer.

The command is running docker compose exec -i -t php composer install

Although php is written in the middle of the command, please enter the name of your php container

By writing the above command, composer install will be executed within the php container.

run: (third)

The third run uses the sleep command.

The command is running sleep 30

Mysql may not have started completely after docker compose up, so

UnitTest cannot run properly in that situation, so we are delaying the process for 30 seconds.

run: (4th)

UnitTest is performed in the fourth and final run.

Similar to the second run, the UnitTest execution command is written inside the php container.

this command docker compose exec -i -t php vendor/bin/phpunit please replace php the name of your php container

At this point I was finally able to run UnitTest.

summary

What did you think?

You can automate many things with GitHub Actions,

It will be difficult to implement it, but once it is implemented, you will be able to increase your work efficiency!

thank you very much.

lastly

We have opened the service site "SEKARAKU Lab" for the system development department to which I belong.
Beyond is a one-stop service for everything from server design and construction to operation, so if you have any trouble with server-side development, please feel free to contact us.

● SEKARAKU Lab: https://sekarakulab.beyondjapan.com

If you found this article helpful , please give it a like!
4
Loading...
4 votes, average: 1.00 / 14
464
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Matsuki

I like poker and rugby.
MARVEL likes “Hulk”

My motto is concentration x time + luck