It turns out npm install actually changes the package-lock.json file (which makes no sense to me, coming from Composer...), and that busts the cache. So npm ci is the better install command for caching the dependencies. Hope this is useful to someone!
Dec 8, 2024
5
Level 1
Please rate my CI strategy for caching vendor/ :)
Currently my CI runs the following for every test/deployment
// TEST STAGE
git clone
composer install
npm install
npm run build
// run tests
// delete vendor
// DEPLOY STAGE
composer install --no-dev --classmap-authoritative
// copy to server
I want to speed this up by caching 3 directories: vendor/ (dev), vendor/ (no-dev) and node_modules/. In psuedocode, I plan to replace composer install with:
if (composer.lock == cached composer.lock)
copy cached vendor
if (is_deploy_stage) composer dump-autoload --no-dev --classmap-authoritative
else
if (is_deploy_stage) composer install --no-dev --classmap-authoritative
else composer install
cache vendor
And replace npm install with:
if (package-lock.json == cached package-lock.json)
copy cached node_modules
else
npm install
cache node_modules
- Can you see anything wrong with this? Or anything missing?
- I'm not familiar with npm. I assume there's no need for a 'dump-autoload' equivalent when using an old cache with new code?
- How about
--dev --classmap-authoritativefor Test Stage, so that bad class references might be caught? - Is it ok for all developers to just run
composer updateandnpm updateas a morning/pre-commit ritual, or should they be run with more care (given that all dependencies are ^ed to major versions)?
Please or to participate in this conversation.