|
| 1 | +name: 'Update Homebrew Macs' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + python_version: |
| 7 | + description: 'Python version to use for the virtual environment' |
| 8 | + type: string |
| 9 | + required: true |
| 10 | + default: 3.12 |
| 11 | + runners_to_update: |
| 12 | + description: 'The runner label where the update job should run' |
| 13 | + type: string |
| 14 | + required: false |
| 15 | + default: '[ experimental-brew-ci, experimental-brew-ci-2 ]' |
| 16 | + |
| 17 | + push: |
| 18 | + branches: |
| 19 | + - 'master' |
| 20 | + paths: |
| 21 | + - '.github/workflow/update-brew-macs.yml' |
| 22 | + |
| 23 | + #TODO: Remove the below |
| 24 | + pull_request: |
| 25 | + branches: |
| 26 | + - 'master' |
| 27 | + |
| 28 | +env: |
| 29 | + VENV_DIR: ${{ github.workspace }}/ROOT_CI_VENV |
| 30 | + |
| 31 | +jobs: |
| 32 | + update-macos: |
| 33 | + if: github.repository_owner == 'root-project' |
| 34 | + |
| 35 | + permissions: |
| 36 | + contents: read |
| 37 | + |
| 38 | + # Use login shells to have brew and java available |
| 39 | + defaults: |
| 40 | + run: |
| 41 | + shell: bash -leo pipefail {0} |
| 42 | + |
| 43 | + strategy: |
| 44 | + fail-fast: false |
| 45 | + matrix: |
| 46 | + runner-label: ${{ fromJSON(inputs.runners_to_update) }} |
| 47 | + |
| 48 | + runs-on: |
| 49 | + - 'self-hosted' |
| 50 | + - ${{ matrix.runner-label }} |
| 51 | + |
| 52 | + name: Update homebrew and Python |
| 53 | + |
| 54 | + env: |
| 55 | + PYTHON_PACKAGE_BREW: ${{ format('python@{0}', inputs.python_version != '' && inputs.python_version || 3.12 ) }} |
| 56 | + PYTHON_EXECUTABLE: ${{ format('python{0}', inputs.python_version != '' && inputs.python_version || 3.12 ) }} |
| 57 | + OPENJDK_PACKAGE_BREW: openjdk@17 |
| 58 | + |
| 59 | + steps: |
| 60 | + - name: Checkout |
| 61 | + uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + path: src/ |
| 64 | + |
| 65 | + - name: Update brew packages |
| 66 | + run: | |
| 67 | + brew update |
| 68 | + brew install ca-certificates ccache googletest "${OPENJDK_PACKAGE_BREW}" pyenv "${PYTHON_PACKAGE_BREW}" |
| 69 | + echo "Installing official brew deps: $(brew deps --direct --include-build root)" |
| 70 | + brew install $(brew deps --direct --include-build root) |
| 71 | +
|
| 72 | + - name: Run brew cleanup |
| 73 | + run: brew cleanup --prune=7 |
| 74 | + |
| 75 | + - name: Display software versions |
| 76 | + run: | |
| 77 | + java --version || { echo "Probably missing the homebrew link for openjdk: sudo ln -sfn $(brew --prefix "${OPENJDK_PACKAGE_BREW}")/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk"; false; } |
| 78 | + cmake --version || { echo "Error when checking for cmake"; false; } |
| 79 | + which "${PYTHON_EXECUTABLE}" |
| 80 | + "${PYTHON_EXECUTABLE}" --version |
| 81 | +
|
| 82 | + - name: Recreate Python venv |
| 83 | + run: | |
| 84 | + rm -rf ${VENV_DIR} |
| 85 | + $(brew --prefix "${PYTHON_PACKAGE_BREW}")/bin/${PYTHON_EXECUTABLE} -m venv "${VENV_DIR}" |
| 86 | + source "${VENV_DIR}"/bin/activate |
| 87 | + pip3 install --upgrade pip |
| 88 | + cat ${{ github.workspace }}/src/requirements.txt | while read PACKAGE; do |
| 89 | + if [ -n "${PACKAGE%%#*}" ]; then |
| 90 | + PACKAGE="${PACKAGE%%#*}" |
| 91 | + pip3 --no-cache-dir install -U "${PACKAGE}" || echo "::error file=update-brew-macs.yml::Could not install package ${PACKAGE}" |
| 92 | + fi |
| 93 | + done |
| 94 | +
|
| 95 | + - name: Purge pip cache |
| 96 | + run: ${VENV_DIR}/bin/pip3 cache purge |
| 97 | + |
0 commit comments