diff --git a/.dockerignore b/.dockerignore index 158d498..c09541b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -25,7 +25,6 @@ mypy.ini .gitignore .gitlab-ci.yml .python-version -README.md .hooks .lets helm diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d8b3859..9106422 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,26 +1,25 @@ name: Build & publish -# TODO: Setup release workflow on: push: - branches: [ "**" ] tags: - "v*" -# pull_request: -# branches: [main] jobs: - deploy-client: + deploy: runs-on: ubuntu-latest - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/client-') + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') strategy: matrix: python-version: [3.7] steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python with PDM ${{ matrix.python-version }} uses: pdm-project/setup-pdm@v3 with: python-version: ${{ matrix.python-version }} + - name: Upload package to pypi.org - run: pdm publish --username ${{ secrets.PYPI_USERNAME }} --password ${{ secrets.PYPI_PASSWORD }} + run: pdm publish -u "__token__" -P ${{ secrets.PYPI_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 9c3f3c6..68c7ea9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,11 @@ WORKDIR /app COPY ./pyproject.toml . COPY ./pdm.lock . +# for pyproject.toml to extract version +COPY ./featureflags_client/__init__.py ./featureflags_client/__init__.py +# for pyproject.toml to read readme +COPY ./README.md . + RUN apt-get update && \ apt-get install -y --no-install-recommends \ libpq-dev \ diff --git a/README.md b/README.md index 38baa42..f7bd1dc 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,19 @@ Client supports Python >=3.9. Installation ------------ -TODO: +To install package: + +- ``pdm add evo-featureflags-protobuf`` + +To release package: +- ``VERSION= MESSAGE= pdm run release"`` Development ----------- Install dependencies: + - ``pdm install -d`` Pre-commit @@ -26,8 +32,8 @@ Pre-commit ``./scripts/disable-hooks.sh`` - TODO: + - add docs, automate docs build - add tests - add `tracer` / `stats_collector` for http manager diff --git a/docker-compose.yaml b/docker-compose.yaml index 05e2f02..7b69780 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,8 +15,9 @@ services: - ./featureflags_client:/app/featureflags_client - ./examples:/app/examples - ./.ptpython:/app/.ptpython + - ./README.md:/app/README.md # Uncomment to mount local build of `featureflags_protobuf` - - ./featureflags_protobuf:/app/featureflags_protobuf + #- ./featureflags_protobuf:/app/featureflags_protobuf ishell: <<: *base diff --git a/featureflags_client/__init__.py b/featureflags_client/__init__.py index e69de29..6a9beea 100644 --- a/featureflags_client/__init__.py +++ b/featureflags_client/__init__.py @@ -0,0 +1 @@ +__version__ = "0.4.0" diff --git a/featureflags_client/grpc/managers/asyncio.py b/featureflags_client/grpc/managers/asyncio.py index 98ef02f..97f9c0f 100644 --- a/featureflags_client/grpc/managers/asyncio.py +++ b/featureflags_client/grpc/managers/asyncio.py @@ -4,14 +4,15 @@ from asyncio import AbstractEventLoop from typing import Callable, Dict, List, Optional +from featureflags_protobuf.service_grpc import FeatureFlagsStub +from featureflags_protobuf.service_pb2 import FlagUsage as FlagUsageProto + from featureflags_client.grpc.managers.base import AbstractManager from featureflags_client.grpc.state import GrpcState from featureflags_client.grpc.stats_collector import StatsCollector from featureflags_client.grpc.tracer import Tracer from featureflags_client.grpc.types import Variable from featureflags_client.grpc.utils import intervals_gen -from featureflags_protobuf.service_grpc import FeatureFlagsStub -from featureflags_protobuf.service_pb2 import FlagUsage as FlagUsageProto try: import grpclib.client diff --git a/featureflags_client/grpc/managers/sync.py b/featureflags_client/grpc/managers/sync.py index 2c67d0b..6d84e10 100644 --- a/featureflags_client/grpc/managers/sync.py +++ b/featureflags_client/grpc/managers/sync.py @@ -2,14 +2,15 @@ from datetime import datetime, timedelta from typing import Callable, Dict, List, Optional +from featureflags_protobuf.service_pb2 import FlagUsage as FlagUsageProto +from featureflags_protobuf.service_pb2_grpc import FeatureFlagsStub + from featureflags_client.grpc.managers.base import AbstractManager from featureflags_client.grpc.state import GrpcState from featureflags_client.grpc.stats_collector import StatsCollector from featureflags_client.grpc.tracer import Tracer from featureflags_client.grpc.types import Variable from featureflags_client.grpc.utils import intervals_gen -from featureflags_protobuf.service_pb2 import FlagUsage as FlagUsageProto -from featureflags_protobuf.service_pb2_grpc import FeatureFlagsStub try: import grpc diff --git a/featureflags_client/grpc/state.py b/featureflags_client/grpc/state.py index 198a29d..6c1fe0b 100644 --- a/featureflags_client/grpc/state.py +++ b/featureflags_client/grpc/state.py @@ -1,14 +1,14 @@ from abc import ABC, abstractmethod from typing import Any, Callable, Dict, List, Optional +from featureflags_protobuf import service_pb2 +from featureflags_protobuf.service_pb2 import FlagUsage as FlagUsageProto from hiku.builder import Q, build from hiku.export.protobuf import export from hiku.query import Node as QueryNode from featureflags_client.grpc.conditions import load_flags from featureflags_client.grpc.types import Variable -from featureflags_protobuf import service_pb2 -from featureflags_protobuf.service_pb2 import FlagUsage as FlagUsageProto def get_grpc_graph_query(project_name: str) -> QueryNode: diff --git a/featureflags_client/grpc/stats_collector.py b/featureflags_client/grpc/stats_collector.py index c2a111c..1b1e260 100644 --- a/featureflags_client/grpc/stats_collector.py +++ b/featureflags_client/grpc/stats_collector.py @@ -2,9 +2,8 @@ from datetime import datetime, timedelta from typing import DefaultDict, Dict, List -from google.protobuf.timestamp_pb2 import Timestamp as TimestampProto - from featureflags_protobuf.service_pb2 import FlagUsage as FlagUsageProto +from google.protobuf.timestamp_pb2 import Timestamp as TimestampProto class StatsCollector: diff --git a/featureflags_client/tests/grpc/test_conditions.py b/featureflags_client/tests/grpc/test_conditions.py index bb3918f..a0c7f52 100644 --- a/featureflags_client/tests/grpc/test_conditions.py +++ b/featureflags_client/tests/grpc/test_conditions.py @@ -1,5 +1,13 @@ import faker import pytest +from featureflags_protobuf.graph_pb2 import ( + Check, + Condition, + Flag, + Ref, + Result, + Variable, +) from google.protobuf.wrappers_pb2 import BoolValue from featureflags_client.grpc.conditions import ( @@ -19,14 +27,6 @@ superset, wildcard, ) -from featureflags_protobuf.graph_pb2 import ( - Check, - Condition, - Flag, - Ref, - Result, - Variable, -) f = faker.Faker() undefined = object() diff --git a/featureflags_client/tests/grpc/test_flags.py b/featureflags_client/tests/grpc/test_flags.py index 7afcdec..5fe73bc 100644 --- a/featureflags_client/tests/grpc/test_flags.py +++ b/featureflags_client/tests/grpc/test_flags.py @@ -3,14 +3,14 @@ import faker import pytest +from featureflags_protobuf.graph_pb2 import Check, Result, Variable +from featureflags_protobuf.service_pb2 import FlagUsage from google.protobuf.timestamp_pb2 import Timestamp from featureflags_client.grpc.client import FeatureFlagsClient from featureflags_client.grpc.flags import Flags from featureflags_client.grpc.managers.dummy import DummyManager from featureflags_client.grpc.stats_collector import StatsCollector -from featureflags_protobuf.graph_pb2 import Check, Result, Variable -from featureflags_protobuf.service_pb2 import FlagUsage f = faker.Faker() diff --git a/featureflags_client/tests/grpc/test_managers_asyncio.py b/featureflags_client/tests/grpc/test_managers_asyncio.py index 36895bc..962f94c 100644 --- a/featureflags_client/tests/grpc/test_managers_asyncio.py +++ b/featureflags_client/tests/grpc/test_managers_asyncio.py @@ -2,6 +2,7 @@ import faker import pytest +from featureflags_protobuf import graph_pb2, service_pb2 from google.protobuf import wrappers_pb2 from grpclib.client import Channel @@ -9,7 +10,6 @@ from featureflags_client.grpc.managers.asyncio import AsyncIOManager from featureflags_client.grpc.state import get_grpc_graph_query from featureflags_client.grpc.types import Types, Variable -from featureflags_protobuf import graph_pb2, service_pb2 f = faker.Faker() diff --git a/pyproject.toml b/pyproject.toml index b54e111..4872a0e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,8 @@ [project] name = "evo-featureflags-client" -version = "0.4.0" +dynamic = ["version"] description = "Feature flags client" +readme = "README.md" authors = [ { name = "d.zakharchuk", email = "d.zakharchuk@smartweb.com.ua" }, { name = "m.kindritskiy", email = "m.kindritskiy@smartweb.com.ua" }, @@ -27,7 +28,12 @@ build-backend = "pdm.backend" [tool.pdm] +[tool.pdm.version] +source = "file" +path = "featureflags_client/__init__.py" + [tool.pdm.scripts] +release = "./scripts/release.sh" ishell = "ptpython --asyncio --dark-bg --history-file=.ptpython {args}" test = "python -m pytest {args}" docs = "sphinx-build -a -b html docs public" diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..40e5ba8 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e +USAGE="Usage: VERSION=<> MESSAGE=<> pdm run release" + +if [ -z "${VERSION}" ]; then + echo "$USAGE" + echo "VERSION is not set" + exit 1 +fi +if [ -z "${MESSAGE}" ]; then + echo "$USAGE" + echo "MESSAGE is not set" + exit 1 +fi + +echo "Releasing ${VERSION} with message: ${MESSAGE}" + +echo "__version__ = \"${VERSION}\"" > featureflags_client/__init__.py +git add featureflags_client/__init__.py +git commit -m "Release ${VERSION}" + +git tag -a v${VERSION} -m "${MESSAGE}" +git push origin main --tags