Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh actions with xapian wheels and caching #2

Closed
wants to merge 14 commits into from
Closed
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
104 changes: 104 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Test

on: [push, pull_request]

env:
FORCE_COLOR: 1

jobs:
prebuild_xapian_wheel:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6]
xapian-version: [1.4.18]

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Checkout xapian-haystack
uses: actions/checkout@v2

- name: Check for cached xapian wheel
# https://github.com/actions/cache#cache-limits
# says this cached wheel will be evicted after a week unused.
id: xapian-cache
uses: actions/cache@v2
with:
path: xapian*.whl
key: xapian-${{ matrix.xapian-version }}-${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('xapian_wheel_builder.sh') }}

- name: Build xapian wheel
if: steps.xapian-cache.outputs.cache-hit != 'true'
run: |
./xapian_wheel_builder.sh ${{ matrix.xapian-version }}

test:
needs: prebuild_xapian_wheel
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6]
django-version: [2.2]
xapian-version: [1.4.18]

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Checkout xapian-haystack
uses: actions/checkout@v2

- name: Check for cached xapian wheel
# This will always succeed since the previous job just ran.
id: xapian-cache
uses: actions/cache@v2
with:
path: xapian*.whl
key: xapian-${{ matrix.xapian-version }}-${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('xapian_wheel_builder.sh') }}

- name: Install Django and other Python dependencies
run: |
python -m pip install --upgrade pip
pip install django~=${{ matrix.django-version }} coveralls xapian*.whl

- name: Checkout django-haystack
uses: actions/checkout@v2
with:
repository: 'django-haystack/django-haystack'
path: django-haystack

- name: Copy some test files to django-haystack
run: |
cp xapian_backend.py django-haystack/haystack/backends/
cp -r tests/* django-haystack/test_haystack/
cp tests/xapian_tests/__init__.py django-haystack/test_haystack/
cp .coveragerc django-haystack/

- name: Set PYTHONPATH
run: |
echo "PYTHONPATH=/usr/lib/python3/dist-packages:." >> $GITHUB_ENV

- name: Ensure all apps have migrations
run: |
cd django-haystack
django-admin makemigrations --settings=test_haystack.xapian_settings

- name: Running tests
run: |
cd django-haystack
coverage run $(command -v django-admin) test test_haystack.xapian_tests --settings=test_haystack.xapian_settings
env:
PYTHONPATH: "/usr/lib/python3/dist-packages:."

- name: Coveralls
run: |
cd django-haystack
coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63 changes: 0 additions & 63 deletions .travis.yml

This file was deleted.

15 changes: 8 additions & 7 deletions tests/xapian_tests/tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from decimal import Decimal
import datetime
import inspect
import sys
import xapian
import subprocess
Expand Down Expand Up @@ -30,17 +31,17 @@ def __init__(self, app_label, model_name, pk, score, **kwargs):


def get_terms(backend, *args):
if XAPIAN_VERSION[1] <= 2:
# old versions use "delve".
executable = 'delve'
else:
# new versions use 'xapian-delve'
executable = 'xapian-delve'
executable = 'xapian-delve'

# dev versions (odd minor) use a suffix
if XAPIAN_VERSION[1] % 2 != 0:
executable = executable+'-%d.%d' % tuple(XAPIAN_VERSION[0:2])

# look for a xapian-delve built by `xapian_wheel_builder`
wheel_delve = os.path.join(os.path.dirname(inspect.getfile(xapian)), executable)
if os.path.exists(wheel_delve):
executable = wheel_delve

result = subprocess.check_output([executable] + list(args) + [backend.path],
env=os.environ.copy()).decode('utf-8')
result = result.split(": ")
Expand Down Expand Up @@ -482,7 +483,7 @@ def test_highlight(self):

results = self.backend.search(xapian.Query('indexed'), highlight=True)['results']
self.assertEqual([result.highlighted['text'] for result in results],
['<em>indexed</em>!\n1', '<em>indexed</em>!\n2', '<em>indexed</em>!\n3'])
['<em>indexed</em>!\n1\n', '<em>indexed</em>!\n2\n', '<em>indexed</em>!\n3\n'])

def test_spelling_suggestion(self):
self.assertEqual(self.backend.search(xapian.Query('indxe'))['hits'], 0)
Expand Down
14 changes: 12 additions & 2 deletions xapian_wheel_builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ echo "Building xapian python3 bindings..."
make install
)

echo "preparing xapian wheel..."
for file in "${prefix}"/xapian/*.so; do
binary_patch_rpath() {
file="${1}"
case "${uname_sysname}" in
Linux|FreeBSD)
# Binary patch rpath to be '$ORIGIN' as needed.
Expand All @@ -151,6 +151,11 @@ for file in "${prefix}"/xapian/*.so; do
install_name_tool -change "${prefix}/lib/${libxapian_name}" "@loader_path/${libxapian_name}" "${file}"
;;
esac
}

echo "preparing xapian wheel..."
for file in "${prefix}"/xapian/*.so; do
binary_patch_rpath "${file}"
done

# Copy libxapian into place alongside the python bindings.
Expand All @@ -161,6 +166,11 @@ case "${uname_sysname}" in
;;
esac

for file in "${prefix}"/bin/xapian-delve*; do
binary_patch_rpath "${file}"
cp "${file}" "${prefix}/xapian"
done

# Prepare the scaffolding for the wheel
cat > "$prefix/setup.py" <<EOF
from setuptools import setup
Expand Down