Skip to content

Commit

Permalink
Speed up brew module package install & upgrade (ansible-collections#9022
Browse files Browse the repository at this point in the history
)

* Verify installation via `brew install` return code in`_install_current_package` (Skip one brew info)

* Avoid computing `current_package_is_installed` twice in a row

* Verify installation via `brew install` return code in  `_upgrade_current_package(Skip 2 brew commands)

* Add changelog fragment

* Update changelogs/fragments/9022-improve-homebrew-perf.yml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
  • Loading branch information
UnknownPlatypus and felixfontein authored Oct 19, 2024
1 parent 1180843 commit 86166cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9022-improve-homebrew-perf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- homebrew - speed up brew install and upgrade (https://github.com/ansible-collections/community.general/pull/9022).
9 changes: 5 additions & 4 deletions plugins/modules/homebrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def _install_current_package(self):
cmd = [opt for opt in opts if opt]
rc, out, err = self.module.run_command(cmd)

if self._current_package_is_installed():
if rc == 0:
self.changed_count += 1
self.changed_pkgs.append(self.current_package)
self.changed = True
Expand Down Expand Up @@ -600,10 +600,11 @@ def _upgrade_current_package(self):
self.message = 'Invalid package: {0}.'.format(self.current_package)
raise HomebrewException(self.message)

if not self._current_package_is_installed():
current_package_is_installed = self._current_package_is_installed()
if not current_package_is_installed:
command = 'install'

if self._current_package_is_installed() and not self._current_package_is_outdated():
if current_package_is_installed and not self._current_package_is_outdated():
self.message = 'Package is already upgraded: {0}'.format(
self.current_package,
)
Expand All @@ -626,7 +627,7 @@ def _upgrade_current_package(self):
cmd = [opt for opt in opts if opt]
rc, out, err = self.module.run_command(cmd)

if self._current_package_is_installed() and not self._current_package_is_outdated():
if rc == 0:
self.changed_count += 1
self.changed_pkgs.append(self.current_package)
self.changed = True
Expand Down

0 comments on commit 86166cc

Please sign in to comment.