From 6c4739a6826f8ba0b0995024d7a3713e2d4ea348 Mon Sep 17 00:00:00 2001 From: "d.zakharchuk" Date: Tue, 23 Jan 2024 11:16:45 +0200 Subject: [PATCH] add release workflow, fix tests --- .dockerignore | 1 - .github/workflows/release.yaml | 28 ++++++++++++++++++++++++++++ .github/workflows/test.yaml | 18 ++++++++++++++++-- Dockerfile | 7 ++++--- README.md | 28 +++++++++++++--------------- docker-compose.yaml | 1 + featureflags/__init__.py | 1 + featureflags/web/app.py | 9 +++++---- lets.yaml | 21 ++++++++++++++++----- pdm.lock | 6 +++--- pyproject.toml | 12 +++++++++--- scripts/pre-install.sh | 3 --- scripts/release.sh | 23 +++++++++++++++++++++++ 13 files changed, 119 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/release.yaml delete mode 100755 scripts/pre-install.sh create mode 100755 scripts/release.sh diff --git a/.dockerignore b/.dockerignore index 7cfd59d..4bd9b7b 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 new file mode 100644 index 0000000..16097fa --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,28 @@ +name: Build & publish + +on: + push: + tags: + - "v*" + +jobs: + deploy: + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + strategy: + matrix: + python-version: [3.7] + steps: + - 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: Build and copy UI bundle + run: ./scripts/build-copy-ui-dist.sh + + - name: Upload package to pypi.org + run: pdm publish -u "__token__" -P ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f004707..03a85c3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,7 +12,7 @@ on: - reopened jobs: - test-web: + test: runs-on: ubuntu-latest steps: @@ -22,5 +22,19 @@ jobs: - name: Install lets uses: lets-cli/lets-action@v1.1 - - name: Run test + - name: Set up Node + uses: actions/setup-node@v4.0.1 + with: + node-version: 20 + cache-dependency-path: ./ui/package-lock.json + cache: 'npm' + + - name: Install dependencies + working-directory: ./ui + run: npm install + + - name: Build UI + run: lets build-copy-ui-bundle + + - name: Run server tests run: lets test diff --git a/Dockerfile b/Dockerfile index 6962c8c..36f7e3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,10 @@ WORKDIR /app COPY ./pyproject.toml . COPY ./pdm.lock . -COPY ./scripts/pre-install.sh . +# for pyproject.toml to extract version +COPY ./featureflags/__init__.py ./featureflags/__init__.py +# for pyproject.toml to read readme +COPY ./README.md . RUN apt-get update && \ apt-get install -y --no-install-recommends \ @@ -25,8 +28,6 @@ RUN apt-get update && \ # configure pdm config cache_dir /pdm_cache && \ pdm config check_update false && \ - # custom pre-install script - /app/pre-install.sh && \ # install base deps \ pdm install --no-lock --prod --no-editable && \ # cleanup base layer to keep image size small diff --git a/README.md b/README.md index b9c9ff8..e6c7407 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,11 @@ Check important architecture decisions in ``adr/`` directory. Installation ------------ -TODO: update after deploy configuration -On PyPi: https://pypi.org/project/evo-featureflags-client +On PyPi: https://pypi.org/project/evo-featureflags-server -To install client library for synchronous app: - -.. code-block:: shell - - $ pip install evo-featureflags grpcio - -To install client library for asynchronous app: - -.. code-block:: shell - - $ pip install evo-featureflags grpclib +To install client library follow instructions +here: [evo-featureflags-client](https://github.com/evo-company/featureflags-py) Development ----------- @@ -54,11 +44,19 @@ Run all this commands: - ``lets web`` # in separate terminal - ``lets ui`` # in separate terminal -to start API handlers (not required for web application): +To start API handlers (not required for web application): - ``lets http`` # in separate terminal - ``lets rpc`` # in separate terminal +To build UI and copy it to ``web/static`` directory: + +- ``lets build-copy-ui-bundle`` + +To release package: + +- ``lets release 1.0.0 --message="Added feature"`` + Pre-commit ``./scripts/enable-hooks.sh`` @@ -68,7 +66,7 @@ Pre-commit TODO: - add docs, automate docs build -- add tests +- add more tests .. _fastapi: https://github.com/tiangolo/fastapi .. _hiku: https://github.com/vmagamedov/hiku diff --git a/docker-compose.yaml b/docker-compose.yaml index 03af601..bc13aca 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -54,6 +54,7 @@ services: - ./scripts:/app/scripts - ./configs:/app/configs - ./.ipython:/app/.ipython + - ./README.md:/app/README.md # Uncomment to mount local build of `featureflags_protobuf` #- ./featureflags_protobuf:/app/featureflags_protobuf diff --git a/featureflags/__init__.py b/featureflags/__init__.py index e69de29..5becc17 100644 --- a/featureflags/__init__.py +++ b/featureflags/__init__.py @@ -0,0 +1 @@ +__version__ = "1.0.0" diff --git a/featureflags/web/app.py b/featureflags/web/app.py index c02a87a..6801e13 100644 --- a/featureflags/web/app.py +++ b/featureflags/web/app.py @@ -26,11 +26,12 @@ def create_app() -> FastAPI: app.include_router(index_router) app.include_router(graphql_router) - app.mount( - "/static", - app=StaticFiles(directory=STATIC_DIR, html=True), - name="static", + static_files = StaticFiles( + directory=STATIC_DIR, + check_dir=not config.debug, + html=True, ) + app.mount("/static", static_files, name="static") configure_metrics(port=config.instrumentation.prometheus_port) configure_middlewares(app, container) diff --git a/lets.yaml b/lets.yaml index 1ee2c28..57c5b6c 100644 --- a/lets.yaml +++ b/lets.yaml @@ -82,11 +82,7 @@ commands: - build-test - postgres-test cmd: | - export ARGS="$@" docker-compose run --rm test - TESTS_EXIT_CODE=$? - docker-compose down postgres-test - exit $TESTS_EXIT_CODE postgres: description: Run postgres @@ -140,7 +136,7 @@ commands: docker-compose run --rm docs \ sphinx-build -a -b html docs public - copy-ui-bundle: + build-copy-ui-bundle: description: Build and copy UI bundle to server cmd: ./scripts/build-copy-ui-dist.sh @@ -183,3 +179,18 @@ commands: cmd: | docker-compose run -T --rm backend \ pdm run fmt + + release: + description: | + Update version in featureflags/__init__.py + Create new annotated tag + Push changes to remote + options: | + Usage: lets release --message= + Options: + Set version + --message=, -m Release message + Example: + lets release 1.0.0 --message="Added feature" + cmd: | + VERSION=${LETSOPT_VERSION} MESSAGE=${LETSOPT_MESSAGE} pdm run release diff --git a/pdm.lock b/pdm.lock index 7d22118..d39177b 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev", "docs", "lint", "test"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:5f67547e53728d0973ce9e9ab10a615555c2f18545d2f634985b2deb973e885a" +content_hash = "sha256:9a1107332d22df98c9218951c14639bd8bb105feb9f863b950dffa542b7bdd82" [[package]] name = "aiopg" @@ -470,7 +470,7 @@ files = [ [[package]] name = "grpclib" -version = "0.4.5" +version = "0.4.6" requires_python = ">=3.7" summary = "Pure-Python gRPC implementation for asyncio" groups = ["default"] @@ -479,7 +479,7 @@ dependencies = [ "multidict", ] files = [ - {file = "grpclib-0.4.5.tar.gz", hash = "sha256:bf83ed55aca59497e168761d9555056efc54a8f865316c3b39becd007e9f9a73"}, + {file = "grpclib-0.4.6.tar.gz", hash = "sha256:595d05236ca8b8f8e433f5bf6095e6354c1d8777d003ddaf5288efa9611e3fd6"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index 2ba4f26..d7cd57d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,8 @@ [project] -name = "evo-featureflags" -version = "1.0.0" +name = "evo-featureflags-server" +dynamic = ["version"] description = "Feature flags server" +readme = "README.md" authors = [ {name = "d.zakharchuk", email = "d.zakharchuk@smartweb.com.ua"}, {name = "m.kindritskiy", email = "m.kindritskiy@smartweb.com.ua"}, @@ -9,7 +10,7 @@ authors = [ ] dependencies = [ "evo-featureflags-protobuf==0.3.0", - "grpclib==0.4.5", + "grpclib==0.4.6", "hiku==0.7.1", "protobuf<4.0.0", "sqlalchemy[mypy]==1.4.42", @@ -44,7 +45,12 @@ build-backend = "pdm.backend" [tool] +[tool.pdm.version] +source = "file" +path = "featureflags/__init__.py" + [tool.pdm.scripts] +release = "./scripts/release.sh" test = "python -m pytest {args}" docs = "sphinx-build -a -b html docs public" ruff = "ruff check featureflags {args} --fix" diff --git a/scripts/pre-install.sh b/scripts/pre-install.sh deleted file mode 100755 index 370ec97..0000000 --- a/scripts/pre-install.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# This script is run before the installation of the packages - pdm install --prod -# You can use it to run any commands that you need to run before the installation diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..14957e6 --- /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/__init__.py +git add featureflags/__init__.py +git commit -m "Release ${VERSION}" + +git tag -a v${VERSION} -m "${MESSAGE}" +git push origin main --tags