Notes on software development

How to create a PHP package. Part 5: GitHub Actions

This is the last chapter on creating a PHP package. It will be a quick overview of github actions without details and in the end I will provide a final script for the flow. 

GitHub Actions

Github actions is built-in into github and allows easily create custom workflows in repositories. It can run specific command when a certain event is accrued.

To initialize a github actions, you need to create a .yml file in you repo under the folder ".github/workflows/". The name of the file can be any. I called it "php_ci.yml".

This file consists of 4 main parts:

  • events
    • jobs
      • steps
        • actions

I want to run a pipeline when someone creates a pull request or push changes to the master branch.

I will split my workflow into two jobs:

  1. run units;

  2. run code style check.

We already have commands for that in composer.json.

Besides that, I want to run my jobs on two php versions: 8.1 and 8.2. And my actions/commands are:

  1. setup php with pre-build action.

  2. check php version

  3. checks-out current repository under $GITHUB_WORKSPACE to let the workflow can access it.

  4. validate composer.json and composer.lock

  5. run composer install

  6. Run PHPUnit / linter

You can find full file below:

Now each pull request or push to the master branch will trigger this workflow. You can check output on the actions page:

github actions


For now that's all I wanted to tell about php package development. If you have questions, as always, please, leave a comment. Thank you for reading these articles. I hope you have found something useful and maybe learned something new.

Комментарии