Test
The Test
workflow configure GitHub Actions for your repository to
automatically run tests on pull requests and pushes to specific branches.
The workflow includes steps for linting, testing, and code coverage.
Trigger conditions
-
Pull Requests: The workflow activates whenever a new pull request is created or an existing one is updated. It triggers for pull requests targeting the
main
branch, any branch that begins withfeature/
, or even between feature branches themselves. For example, a pull request fromfeature/new-button
tofeature/new-layout
would also activate the workflow. This ensures automated testing for changes aimed at both the stablemain
branch and ongoing work in feature-specific branches. -
Pushes: The workflow also activates whenever new commits are pushed directly to the
main
branch. This could be a direct commit or a merge from a pull request. This action ensures that themain
branch is continually in a deployable and stable state according to the defined tests and checks.
PHP job
- Runs on
ubuntu-latest
. - Uses a matrix strategy to test against multiple PHP versions.
- Checks out code and caches Composer dependencies.
- Installs dependencies via Composer.
- Runs code linting. Add
CI_LINT_IGNORE_FAILURE
with a value of1
to your repository's variables to ignore linting failures. - Runs tests with coverage. Add
CI_TEST_IGNORE_FAILURE
with a value of1
to your repository's variables to ignore test failures. - Publishes coverage report with a 90% threshold to the associated pull request.
Node.js job
- Runs on
ubuntu-latest
. - Uses a matrix strategy to test against multiple NodeJs versions.
- Checks out code.
- Sets up Node.js environment.
- Runs code linting. Add
CI_LINT_IGNORE_FAILURE
with a value of1
to your repository's variables to ignore linting failures - Runs tests with coverage. Add
CI_TEST_IGNORE_FAILURE
with a value of1
to your repository's variables to ignore test failures.
Shell job
- Runs on a matrix of several OSes.
- Checks out code.
- Sets up Node.js environment.
- Installs BATS testing framework.
- Runs code linting. Add
CI_LINT_IGNORE_FAILURE
with a value of1
to your repository's variables to ignore linting failures - Runs tests with coverage. Add
CI_TEST_IGNORE_FAILURE
with a value of1
to your repository's variables to ignore test failures.
Actions job
Used to validate the GitHub Actions workflow files in the repository.
- Checks out code.
- Runs code linting with
yamllint
using configuration file. - Runs code linting with
actionlint
.
Add CI_ACTIONLINT_IGNORE_FAILURE
with a value of 1
to your repository's variables
to ignore linting failures.
Code coverage
The workflow publishes code coverage reports for PHP and Node.js projects to the relevant pull request. This helps you keep track of code coverage and make sure that new code is sufficiently tested.
Codecov is used to track code coverage using reports generated by test tooling.
The codecov/codecov-action
action is used to send coverage reports to Codecov.
To setup Codecov for your repository, follow the steps in the official Codecov documentation. Note that Codecov is free for open source projects and does not require a secret token to be set up.
An example of a coverage comment in a pull request:
Read more about code coverage reporting in the codecov/codecov-action
.