Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ Python is installed via `actions/setup-python@v7`, unless Homebrew is requested.

#### Whether to Install Python with Homebrew

Install Python via Homebrew instead. This only has effect on MacOS.
Install Python via Homebrew instead. This only has effect on MacOS. Only `python@<version>` and its own
dependencies are installed or upgraded; other formulae already present on the runner are left as they are.

```yaml
homebrew-python:
Expand Down
15 changes: 13 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,26 @@ runs:
- name: Setup Python with Homebrew
shell: bash
if: inputs.install-python == 'true' && runner.os == 'macOS' && inputs.homebrew-python == 'true'
env:
# Only touch Python and its own dependencies, not every formula on the runner image
HOMEBREW_NO_AUTO_UPDATE: '1'
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: '1'
HOMEBREW_NO_INSTALL_CLEANUP: '1'
HOMEBREW_NO_ENV_HINTS: '1'
run: |
brew update
brew upgrade --overwrite
brew uninstall --force --ignore-dependencies 'python@${{ inputs.python-version }}' || true
# Dependencies that `brew install` upgrades implicitly are linked without `--overwrite`,
# so upgrade Python's outdated dependencies explicitly first
PYTHON_DEPS="$(brew deps 'python@${{ inputs.python-version }}')"
OUTDATED_DEPS="$(brew outdated --formula --quiet | grep -Fx -f <(echo "$PYTHON_DEPS") || true)"
if [ -n "$OUTDATED_DEPS" ]; then
brew upgrade --overwrite $OUTDATED_DEPS
fi
brew install --overwrite 'python@${{ inputs.python-version }}'
echo "/usr/local/opt/python@${{ inputs.python-version }}/Frameworks/Python.framework/Versions/${{ inputs.python-version }}/bin" >> $GITHUB_PATH
echo "/usr/local/opt/python@${{ inputs.python-version }}/libexec/bin" >> $GITHUB_PATH
echo "/usr/local/opt/python@${{ inputs.python-version }}/bin" >> $GITHUB_PATH
brew cleanup

- name: Python Pre-VENV Check
shell: bash
Expand Down
Loading