Skip to content

Commit

Permalink
Fix local checkout of cask repo
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Oct 27, 2023
1 parent cd8cacd commit 98d605a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@ jobs:
# https://github.com/pallets/click/issues/2121#issuecomment-1312773882
# https://gist.github.com/NodeJSmith/e7e37f2d3f162456869f015f842bcf15
PYTHONIOENCODING: "utf8"
# Deactivate Homebrew auto-update and verbose output.
# Deactivate Homebrew verbose output and auto-update.
HOMEBREW_NO_ENV_HINTS: "1"
HOMEBREW_NO_AUTO_UPDATE: "1"
# Do not let brew use its live API to fetch the latest version.
# This variable forces brew to use the local repository instead (which we need in destructive tests to checkout
# formulas from the past): https://github.com/Homebrew/brew/blob/10845a1/Library/Homebrew/env_config.rb#L314-L317
# See: meta_package_manager/tests/test_manager_homebrew.py::TestCask test.
HOMEBREW_NO_INSTALL_FROM_API: "1"
steps:
- uses: actions/[email protected]

Expand Down Expand Up @@ -135,6 +140,12 @@ jobs:
run: |
brew upgrade
brew update
- name: Homebrew - macOS cask repository copy
if: runner.os == 'macOS'
# Clone the full copy of the cask repository, so tests on macOS can locally checkout past versions of casks.
# This is performed by the destructive meta_package_manager/tests/test_manager_homebrew.py::TestCask test.
run: |
brew tap homebrew/cask
- name: Homebrew - Linux install
if: runner.os == 'Linux'
run: |
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This version is not released yet and is under active development.
- \[mpm\] Run bar plugin unittests in their independent, non-parrallel step.
- \[mpm\] Skip testing on intermediate Python versions to speed up CI. Only the oldest and latest supported.
- \[mpm\] Skip configuration-related tests while we investigate test isolation.
- \[mpm\] Fix fetching of full local copy of cask tap in tests to allow for checkout of past formula.
- \[mpm\] Replace unmaintained `bump2version` by `bump-my-version`.

## {gh}`5.13.1 (2023-05-04) <compare/v5.13.0...v5.13.1>`
Expand Down
32 changes: 27 additions & 5 deletions meta_package_manager/tests/test_manager_homebrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@

@pytest.fixture()
def install_cask():
"""A fixture to install a Cask from a specific commit."""

packages = set()
"""List of installed packages."""

def get_cask_path():
def get_cask_tap_path():
"""Default location of Homebrew Cask formulas on macOS.
This is supposed to be a shallow copy of the following Git repository:
https://github.com/Homebrew/homebrew-cask
This is supposed to be a `shallow copy of the official cask repository
<https://github.com/Homebrew/homebrew-cask>`_.
The later can be obtained with:
.. code-block:: shell-session
$ export HOMEBREW_NO_INSTALL_FROM_API="1"
$ brew tap homebrew/cask
"""
process = subprocess.run(
("brew", "--repository"),
Expand All @@ -55,9 +64,22 @@ def get_cask_path():
assert cask_repo.is_dir()
return cask_repo

def git_checkout(package_id, commit):
def get_cask_folder(package_id: str):
"""Get the folder where a Cask is located.
..warning::
As of `aa46114 <https://github.com/Homebrew/homebrew-cask/commit/aa46114>`_,
casks have been moved to a subfolder named after their first letter.
"""
cask_folder = get_cask_tap_path().joinpath(package_id[0])
assert cask_folder.is_absolute()
assert cask_folder.exists()
assert cask_folder.is_dir()
return cask_folder

def git_checkout(package_id: str, commit: str):
process = subprocess.run(
("git", "-C", get_cask_path(), "checkout", commit, f"{package_id}.rb"),
("git", "-C", get_cask_folder(package_id), "checkout", commit, f"{package_id}.rb"),
)
assert not process.stderr
assert process.returncode == 0
Expand Down

0 comments on commit 98d605a

Please sign in to comment.