From 4f5da0460bf2ff3709f8e185982b5fffbb1e0ac8 Mon Sep 17 00:00:00 2001 From: Rui Hu Date: Thu, 27 Mar 2025 21:05:41 +0800 Subject: [PATCH] fix(General): fix ci pipeline with forgejo runner --- .forgejo/workflows/coverage-check.yaml | 47 ++++++++++++++++++ .forgejo/workflows/publish-python.yaml | 49 +++++++++++++++++++ .gitignore | 4 ++ .gitlab-ci.yml | 5 +- pyproject.toml | 25 +++++++++- requirements.txt | 8 --- setup.py | 30 ------------ .../adapter/test_amq_message_factory.py | 0 .../adapter/test_amq_response_factory.py | 0 .../adapter/test_amq_route_factory.py | 0 .../adapter/test_service_message_factory.py | 0 {amqp => tests}/model/test_snowflake_id.py | 0 {amqp => tests}/router/test_route_database.py | 0 {amqp => tests}/router/test_router_base.py | 0 {amqp => tests}/router/test_utils.py | 0 {amqp => tests}/service/test_stream_parser.py | 0 16 files changed, 125 insertions(+), 43 deletions(-) create mode 100644 .forgejo/workflows/coverage-check.yaml create mode 100644 .forgejo/workflows/publish-python.yaml delete mode 100644 requirements.txt delete mode 100644 setup.py rename {amqp => tests}/adapter/test_amq_message_factory.py (100%) rename {amqp => tests}/adapter/test_amq_response_factory.py (100%) rename {amqp => tests}/adapter/test_amq_route_factory.py (100%) rename {amqp => tests}/adapter/test_service_message_factory.py (100%) rename {amqp => tests}/model/test_snowflake_id.py (100%) rename {amqp => tests}/router/test_route_database.py (100%) rename {amqp => tests}/router/test_router_base.py (100%) rename {amqp => tests}/router/test_utils.py (100%) rename {amqp => tests}/service/test_stream_parser.py (100%) diff --git a/.forgejo/workflows/coverage-check.yaml b/.forgejo/workflows/coverage-check.yaml new file mode 100644 index 0000000..2f6c979 --- /dev/null +++ b/.forgejo/workflows/coverage-check.yaml @@ -0,0 +1,47 @@ +name: "Unit test coverage" +on: + push: + pull_request: +env: + MIN_COVERAGE_PERCENTAGE: 85 + DEBIAN_FRONTEND: noninteractive + TZ: UTC +jobs: + # gradle test for modules + pytest: + runs-on: default + container: + image: ubuntu:24.04 + steps: + # need to setup node and git + - run: | + apt-get update + apt-get install -y nodejs git curl + # check out code and set up python + - uses: actions/checkout@v4 + - uses: https://github.com/actions/setup-python@v5 + with: + python-version: '3.11' + # install dependencies + - run: pip install -e .[dev] + # run pytest with coverage + - run: pytest --cov=amqp --cov-report=xml + # process coverage report + - name: Collect coverage report + id: coverage + run: | + COVERAGE_PERCENTAGE=$(coverage report --format=total) + echo "Code coverage: ${COVERAGE_PERCENTAGE}%" + echo "Minimal coverage: ${MIN_COVERAGE_PERCENTAGE}%" + echo "percentage=${COVERAGE_PERCENTAGE}" >> $GITHUB_OUTPUT + - name: Post coverage to RP + if: github.event_name == 'pull_request' + run: | + curl --fail \ + -X POST '${{github.api_url}}/repos/${{github.repository}}/issues/${{github.event.number}}/comments' \ + -H "Content-Type: application/json" \ + -H "Authorization: token ${{github.token}}" \ + -d '{"body":"Coverage for module ${{ matrix.submodule }} is ${{steps.coverage.outputs.percentage}}%"}' + - name: Check coverage rate + run: | + coverage report --fail-under=${MIN_COVERAGE_PERCENTAGE} \ No newline at end of file diff --git a/.forgejo/workflows/publish-python.yaml b/.forgejo/workflows/publish-python.yaml new file mode 100644 index 0000000..97aaa29 --- /dev/null +++ b/.forgejo/workflows/publish-python.yaml @@ -0,0 +1,49 @@ +name: "CI for pypl publish" +on: + push: + branches: + - master # publish release on master + - develop # publish snapshot on develop + - "feat/*" # test + workflow_dispatch: + # allow manual trigger +env: + DEBIAN_FRONTEND: noninteractive + TZ: UTC +jobs: + publish-lib: + runs-on: default + container: + image: ubuntu:24.04 + steps: + # need to setup node and git + - run: | + apt-get update + apt-get install -y nodejs git + # check out code + - uses: actions/checkout@v4 + - uses: https://github.com/actions/setup-python@v5 + with: + python-version: '3.11' + # install dependencies + - run: pip install -e .[dev] + # run pytest + - run: pytest + # replace timestamp building dev version + - name: Add timestamp to version + if: github.head_ref != '' && github.head_ref != 'master' + run: | + sed -i -E "s/(version = \"[^\"]+)(-dev)DT\"/\1\2$(date -u +'%Y%m%d%H%M%S')\"/" pyproject.toml + cat pyproject.toml + - name: Build wheel + run: | + python -m build + # publish + - run: | + twine upload --repository-url https://git.cleverthis.com/api/packages/clevermicro/pypi \ + --username $CI_REGISTRY_USER \ + --password $CI_REGISTRY_PASSWORD \ + dist/* + env: + CI_REGISTRY_USER: ${{ secrets.REGISTRY_USER }} + CI_REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6d50dcd..2d91fca 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,7 @@ hs_err_pid* .venv .coverage + +amq_adapter.egg-info/ +build/ +coverage.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8868e30..617e89c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,7 +59,4 @@ publish: script: # - twine upload --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD dist/* - twine upload --repository-url https://git.cleverthis.com/api/v4/projects/$PROJECT_ID/packages/pypi --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD dist/* - #only: - # - main # Only publish from the main branch - #rules: - # - if: $CI_COMMIT_BRANCH == "main" + diff --git a/pyproject.toml b/pyproject.toml index 750bec3..bf2e092 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,9 +5,19 @@ build-backend = "setuptools.build_meta" [project] name = "amq_adapter" version = "0.2.2" -description = "The Python implementation of the AMQ Adaptor for CleverMicro" +description = "Adapter for RabbitMQ to integrate a CleverThis python-code Service with CleverMicro platform" readme = "README.md" +authors = [ + { name = "Stanislav Hejny", email = "stanislav.hejny@cleverthis.com" } +] license = { text = "Apache License 2.0" } +urls = { Homepage = "https://git.cleverthis.com/clevermicro/amq-adapter-python" } +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] +requires-python = ">=3.11" dependencies = [ "aiohttp~=3.11.11", "pika~=1.3.2", @@ -18,3 +28,16 @@ dependencies = [ "opentelemetry-exporter-prometheus", "opentelemetry-instrumentation-pika" ] + +[tool.setuptools.packages.find] +where = ["."] +exclude = ["tests*", "docs*"] + +[project.optional-dependencies] +dev = [ + "pytest>=7.0", + "pytest-cov>=4.0", + "build", + "twine" +] + diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 3341347..0000000 --- a/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -aiohttp~=3.11.11 -fastapi==0.115.6 -pika~=1.3.2 -opentelemetry-api -opentelemetry-sdk -opentelemetry-exporter-otlp -opentelemetry-exporter-prometheus -opentelemetry-instrumentation-pika diff --git a/setup.py b/setup.py deleted file mode 100644 index db0d66d..0000000 --- a/setup.py +++ /dev/null @@ -1,30 +0,0 @@ -from setuptools import setup, find_packages - -setup( - name="amqp", - version="0.2.0", - author="Stanislav Hejny", - author_email="stanislav.hejny@cleverthis.com", - description="Adapter for RabbitMQ to integrate a CleverThis python-code Service with CleverMicro platform", - long_description=open("README.md").read(), - long_description_content_type="text/markdown", - url="https://git.cleverthis.com/cleverthis/clevermicro/amq-adapter-python", - packages=find_packages(), - install_requires=[ - # dependencies here - "aiohttp~=3.11.11", - "fastapi==0.115.6", - "pika~=1.3.2", - "opentelemetry-api", - "opentelemetry-sdk", - "opentelemetry-exporter-otlp", - "opentelemetry-exporter-prometheus", - "opentelemetry-instrumentation-pika" - ], - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], - python_requires=">=3.11", -) diff --git a/amqp/adapter/test_amq_message_factory.py b/tests/adapter/test_amq_message_factory.py similarity index 100% rename from amqp/adapter/test_amq_message_factory.py rename to tests/adapter/test_amq_message_factory.py diff --git a/amqp/adapter/test_amq_response_factory.py b/tests/adapter/test_amq_response_factory.py similarity index 100% rename from amqp/adapter/test_amq_response_factory.py rename to tests/adapter/test_amq_response_factory.py diff --git a/amqp/adapter/test_amq_route_factory.py b/tests/adapter/test_amq_route_factory.py similarity index 100% rename from amqp/adapter/test_amq_route_factory.py rename to tests/adapter/test_amq_route_factory.py diff --git a/amqp/adapter/test_service_message_factory.py b/tests/adapter/test_service_message_factory.py similarity index 100% rename from amqp/adapter/test_service_message_factory.py rename to tests/adapter/test_service_message_factory.py diff --git a/amqp/model/test_snowflake_id.py b/tests/model/test_snowflake_id.py similarity index 100% rename from amqp/model/test_snowflake_id.py rename to tests/model/test_snowflake_id.py diff --git a/amqp/router/test_route_database.py b/tests/router/test_route_database.py similarity index 100% rename from amqp/router/test_route_database.py rename to tests/router/test_route_database.py diff --git a/amqp/router/test_router_base.py b/tests/router/test_router_base.py similarity index 100% rename from amqp/router/test_router_base.py rename to tests/router/test_router_base.py diff --git a/amqp/router/test_utils.py b/tests/router/test_utils.py similarity index 100% rename from amqp/router/test_utils.py rename to tests/router/test_utils.py diff --git a/amqp/service/test_stream_parser.py b/tests/service/test_stream_parser.py similarity index 100% rename from amqp/service/test_stream_parser.py rename to tests/service/test_stream_parser.py