Skip to content

Commit

Permalink
add release workflow, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dzakharchuk committed Jan 23, 2024
1 parent ede3907 commit 6c4739a
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 39 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ mypy.ini
.gitignore
.gitlab-ci.yml
.python-version
README.md
.hooks
.lets
helm
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
18 changes: 16 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- reopened

jobs:
test-web:
test:
runs-on: ubuntu-latest

steps:
Expand All @@ -22,5 +22,19 @@ jobs:
- name: Install lets
uses: lets-cli/[email protected]

- name: Run test
- name: Set up Node
uses: actions/[email protected]
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
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand All @@ -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``
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions featureflags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.0"
9 changes: 5 additions & 4 deletions featureflags/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 16 additions & 5 deletions lets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 <version> --message=<message>
Options:
<version> Set version
--message=<message>, -m Release message
Example:
lets release 1.0.0 --message="Added feature"
cmd: |
VERSION=${LETSOPT_VERSION} MESSAGE=${LETSOPT_MESSAGE} pdm run release
6 changes: 3 additions & 3 deletions pdm.lock

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

12 changes: 9 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[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 = "[email protected]"},
{name = "m.kindritskiy", email = "[email protected]"},
{name = "Vladimir Magamedov", email = "[email protected]"},
]
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",
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions scripts/pre-install.sh

This file was deleted.

23 changes: 23 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6c4739a

Please sign in to comment.