Problem/Motivation
~
Opening this as an alternative to #3387117: Enable distributed caching in GitLab Runner.
gitlab has an API for fetching artifacts from arbitrary branches and jobs and it recommends this over using the distributed cache, which it looks like may not be shared between issue repositories and the main project (and also isn't enabled on Drupal gitlab yet).
phpstan is the longest job in the lint step, taking 1m51s (and also requiring a lot of cpu), whereas the others complete in less than a minute.
If we can cut phpstan jobs to under one minute, that will potentially mean all pipeline runs return a minute faster.
What this MR does:
1. Configures the phpstan tmp directory so that it's within the workspace
2. Sets phpstan artifacts to always upload.
3. Downloads the phpstan result cache using curl from the gitlab API. This is to avoid using 'needs:' which results in a hard failure if the file isn't available, whereas we need the cache get to fail silently so phpstan can just run without the cache if it's not there. This is to prevent a circular dependency from the job to itself.
Steps to reproduce
https://git.drupalcode.org/project/drupal/-/jobs/2191580 instead of finishing in about 1m44s, finished in 55s. Because phpstan is the slowest lint step, this has the potential to reduce overall pipeline time (currently around 7m30s+ down to about 6m40+
Proposed resolution
Remaining tasks
https://git.drupalcode.org/project/drupal/-/merge_requests/8867 uses the phpstan job itself to generate the cache, but only fetches it from HEAD runs.
https://git.drupalcode.org/project/drupal/-/merge_requests/8871 uses a separate on-commit job to generate the cache, so that we don't create an artifact for it on MR runs.
If we could somehow only create the artifact on HEAD runs that might work, but I couldn't figure how to do this with artifacts:when
for a specific artifact.
Once this is done for phpstan, we can do exactly the same for the cspell cache and possibly more things.