Skip to content

Commit

Permalink
fix(python): 3.8 compatibility and CI multi-version [skip-bc] (#3613)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Millot <[email protected]>
  • Loading branch information
shortcuts and millotp committed Aug 29, 2024
1 parent df527e1 commit 036f9ac
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 105 deletions.
34 changes: 12 additions & 22 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
language:
description: the language for which to install deps
required: false
version:
description: the version of the language to setup
required: false

runs:
using: composite
Expand Down Expand Up @@ -48,19 +51,6 @@ runs:
shell: bash
run: yarn workspace scripts build:cli

- name: Get all languages versions
id: versions
shell: bash
run: |
# remove patch from php version
echo "CSHARP_VERSION=$(cat config/.csharp-version)" >> $GITHUB_OUTPUT
echo "DART_VERSION=$(cat config/.dart-version)" >> $GITHUB_OUTPUT
echo "GO_VERSION=$(cat config/.go-version)" >> $GITHUB_OUTPUT
echo "PHP_VERSION=$(cat config/.php-version | cut -d '.' -f 1,2)" >> $GITHUB_OUTPUT
echo "PYTHON_VERSION=$(cat config/.python-version)" >> $GITHUB_OUTPUT
echo "RUBY_VERSION=$(cat config/.ruby-version)" >> $GITHUB_OUTPUT
echo "SWIFT_VERSION=$(cat config/.swift-version)" >> $GITHUB_OUTPUT
# JavaScript client deps
- name: Get yarn js-client cache directory path
if: ${{ inputs.language == 'javascript' }}
Expand Down Expand Up @@ -92,7 +82,7 @@ runs:
if: ${{ inputs.language == 'php' }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ steps.versions.outputs.PHP_VERSION }}
php-version: ${{ inputs.version }}
tools: composer

- name: Run composer install
Expand All @@ -108,7 +98,7 @@ runs:
uses: actions/setup-go@v5
with:
cache-dependency-path: clients/algoliasearch-client-go/go.sum
go-version: ${{ steps.versions.outputs.GO_VERSION }}
go-version: ${{ inputs.version }}

- name: Install golangci-lint
if: ${{ inputs.language == 'go' }}
Expand All @@ -123,7 +113,7 @@ runs:
uses: actions/cache@v4
with:
path: ~/.cache/golangci-lint
key: golangci-lint-${{ steps.versions.outputs.GO_VERSION }}-${{ hashFiles('clients/algoliasearch-client-go/go.sum') }}
key: golangci-lint-${{ inputs.version }}-${{ hashFiles('clients/algoliasearch-client-go/go.sum') }}

# Kotlin
- name: Cache spotless
Expand All @@ -138,7 +128,7 @@ runs:
if: ${{ inputs.language == 'dart' }}
uses: dart-lang/setup-dart@v1
with:
sdk: ${{ steps.versions.outputs.DART_VERSION }}
sdk: ${{ inputs.version }}

- name: Setup dart tools
if: ${{ inputs.language == 'dart' }}
Expand All @@ -154,7 +144,7 @@ runs:
- uses: actions/setup-python@v5
if: ${{ inputs.language == 'python' }}
with:
python-version: ${{ steps.versions.outputs.PYTHON_VERSION }}
python-version: ${{ inputs.version }}
cache: 'poetry'

- run: poetry install
Expand All @@ -167,7 +157,7 @@ runs:
if: ${{ inputs.language == 'ruby' }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ steps.versions.outputs.RUBY_VERSION }}
ruby-version: ${{ inputs.version }}
bundler-cache: true

- name: Install Ruby formatter
Expand All @@ -184,7 +174,7 @@ runs:
if: ${{ inputs.language == 'csharp' }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ steps.versions.outputs.CSHARP_VERSION }}
dotnet-version: ${{ inputs.version }}

# Swift deps
- name: Install swift
Expand All @@ -195,7 +185,7 @@ runs:
# uses: swift-actions/setup-swift@v2
uses: redsun82/setup-swift@b2b6f77ab14f6a9b136b520dc53ec8eca27d2b99
with:
swift-version: ${{ steps.versions.outputs.SWIFT_VERSION }}
swift-version: ${{ inputs.version }}

- name: Cache the build folder
id: cache-swift-build
Expand All @@ -205,7 +195,7 @@ runs:
path: |
clients/algoliasearch-client-swift/.build
tests/output/swift/.build
key: swift-build-${{ steps.versions.outputs.SWIFT_VERSION }}-${{ runner.os }}
key: swift-build-${{ inputs.version }}-${{ runner.os }}

- name: Set swiftformat version
if: ${{ inputs.language == 'swift' }}
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ jobs:
SWIFT_DATA: ${{ steps.gen-matrix.outputs.SWIFT_DATA }}
RUN_MACOS_SWIFT_CTS: ${{ steps.gen-matrix.outputs.RUN_MACOS_SWIFT_CTS }}

KOTLIN_DATA: ${{ steps.gen-matrix.outputs.KOTLIN_DATA }}
RUN_MACOS_KOTLIN_BUILD: ${{ steps.gen-matrix.outputs.RUN_MACOS_KOTLIN_BUILD }}

scripts:
Expand Down Expand Up @@ -183,6 +184,7 @@ jobs:
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
MONITORING_API_KEY: ${{ secrets.MONITORING_API_KEY }}
name: client javascript@${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).version }}
steps:
- uses: actions/checkout@v4

Expand All @@ -203,6 +205,7 @@ jobs:
uses: ./.github/actions/setup
with:
language: javascript
version: ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).version }}

- name: Generate clients
run: yarn cli generate javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun }}
Expand Down Expand Up @@ -295,6 +298,7 @@ jobs:
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
MONITORING_API_KEY: ${{ secrets.MONITORING_API_KEY }}
name: client ${{ matrix.client.language }}@${{ matrix.client.version }}
steps:
- uses: actions/checkout@v4

Expand All @@ -307,16 +311,17 @@ jobs:
uses: ./.github/actions/setup
with:
language: ${{ matrix.client.language }}
version: ${{ matrix.client.version }}

- name: Generate clients
run: yarn cli generate ${{ matrix.client.language }} ${{ matrix.client.toRun }}

- name: Update composer.lock
if: ${{ matrix.client.language == 'php' && startsWith(env.head_ref, 'chore/renovateBaseBranch') }}
if: ${{ matrix.client.language == 'php' && startsWith(env.head_ref, 'chore/renovateBaseBranch') && matrix.client.isMainVersion }}
run: cd ${{ matrix.client.path }} && composer update

- name: Check for file duplicates in Swift
if: ${{ matrix.client.language == 'swift' }}
if: ${{ matrix.client.language == 'swift' && matrix.client.isMainVersion }}
run: |
set -eo pipefail
cd clients/algoliasearch-client-swift
Expand All @@ -330,7 +335,7 @@ jobs:
run: yarn cli build playground ${{ matrix.client.language }}

- name: Run Java 'algoliasearch' public API validation
if: ${{ matrix.client.language == 'java' && !contains(format('{0} {1}', github.event.pull_request.title, github.event.head_commit.message), '[skip-bc]') }}
if: ${{ matrix.client.language == 'java' && matrix.client.isMainVersion && !contains(format('{0} {1}', github.event.pull_request.title, github.event.head_commit.message), '[skip-bc]') }}
run: |
cd ${{ matrix.client.path }}
exit_code=0
Expand Down Expand Up @@ -364,6 +369,7 @@ jobs:
run: yarn cli cts run ${{ matrix.client.language }} ${{ matrix.client.toRun }} --no-client --no-requests

- name: Run benchmarks
if: ${{ matrix.client.isMainVersion }}
run: yarn cli cts run ${{ matrix.client.language }} ${{ matrix.client.toRun }} --benchmark --no-client --no-requests --no-e2e

- name: Generate code snippets for documentation
Expand All @@ -373,9 +379,11 @@ jobs:
run: yarn cli build snippets ${{ matrix.client.language }}

- name: Zip artifact before storing
if: ${{ matrix.client.isMainVersion }}
run: zip -r -y clients-${{ matrix.client.language }}.zip ${{ matrix.client.path }} ${{ matrix.client.testsToStore }} ${{ matrix.client.snippetsToStore }} -x "**/node_modules**" "**/__pycache__/**" "**/.yarn/cache/**" "**/build/**" "**/.build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/vendor/**" "**/target/**" "**/.dart_tool/**"

- name: Store ${{ matrix.client.language }} clients
if: ${{ matrix.client.isMainVersion }}
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
Expand All @@ -396,6 +404,7 @@ jobs:
!contains(needs.*.result, 'failure')
outputs:
success: ${{ steps.setoutput.outputs.success }}
name: client kotlin@${{ fromJSON(needs.setup.outputs.KOTLIN_DATA).version }} macos
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -436,6 +445,7 @@ jobs:
MONITORING_API_KEY: ${{ secrets.MONITORING_API_KEY }}
outputs:
success: ${{ steps.setoutput.outputs.success }}
name: client swift@${{ fromJSON(needs.setup.outputs.SWIFT_DATA).version }} macos
steps:
- uses: actions/checkout@v4

Expand All @@ -451,6 +461,7 @@ jobs:
with:
type: minimal
language: swift
version: ${{ fromJSON(needs.setup.outputs.SWIFT_DATA).version }}

- run: yarn cli cts run swift ${{ fromJSON(needs.setup.outputs.SWIFT_DATA).toRun }} -v ${{ !contains(format('{0} {1}', github.event.pull_request.title, github.event.head_commit.message), '[skip-e2e]') && '--no-e2e' || '' }}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# coding: utf-8

from asyncio import sleep
from typing import Callable, Protocol, TypeVar
from typing import Callable, TypeVar

T = TypeVar("T")


class Timeout(Protocol):
class Timeout:
def __call__(self) -> int:
return 0

Expand All @@ -16,10 +16,7 @@ def __init__(self) -> None:

class RetryTimeout(Timeout):
def __call__(self, retry_count: int) -> int:
return min(retry_count * 0.2, 5)

def __init__(self) -> None:
pass
return int(min(retry_count * 0.2, 5))


async def create_iterable(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from copy import deepcopy
from sys import version_info
from typing import Any, Dict, List, Optional, Tuple, Union
from urllib.parse import quote

from algoliasearch.http.base_config import BaseConfig
from algoliasearch.http.serializer import QueryParametersSerializer

try:
if version_info >= (3, 11):
from typing import Self
except ImportError:
else:
from typing_extensions import Self


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from platform import python_version
from typing import Optional, Self
from sys import version_info
from typing import Optional

if version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

from algoliasearch import __version__

Expand Down
2 changes: 1 addition & 1 deletion clients/algoliasearch-client-python/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ install_requires =
python-dateutil>=2.8.2,<3.0
pydantic>=2,3.0
typing-extensions>=4.7.1,<5.0
python_requires = >= 3.8
python_requires = >=3.8
9 changes: 8 additions & 1 deletion config/clients.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,14 @@
"snippets": {
"extension": ".py",
"outputFolder": ""
}
},
"supportedVersions": [
"3.8",
"3.9",
"3.10",
"3.11",
"3.12"
]
},
"ruby": {
"clients": [
Expand Down
2 changes: 1 addition & 1 deletion playground/python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion playground/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = "https://www.algolia.com"
repository = "https://github.com/algolia/api-clients-automation"

[tool.poetry.dependencies]
python = "3.11.6"
python = "^3.8.1"
algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true }
ruff = "0.4.9"
python-dotenv = "1.0.0"
Expand Down
Loading

0 comments on commit 036f9ac

Please sign in to comment.