From 8d56fd5f8e0662d30aad31113bf54a433320fe96 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Thu, 23 Nov 2023 21:56:20 +0100 Subject: [PATCH] CI: Add job configuration for "python-flask" --- .github/workflows/test-python-flask.yml | 63 +++++++++++++++++++++++++ .gitignore | 1 + python-flask/app.py | 6 +++ python-flask/pyproject.toml | 5 ++ python-flask/requirements-dev.txt | 2 + 5 files changed, 77 insertions(+) create mode 100644 .github/workflows/test-python-flask.yml create mode 100644 python-flask/requirements-dev.txt diff --git a/.github/workflows/test-python-flask.yml b/.github/workflows/test-python-flask.yml new file mode 100644 index 0000000..7ba5938 --- /dev/null +++ b/.github/workflows/test-python-flask.yml @@ -0,0 +1,63 @@ +name: Python / Flask + +on: + pull_request: + branches: ~ + paths: + - '.github/workflows/test-python-flask.yml' + - 'python-flask/**' + - 'requirements.txt' + push: + branches: [ main ] + paths: + - '.github/workflows/test-python-flask.yml' + - 'python-flask/**' + - 'requirements.txt' + + # Allow job to be triggered manually. + workflow_dispatch: + + # Run job each night after CrateDB nightly has been published. + schedule: + - cron: '0 3 * * *' + +# Cancel in-progress jobs when pushing to the same branch. +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + test: + name: " + Python: ${{ matrix.python-version }} + CrateDB: ${{ matrix.cratedb-version }} + on ${{ matrix.os }}" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ 'ubuntu-latest' ] + python-version: [ '3.8', '3.12' ] + cratedb-version: [ 'nightly' ] + + steps: + + - name: Acquire sources + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + architecture: x64 + cache: 'pip' + cache-dependency-path: | + python-flask/pyproject.toml + + - name: Install utilities + run: | + pip install -r requirements.txt + + - name: Validate python-flask + run: | + ngr test --accept-no-venv python-flask diff --git a/.gitignore b/.gitignore index 91387aa..738ff0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea !go-gin/.idea .venv* +*.pyc diff --git a/python-flask/app.py b/python-flask/app.py index c51ef04..6fc591e 100644 --- a/python-flask/app.py +++ b/python-flask/app.py @@ -24,6 +24,7 @@ import base64 import hashlib import typing as t +import sys from datetime import datetime from tempfile import TemporaryFile @@ -400,4 +401,9 @@ def run(): if __name__ == '__main__': + if "--info" in sys.argv[1:]: + from importlib.metadata import version + app_version = version("cratedb-python-flask-guestbook-demo") + print(f"Backend API implementation of the CrateDB guestbook demo application, version {app_version}") + sys.exit(0) run() diff --git a/python-flask/pyproject.toml b/python-flask/pyproject.toml index 50ac661..38560ea 100644 --- a/python-flask/pyproject.toml +++ b/python-flask/pyproject.toml @@ -23,3 +23,8 @@ install = [ run = [ {cmd=".venv/bin/python app.py"}, ] +check = [ + {cmd="python -m py_compile app.py"}, + {cmd="ruff --ignore=E713 app.py"}, + {cmd="python app.py --info"}, +] diff --git a/python-flask/requirements-dev.txt b/python-flask/requirements-dev.txt new file mode 100644 index 0000000..584da56 --- /dev/null +++ b/python-flask/requirements-dev.txt @@ -0,0 +1,2 @@ +poethepoet<0.25 +ruff==0.1.6