Reduce GitHub actions workflow duration using brew on macOS runner
This article is based on my own experiences, and it can not be best way. So please comment and share something you find.
TL;DR
- Skip
brew update
if possible - Use
HOMEBREW_NO_AUTO_UPDATE
to skip automatically update inbrew install
- Use
HOMEBREW_NO_INSTALL_CLEANUP
to skip automatically clean up inbrew install
actions/cache
cannot reduce duration so much, sometimes increase
Details
update
- Most of duration seems used for updating, so it is important to skip that
- Of course it can occur side effects, you have to consider
- It is not enough to skip
brew update
for skipping update completely - Use
HOMEBREW_NO_AUTO_UPDATE
to skip automatically update inbrew install
- Specify as environment variable in step using
brew install
- Specify as environment variable in step using
env: HOMEBREW_NO_AUTO_UPDATE: 1
or
run: HOMEBREW_NO_AUTO_UPDATE=1 brew install foobar
cache
actions/cache
provides system to cache and restore directory tree- But there are some difficulties to cache
brew
artifacts- Modules installed by
brew
don't exist in unified dir tree, so it is difficult to cache them- If you can defeat difficulties and cache installed modules completely, it can reduce duration so much
- Download cache dir is usually
~/Library/Caches/Homebrew
- It can skip downloading if cache that directory, but it doesn't reduce duration so much or it sometimes increases duration
- It takes a few minutes to restore cache
- It is better to call
brew cleanup -s
for shrink cache size, but it takes a few minutes
- Modules installed by
tap
- I have not investigated enough, but it may make little effect to
brew untap
unnecessary pre-installed taps- Because it may caused already skipping update