Testing Laravel with PHPUnit and GitHub Actions
This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.
GitHub recently announced a new release of GitHub Actions which allows you to automate workflows in response to events that occur in your repos. One key new feature in the new release is the ability to use GitHub as your CI/CD tool. Instead of having a third-party build your commits/pull requests you now have the ability to run it all in the GitHub ecosystem. It's free for public repos, and you get 2,000 free minutes for private repos or 3,000 free minutes if you have a pro account. If you don't have access already, be sure to sign up for the beta.
Once you have access to the beta (you'll get an email, and the "Actions" tab will appear on your repo) you can start adding workflows. Here's my boilerplate for building my Laravel app - including building front-end assets - which I've placed in .github/workflows/ci.yml
.
You can explore the documenation to exercise greater control over different parts of the environemnt - if you wanted to use an earlier version of Node or PHP, for example. Though the documentation isn't fully fleshed out for PHP just yet composer
and a number of php7.x
executables are still available.
Environment variables/secrets
In addition you might need to inject environment variables into your build process - I needed in order to get Laravel Nova installed. First, go to your repo's settings tab and then click secrets. For Laravel Nova I added a COMPOSER_AUTH
environment variable, which Composer will use out of the box to authenticate correctly during installation.
Then you can adjust your install script to be aware the specific secrets you need and use them appropriately.
It works just the same if you had other variables you wanted to use in your scripts.
Deployment
Still working on getting a tight solution to deploy straight to Laravel Vapor, and I'll post it here once it's ready.