Skip to content

Comments

GH Actions: various tweaks#134

Merged
jrfnl merged 5 commits intodevelopfrom
JRF/ghactions-harden-cs-steps
Nov 5, 2022
Merged

GH Actions: various tweaks#134
jrfnl merged 5 commits intodevelopfrom
JRF/ghactions-harden-cs-steps

Conversation

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Nov 5, 2022

Context

  • CI maintenance

Summary

This PR can be summarized in the following changelog entry:

  • CI maintenance

Relevant technical choices:

GH Actions: harden the workflow against PHPCS ruleset errors

If there is a ruleset error, the cs2pr action doesn't receive an xml report and exits with a 0 error code, even though the PHPCS run failed (though not on CS errors, but on a ruleset error).

This changes the GH Actions workflow to allow for that situation and still fail the build in that case.

GH Actions: clean up after branch rename

Make sure branch names in the branch selection are correct to ensure builds will still run when appropriate.

GH Actions: bust the cache semi-regularly

Caches used in GH Actions do not get updated, they can only be replaced by a different cache with a different cache key.

Now the predefined Composer install action this repo is using already creates a pretty comprehensive cache key:

ramsey/composer-install will auto-generate a cache key which is composed of
the following elements:

  • The OS image name, like ubuntu-latest.
  • The exact PHP version, like 8.1.11.
  • The options passed via composer-options.
  • The dependency version setting as per dependency-versions.
  • The working directory as per working-directory.
  • A hash of the composer.json and/or composer.lock files.

This means that aside from other factors, the cache will always be busted when changes are made to the (committed) composer.json or the composer.lock file (if the latter exists in the repo).

For packages running on recent versions of PHP, it also means that the cache will automatically be busted once a month when a new PHP version comes out.

The problem

For runs on older PHP versions which don't receive updates anymore, the cache will not be busted via new PHP version releases, so effectively, the cache will only be busted when a change is made to the composer.json/composer.lock file - which may not happen that frequently on low-traffic repos.

But... packages in use on those older PHP versions - especially dependencies of declared dependencies - may still release new versions and those new versions will not exist in the cache and will need to be downloaded each time the action is run and over time the cache gets less and less relevant as more and more packages will need to be downloaded for each run.

The solution

To combat this issue, a new custom-cache-suffix option has been added to the Composer install action in version 2.2.0.
This new option allows for providing some extra information to add to the cache key, which allows for busting the cache based on your own additional criteria.

This commit implements the use of this custom-cache-suffix option for all relevant workflows in this repo.

Refs:

GH Actions: don't allow linting issues on PHP 8.2

GH Actions: run the tests against PHP 8.2

... and as the tests currently pass without issue, don't allow the build to fail.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • N/A

jrfnl added 5 commits November 5, 2022 16:37
If there is a ruleset error, the `cs2pr` action doesn't receive an `xml` report and exits with a `0` error code, even though the PHPCS run failed (though not on CS errors, but on a ruleset error).

This changes the GH Actions workflow to allow for that situation and still fail the build in that case.
Make sure branch names in the branch selection are correct to ensure builds will still run when appropriate.
Caches used in GH Actions do not get updated, they can only be replaced by a different cache with a different cache key.

Now the predefined Composer install action this repo is using already creates a pretty comprehensive cache key:

> `ramsey/composer-install` will auto-generate a cache key which is composed of
the following elements:
> * The OS image name, like `ubuntu-latest`.
> * The exact PHP version, like `8.1.11`.
> * The options passed via `composer-options`.
> * The dependency version setting as per `dependency-versions`.
> * The working directory as per `working-directory`.
> * A hash of the `composer.json` and/or `composer.lock` files.

This means that aside from other factors, the cache will always be busted when changes are made to the (committed) `composer.json` or the `composer.lock` file (if the latter exists in the repo).

For packages running on recent versions of PHP, it also means that the cache will automatically be busted once a month when a new PHP version comes out.

### The problem

For runs on older PHP versions which don't receive updates anymore, the cache will not be busted via new PHP version releases, so effectively, the cache will only be busted when a change is made to the `composer.json`/`composer.lock` file - which may not happen that frequently on low-traffic repos.

But... packages _in use_ on those older PHP versions - especially dependencies of declared dependencies - may still release new versions and those new versions will not exist in the cache and will need to be downloaded each time the action is run and over time the cache gets less and less relevant as more and more packages will need to be downloaded for each run.

### The solution

To combat this issue, a new `custom-cache-suffix` option has been added to the Composer install action in version 2.2.0.
This new option allows for providing some extra information to add to the cache key, which allows for busting the cache based on your own additional criteria.

This commit implements the use of this `custom-cache-suffix` option for all relevant workflows in this repo.

Refs:
* https://github.com/ramsey/composer-install/#custom-cache-suffix
* https://github.com/ramsey/composer-install/releases/tag/2.2.0
... and as the tests currently pass without issue, don't allow the build to fail.
@jrfnl jrfnl added this to the Next release milestone Nov 5, 2022
@jrfnl jrfnl changed the title Jrf/ghactions harden cs steps GH Actions: various tweaks Nov 5, 2022
@jrfnl jrfnl merged commit 25ce100 into develop Nov 5, 2022
@jrfnl jrfnl deleted the JRF/ghactions-harden-cs-steps branch November 5, 2022 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant