Enable caching for github actions (#43)

This commit is contained in:
ian_Cin 2023-10-12 13:52:19 +07:00 committed by GitHub
parent 84f1fa8cbd
commit 533fffa6db
3 changed files with 40 additions and 9 deletions

View File

@ -8,25 +8,53 @@ on:
jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
include:
- os: ubuntu-latest
ACTIVATE_ENV: ". env/bin/activate"
GITHUB_OUTPUT: "$GITHUB_OUTPUT"
# - os: windows-latest
# ACTIVATE_ENV: env/Scripts/activate.ps1
# GITHUB_OUTPUT: "$env:GITHUB_OUTPUT"
name: unit testing with python ${{ matrix.python-version }}
steps:
- name: Clone the repo
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }} on ${{ runner.os }}
uses: actions/setup-python@v4
id: setup_python
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
- name: Get package version
id: get-package-version
run: |
echo "version=$(python setup.py --version)" | tee -a ${{ matrix.GITHUB_OUTPUT }}
- name: Try to restore env from ${{ runner.os }}-py${{ matrix.python-version }}-v${{ steps.get-package-version.outputs.version }}
id: restore-env
uses: actions/cache/restore@v3
with:
path: env
key: ${{ runner.os }}-py${{ matrix.python-version }}-v${{ steps.get-package-version.outputs.version }}
- name: Create new env if no cache hit
if: steps.restore-env.outputs.cache-hit != 'true'
run: |
python -m venv env
${{ matrix.ACTIVATE_ENV }}
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Cache new env for key ${{ steps.restore-env.outputs.cache-primary-key }}
if: steps.restore-env.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: env
key: ${{ steps.restore-env.outputs.cache-primary-key }}
- name: Test with pytest
run: |
pytest
${{ matrix.ACTIVATE_ENV }}
python -m pytest

View File

@ -61,7 +61,7 @@ setuptools.setup(
],
},
entry_points={"console_scripts": ["kh=kotaemon.cli:main"]},
python_requires=">=3",
python_requires=">=3.8",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",

View File

@ -11,14 +11,17 @@ input_file_excel = Path(__file__).parent / "resources" / "dummy.xlsx"
@pytest.fixture
def fullocr_output():
with open(Path(__file__).parent / "resources" / "fullocr_sample_output.json") as f:
with open(
Path(__file__).parent / "resources" / "fullocr_sample_output.json",
encoding="utf-8",
) as f:
fullocr = json.load(f)
return fullocr
@pytest.fixture
def mathpix_output():
with open(Path(__file__).parent / "resources" / "policy.md") as f:
with open(Path(__file__).parent / "resources" / "policy.md", encoding="utf-8") as f:
content = f.read()
return content