Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH Actions: mixed bag of improvements #113

Merged
merged 7 commits into from
Nov 11, 2021

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Nov 11, 2021

GH Actions: another ini tweak

Follow up on #99: also enable assertions, which are turned off by default when using setup-php@v2.

GH Actions: use PHP Parallel Lint

... for faster linting results.

Ref: https://github.com/php-parallel-lint/PHP-Parallel-Lint/

The results of PHP Parallel Lint can also be used in combination with cs2pr to show any issues in-line in the GH (PR) code view.

GH Actions: cache downloads for Composer

... for faster builds and to be kind to the resources which GH provides freely.

The caching is handled by using a predefined GH action specifically created for this purpose.
The alternative would be to handle the caching manually, which would add three extra steps to the script.

Refs:

GH Actions: selectively run tests with code coverage

As it was, the setup-php action would always install with xdebug enabled, making all PHP tasks slower and tests would always be run with code coverage being generated, while the coverage report was only used (uploaded to CodeCov) on PHP 7.4.

This commit changes that to:

  • Only enable Xdebug for the PHP 7.4 build.
  • Only run the tests with code coverage on PHP 7.4.

GH Actions: run tests against highest/lowest versions of dependencies

Run tests against the highest and lowest versions of the dependencies.

To do so, this commit:

  • Expands the matrix to include a new dependency-versions key.
    It also special cases the build against PHP 8.2, as running PHP against lowest won't be any use for the time being.
  • Passes the new dependency-versions key to the composer-install action to allow composer to install either with --prefer-lowest or to install via composer update and get the highest available versions of dependencies.
    Ref: https://github.com/ramsey/composer-install/#dependency-versions
  • Adds (extra) conditions to the linting and PHPCompat tasks as those only need to be run once per PHP version / once per build, respectively.
  • Adjusts the conditions for the test runs so that the code coverage is only generated and uploaded for the PHP 7.4 + highest build.

GH Actions: auto-cancel previous builds for same branch

When the same branch is pushed again (and again), builds queues can start piling up.

The configuration now added, will auto-cancel any builds from previous pushes, whether already running or still waiting.

More than anything, this is a way to be kind to GitHub by not wasting resources which they so kindly provide to us for free.

Refs:

GH Actions: allow for manually triggering a workflow

Triggering a workflow for a branch manually is not supported by default in GH Actions, but has to be explicitly allowed.

This is useful if, for instance, an external action script or composer dependency has broken.
Once a fix is available, failing builds for open PRs can be retriggered manually instead of having to be re-pushed to retrigger the workflow.

Ref: https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/

Follow up on 99: also enable assertions, which are turned off by default when using `setup-php@v2`.
... for faster linting results.

Ref: https://github.com/php-parallel-lint/PHP-Parallel-Lint/

The results of PHP Parallel Lint can also be used in combination with [cs2pr](https://github.com/staabm/annotate-pull-request-from-checkstyle) to show any issues in-line in the GH (PR) code view.
... for faster builds and to be kind to the resources which GH provides freely.

The caching is handled by using a [predefined GH action](https://github.com/marketplace/actions/install-composer-dependencies) specifically created for this purpose.
The alternative would be to handle the caching manually, which would add three extra steps to the script.

Refs:
* https://docs.github.com/en/actions/advanced-guides/caching-dependencies-to-speed-up-workflows
* https://github.com/ramsey/composer-install/
As it was, the `setup-php` action would always install with `xdebug` enabled, making all PHP tasks slower and tests would always be run with code coverage being generated, while the coverage report was only used (uploaded to CodeCov) on PHP 7.4.

This commit changes that to:
* Only enable Xdebug for the PHP 7.4 build.
* Only run the tests with code coverage on PHP 7.4.
Run tests against the highest and lowest versions of the dependencies.

To do so, this commit:
* Expands the matrix to include a new `dependency-versions` key.
    It also special cases the build against PHP 8.2, as running PHP against `lowest` won't be any use for the time being.
* Passes the new `dependency-versions` key to the `composer-install` action to allow composer to install either with `--prefer-lowest` or to install via `composer update` and get the highest available versions of dependencies.
    Ref: https://github.com/ramsey/composer-install/#dependency-versions
* Adds (extra) conditions to the linting and PHPCompat tasks as those only need to be run once per PHP version / once per build, respectively.
* Adjusts the conditions for the test runs so that the code coverage is only generated and uploaded for the `PHP 7.4 + highest` build.
When the same branch is pushed again (and again), builds queues can start piling up.

The configuration now added, will auto-cancel any builds from previous pushes, whether already running or still waiting.

More than anything, this is a way to be kind to GitHub by not wasting resources which they so kindly provide to us for free.

Refs:
* https://github.blog/changelog/2021-04-19-github-actions-limit-workflow-run-or-job-concurrency/
* https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency
Triggering a workflow for a branch manually is not supported by default in GH Actions, but has to be explicitly allowed.

This is useful if, for instance, an external action script or composer dependency has broken.
Once a fix is available, failing builds for open PRs can be retriggered manually instead of having to be re-pushed to retrigger the workflow.

Ref: https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
@jrfnl jrfnl added this to the 2.6.1 milestone Nov 11, 2021
@jrfnl jrfnl requested a review from gmazzap November 11, 2021 15:41
Copy link
Collaborator

@gmazzap gmazzap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again.

@gmazzap gmazzap merged commit a31c845 into master Nov 11, 2021
@jrfnl jrfnl deleted the feature/ghactions-adjust-matrix branch November 11, 2021 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants