From a169e9d7c4eef90226678422cea115b4b041220b Mon Sep 17 00:00:00 2001 From: Jan Willhaus Date: Sat, 3 Feb 2024 22:30:52 +0100 Subject: [PATCH] build: Make use of brewed python deps --- .github/workflows/tests.yaml | 46 +++++++++++++++++++++++++++++++++--- brew/template.rb.j2 | 19 +++++++++------ 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 6008326..562f715 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -8,6 +8,9 @@ on: tags: - "*" +env: + HOMEBREW_NO_AUTO_UPDATE: "1" + jobs: pytest: runs-on: ubuntu-latest @@ -21,13 +24,13 @@ jobs: name: pytest-${{ matrix.python-version }} steps: - name: Check out - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install poetry run: pipx install poetry - name: Set up python environment - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: cache: 'poetry' python-version: ${{ matrix.python-version }} @@ -37,8 +40,45 @@ jobs: - run: poetry run pytest --cov-report=xml - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml name: coverage-${{ matrix.python-version }} + + test-formula: + runs-on: macos-latest + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Install poetry + poetry-brew + run: | + pipx install 'poetry>=1.7.0' + pipx inject poetry poetry-homebrew-formula + + - name: Configure cache + uses: actions/cache@v4 + with: + path: | + ~/Library/Caches/Homebrew/podcast-archiver--* + ~/Library/Caches/Homebrew/downloads/*--podcast-archiver-* + key: brew-${{ hashFiles('poetry.lock') }} + restore-keys: brew- + + - name: Render formula template + shell: bash + run: | + brew tap-new --no-git janw/testing + poetry homebrew-formula \ + --verbose \ + --template brew/template.rb.j2 \ + --output "$(brew --repo janw/testing)/Formula/podcast-archiver.rb" + + - name: Install formula + shell: bash + run: brew install podcast-archiver + + - name: Test formula + shell: bash + run: brew test podcast-archiver diff --git a/brew/template.rb.j2 b/brew/template.rb.j2 index e2a488a..8686eb0 100644 --- a/brew/template.rb.j2 +++ b/brew/template.rb.j2 @@ -10,19 +10,24 @@ class {{ formula_name }} < Formula {{ PACKAGE_URL }} - depends_on "python3" + depends_on "python@3.12" depends_on "rust" => :build -{{ RESOURCES }} + def python3 + "python3.12" + end - def install - virtualenv_create(libexec, "python3") - virtualenv_install_with_resources + def std_pip_args(prefix: self.prefix, build_isolation: false) + ["--verbose", "--ignore-installed"] + end - generate_completions_from_executable(bin/"podcast-archiver", shells: [:bash, :zsh, :fish], shell_parameter_format: :click) + def install + venv = virtualenv_create(libexec, python3, system_site_packages: false) + venv.pip_install_and_link buildpath + generate_completions_from_executable(bin/"podcast-archiver", shells: [:zsh, :fish], shell_parameter_format: :click) end test do - false + assert_match "podcast-archiver, ", shell_output(bin/"podcast-archiver --version") end end