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
2 changes: 1 addition & 1 deletion .github/actions/behavior_test_binding_java/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

name: Test Core
name: Test Binding Java
description: 'Test Core with given setup and service'
inputs:
setup:
Expand Down
51 changes: 51 additions & 0 deletions .github/actions/behavior_test_binding_python/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Test Binding Python
description: 'Test Core with given setup and service'
inputs:
setup:
description: "The setup action for test"
service:
description: "The service to test"
feature:
description: "The feature to test"

runs:
using: "composite"
steps:
- name: Setup
shell: bash
run: |
mkdir -p ./dynamic_test_binding_python &&
cat <<EOF >./dynamic_test_binding_python/action.yml
runs:
using: composite
steps:
- name: Setup Test
uses: ./.github/services/${{ inputs.service }}/${{ inputs.setup }}
- name: Run Test Binding Python
shell: bash
working-directory: bindings/python
run: |
source venv/bin/activate
pytest -v tests
env:
OPENDAL_TEST: ${{ inputs.service }}
EOF
- name: Run
uses: ./dynamic_test_binding_python
51 changes: 46 additions & 5 deletions .github/scripts/behavior_test/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import re
from pathlib import Path
from dataclasses import dataclass, field
from typing import Any

# The path for current script.
SCRIPT_PATH = Path(__file__).parent.absolute()
Expand All @@ -31,7 +32,7 @@
PROJECT_DIR = GITHUB_DIR.parent


def provided_cases():
def provided_cases() -> list[dict[str, str]]:
root_dir = f"{GITHUB_DIR}/services"

cases = [
Expand Down Expand Up @@ -74,14 +75,16 @@ class Hint:
core: bool = field(default=False, init=False)
# Is binding java affected?
binding_java: bool = field(default=False, init=False)
# Is binding python affected?
binding_python: bool = field(default=False, init=False)

# Should we run all services test?
all_service: bool = field(default=False, init=False)
# affected services set.
services: set = field(default_factory=set, init=False)


def calculate_hint(changed_files):
def calculate_hint(changed_files: list[str]) -> Hint:
hint = Hint()

# Remove all files that ends with `.md`
Expand All @@ -95,12 +98,14 @@ def calculate_hint(changed_files):
if p == ".github/workflows/behavior_test.yml":
hint.core = True
hint.binding_java = True
hint.binding_python = True
hint.all_service = True
if p == ".github/workflows/behavior_test_core.yml":
hint.core = True
hint.all_service = True
if p == ".github/workflows/behavior_test_binding_java.yml":
hint.binding_java = True
hint.binding_python = True
hint.all_service = True

# core affected
Expand All @@ -113,25 +118,29 @@ def calculate_hint(changed_files):
):
hint.core = True
hint.binding_java = True
hint.binding_python = True
hint.all_service = True

# binding java affected.
if p.startswith("bindings/java/"):
hint.binding_java = True
hint.binding_python = True
hint.all_service = True

# core service affected
match = re.search(service_pattern, p)
if match:
hint.core = True
hint.binding_java = True
hint.binding_python = True
hint.services.add(match.group(1))

# core test affected
match = re.search(test_pattern, p)
if match:
hint.core = True
hint.binding_java = True
hint.binding_python = True
hint.services.add(match.group(1))

return hint
Expand All @@ -154,7 +163,9 @@ def unique_cases(cases):
return list(ucases.values())


def generate_core_cases(cases, hint):
def generate_core_cases(
cases: list[dict[str, str]], hint: Hint
) -> list[dict[str, str]]:
# Always run all tests if it is a push event.
if os.getenv("GITHUB_IS_PUSH") == "true":
return cases
Expand All @@ -172,7 +183,9 @@ def generate_core_cases(cases, hint):
return cases


def generate_binding_java_cases(cases, hint):
def generate_binding_java_cases(
cases: list[dict[str, str]], hint: Hint
) -> list[dict[str, str]]:
cases = unique_cases(cases)

# Always run all tests if it is a push event.
Expand All @@ -192,20 +205,43 @@ def generate_binding_java_cases(cases, hint):
return cases


def plan(changed_files):
def generate_binding_python_cases(
cases: list[dict[str, str]], hint: Hint
) -> list[dict[str, str]]:
cases = unique_cases(cases)
if os.getenv("GITHUB_IS_PUSH") == "true":
return cases

# Return empty if core is False
if not hint.binding_python:
return []

# Return all services if all_service is True
if hint.all_service:
return cases

# Filter all cases that not shown un in changed files
cases = [v for v in cases if v["service"] in hint.services]
return cases


def plan(changed_files: list[str]) -> dict[str, Any]:
cases = provided_cases()
hint = calculate_hint(changed_files)

core_cases = generate_core_cases(cases, hint)
binding_java_cases = generate_binding_java_cases(cases, hint)
binding_python_cases = generate_binding_python_cases(cases, hint)

jobs = {
"components": {
"core": False,
"binding_java": False,
"binding_python": False,
},
"core": [],
"binding_java": [],
"binding_python": [],
}

if len(core_cases) > 0:
Expand All @@ -228,6 +264,11 @@ def plan(changed_files):
jobs["binding_java"].append(
{"os": "ubuntu-latest", "cases": binding_java_cases}
)
if len(binding_python_cases) > 0:
jobs["components"]["binding_python"] = True
jobs["binding_python"].append(
{"os": "ubuntu-latest", "cases": binding_python_cases}
)

return jobs

Expand Down
8 changes: 7 additions & 1 deletion .github/services/mysql/mysql/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ runs:
- name: Setup MySQL Server
shell: bash
working-directory: fixtures/mysql
run: docker-compose -f docker-compose.yml up -d
run: |
apt update && apt install -y mysql-client
docker-compose -f docker-compose.yml up -d
while ! mysql -h localhost -P 3306 --protocol=tcp -u root -p'password' -e "SELECT 1"; do
echo "Waiting for MySQL..."
sleep 1
done
- name: Setup
shell: bash
run: |
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/behavior_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,15 @@ jobs:
with:
os: ${{ matrix.os }}
cases: ${{ toJson(matrix.cases) }}
test_binding_python:
name: binding_python / ${{ matrix.os }}
needs: [plan]
if: fromJson(needs.plan.outputs.plan).components.binding_python
secrets: inherit
strategy:
matrix:
include: ${{ fromJson(needs.plan.outputs.plan).binding_python }}
uses: ./.github/workflows/behavior_test_binding_python.yml
with:
os: ${{ matrix.os }}
cases: ${{ toJson(matrix.cases) }}
71 changes: 71 additions & 0 deletions .github/workflows/behavior_test_binding_python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Behavior Test Binding Python

on:
workflow_call:
inputs:
os:
required: true
type: string
cases:
required: true
type: string

jobs:
test:
name: ${{ matrix.cases.service }} / ${{ matrix.cases.setup }}
runs-on: ${{ inputs.os }}
strategy:
matrix:
cases: ${{ fromJson(inputs.cases) }}
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
need-nextest: true
need-protoc: true
need-rocksdb: true
github-token: ${{ secrets.GITHUB_TOKEN }}

# TODO: 1password is only supported on linux
#
# Waiting for https://github.com/1Password/load-secrets-action/issues/46
- name: Setup service account token for 1password
if: runner.os == 'Linux'
shell: bash
run: echo "OP_SERVICE_ACCOUNT_TOKEN=${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}" >> $GITHUB_ENV
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Build with maturin
shell: bash
working-directory: "bindings/python"
run: |
python -m venv venv
source venv/bin/activate
pip install maturin[patchelf]
maturin develop -E test -F ${{ matrix.cases.feature }}

- name: Test Core
uses: ./.github/actions/behavior_test_binding_python
with:
setup: ${{ matrix.cases.setup }}
service: ${{ matrix.cases.service }}
feature: ${{ matrix.cases.feature }}
19 changes: 0 additions & 19 deletions .github/workflows/bindings_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,6 @@ permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Setup Rust toolchain
uses: ./.github/actions/setup
- name: Build with maturin
working-directory: "bindings/python"
run: |
python -m pip install -e .[test]
- name: Run pytest
working-directory: "bindings/python"
env:
OPENDAL_MEMORY_TEST: on
run: |
pytest -vk TestMemory

sdist:
runs-on: ubuntu-latest
Expand Down
Loading