From c5e00f3de0db32179277bbbf6d517e4a269e1e1c Mon Sep 17 00:00:00 2001 From: Nikita Grishko Date: Tue, 23 Jul 2019 22:14:21 +0300 Subject: [PATCH] [chore] switch to Drone CI --- .drone.jsonnet | 118 +++++++++++++++++++++++++++ .drone.yml | 137 ++++++++++++++++++++++++++++++++ .editorconfig | 2 +- .github/main.workflow | 79 ------------------ Makefile | 14 +--- README.md | 2 +- aiodogstatsd/contrib/aiohttp.py | 4 +- 7 files changed, 263 insertions(+), 93 deletions(-) create mode 100644 .drone.jsonnet create mode 100644 .drone.yml delete mode 100644 .github/main.workflow diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 0000000..12af1f0 --- /dev/null +++ b/.drone.jsonnet @@ -0,0 +1,118 @@ +local + volume_cached_poetry = 'cached-poetry', + volume_cached_deps = 'cached-deps', + + git_step = { + name: 'fetch', + image: 'docker:git', + commands: ['git fetch --tags'], + }, + py_step(name, commands, version='3.7') = { + name: name, + pull: 'always', + image: 'python:%s' % version, + commands: commands, + volumes: [ + { + name: volume_cached_poetry, + path: '/root/.poetry', + }, + { + name: volume_cached_deps, + path: '/root/.cache/pypoetry/virtualenvs', + }, + ], + }, + notify_step(name, message) = { + name: name, + pull: 'always', + image: 'appleboy/drone-telegram', + environment: { + PLUGIN_TOKEN: { + from_secret: 'TELEGRAM_BOT_TOKEN', + }, + PLUGIN_TO: { + from_secret: 'TELEGRAM_CHAT_ID', + }, + PLUGIN_MESSAGE: message, + }, + }; + +{ + kind: 'pipeline', + name: 'default', + clone: { + depth: 50, + }, + steps: [ + git_step, + py_step('deps-3.6', ['make install'], version='3.6'), + py_step('deps-3.7', ['make install']), + py_step('lint-3.7', ['make lint']), + py_step('test-3.6', ['make test'], version='3.6'), + py_step('test-3.7', ['make test', 'make codecov']) { + environment: { + CODECOV_TOKEN: { + from_secret: 'CODECOV_TOKEN', + }, + }, + }, + notify_step('lint/test completed', ||| + {{#success build.status}} + `{{repo.name}}` build {{build.number}} succeeded. Good job. + {{else}} + `{{repo.name}}` build {{build.number}} failed. Fix me please. + {{/success}} + |||) { + when: { + branch: ['master'], + event: { + exclude: + ['pull_request'], + }, + status: [ + 'success', + 'failure', + ], + }, + }, + py_step('publish', ['make publish']) { + environment: { + PYPI_USERNAME: { + from_secret: 'PYPI_USERNAME', + }, + PYPI_PASSWORD: { + from_secret: 'PYPI_PASSWORD', + }, + }, + when: { + event: ['tag'], + }, + }, + notify_step('publish completed', ||| + {{#success build.status}} + `{{repo.name}}` publish {{build.tag}} succeeded. Good job. + {{else}} + `{{repo.name}}` publish {{build.tag}} failed. Fix me please. + {{/success}} + |||) { + when: { + event: ['tag'], + status: [ + 'success', + 'failure', + ], + }, + }, + ], + volumes: [ + { + name: volume_cached_poetry, + temp: {}, + }, + { + name: volume_cached_deps, + temp: {}, + }, + ], +} diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..37017b1 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,137 @@ +--- +kind: pipeline +name: default + +platform: + os: linux + arch: amd64 + +clone: + depth: 50 + +steps: +- name: fetch + image: docker:git + commands: + - git fetch --tags + +- name: deps-3.6 + pull: always + image: python:3.6 + commands: + - make install + volumes: + - name: cached-poetry + path: /root/.poetry + - name: cached-deps + path: /root/.cache/pypoetry/virtualenvs + +- name: deps-3.7 + pull: always + image: python:3.7 + commands: + - make install + volumes: + - name: cached-poetry + path: /root/.poetry + - name: cached-deps + path: /root/.cache/pypoetry/virtualenvs + +- name: lint-3.7 + pull: always + image: python:3.7 + commands: + - make lint + volumes: + - name: cached-poetry + path: /root/.poetry + - name: cached-deps + path: /root/.cache/pypoetry/virtualenvs + +- name: test-3.6 + pull: always + image: python:3.6 + commands: + - make test + volumes: + - name: cached-poetry + path: /root/.poetry + - name: cached-deps + path: /root/.cache/pypoetry/virtualenvs + +- name: test-3.7 + pull: always + image: python:3.7 + commands: + - make test + - make codecov + environment: + CODECOV_TOKEN: + from_secret: CODECOV_TOKEN + volumes: + - name: cached-poetry + path: /root/.poetry + - name: cached-deps + path: /root/.cache/pypoetry/virtualenvs + +- name: lint/test completed + pull: always + image: appleboy/drone-telegram + environment: + PLUGIN_MESSAGE: "{{#success build.status}}\n `{{repo.name}}` build {{build.number}} succeeded. Good job.\n{{else}}\n `{{repo.name}}` build {{build.number}} failed. Fix me please.\n{{/success}}\n" + PLUGIN_TO: + from_secret: TELEGRAM_CHAT_ID + PLUGIN_TOKEN: + from_secret: TELEGRAM_BOT_TOKEN + when: + branch: + - master + event: + exclude: + - pull_request + status: + - success + - failure + +- name: publish + pull: always + image: python:3.7 + commands: + - make publish + environment: + PYPI_PASSWORD: + from_secret: PYPI_PASSWORD + PYPI_USERNAME: + from_secret: PYPI_USERNAME + volumes: + - name: cached-poetry + path: /root/.poetry + - name: cached-deps + path: /root/.cache/pypoetry/virtualenvs + when: + event: + - tag + +- name: publish completed + pull: always + image: appleboy/drone-telegram + environment: + PLUGIN_MESSAGE: "{{#success build.status}}\n `{{repo.name}}` publish {{build.tag}} succeeded. Good job.\n{{else}}\n `{{repo.name}}` publish {{build.tag}} failed. Fix me please.\n{{/success}}\n" + PLUGIN_TO: + from_secret: TELEGRAM_CHAT_ID + PLUGIN_TOKEN: + from_secret: TELEGRAM_BOT_TOKEN + when: + event: + - tag + status: + - success + - failure + +volumes: +- name: cached-poetry + temp: {} +- name: cached-deps + temp: {} + +... diff --git a/.editorconfig b/.editorconfig index 27656a9..b42b4d2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ trim_trailing_whitespace = true indent_style = space indent_size = 4 -[*.{hcl,md,toml,yml}] +[*.{jsonnet,md,toml,yml}] indent_style = space indent_size = 2 diff --git a/.github/main.workflow b/.github/main.workflow deleted file mode 100644 index 30d820b..0000000 --- a/.github/main.workflow +++ /dev/null @@ -1,79 +0,0 @@ -workflow "run linters and tests" { - on = "push" - resolves = ["notify build succeeded"] -} - -action "py3.6 linting and testing" { - uses = "docker://python:3.6" - runs = ["sh", "-c", "make ci-quality-basic"] - secrets = [ - "CODECOV_TOKEN", - ] -} - -action "py3.7 linting and testing" { - needs = [ - "py3.6 linting and testing", - ] - uses = "docker://python:3.7" - runs = ["sh", "-c", "make ci-quality"] - secrets = [ - "CODECOV_TOKEN", - ] -} - -action "notify build succeeded" { - needs = [ - "py3.7 linting and testing", - ] - uses = "docker://gr1n/the-telegram-action:master" - env = { - TELEGRAM_MESSAGE = "`aiodogstatsd` build succeeded" - } - secrets = [ - "TELEGRAM_BOT_TOKEN", - "TELEGRAM_CHAT_ID", - ] -} - -workflow "notify about new star" { - on = "watch" - resolves = ["notify project starred"] -} - -action "notify project starred" { - uses = "docker://gr1n/the-telegram-action:master" - secrets = [ - "TELEGRAM_BOT_TOKEN", - "TELEGRAM_CHAT_ID", - ] - env = { - TELEGRAM_MESSAGE = "`aiodogstatsd` starred!" - } -} - -workflow "publish" { - on = "release" - resolves = ["notify project published"] -} - -action "py37 publish" { - uses = "docker://python:3.7.2" - runs = ["sh", "-c", "make ci-publish"] - secrets = [ - "PYPI_USERNAME", - "PYPI_PASSWORD", - ] -} - -action "notify project published" { - uses = "docker://gr1n/the-telegram-action:master" - needs = ["py37 publish"] - secrets = [ - "TELEGRAM_BOT_TOKEN", - "TELEGRAM_CHAT_ID", - ] - env = { - TELEGRAM_MESSAGE = "`aiodogstatsd` published to PyPI" - } -} diff --git a/Makefile b/Makefile index 2f185b5..00337b2 100644 --- a/Makefile +++ b/Makefile @@ -46,16 +46,10 @@ lint: lint-black lint-flake8 lint-isort lint-mypy test: @$(POETRY) run pytest --cov-report term --cov-report html --cov=aiodogstatsd -vv +.PHONY: codecov +codecov: + @$(POETRY) run codecov --token=$(CODECOV_TOKEN) + .PHONY: publish publish: @$(POETRY) publish --username=$(PYPI_USERNAME) --password=$(PYPI_PASSWORD) --build - -.PHONY: ci-quality-basic -ci-quality-basic: install lint test - -.PHONY: ci-quality -ci-quality: ci-quality-basic - @$(POETRY) run codecov --token=$(CODECOV_TOKEN) - -.PHONY: ci-publish -ci-publish: install-poetry publish diff --git a/README.md b/README.md index aaae2bf..88a9cb5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # aiodogstatsd -![GitHub commit merge status](https://img.shields.io/github/commit-status/Gr1N/aiodogstatsd/master/HEAD.svg?label=build%20status) [![codecov](https://codecov.io/gh/Gr1N/aiodogstatsd/branch/master/graph/badge.svg)](https://codecov.io/gh/Gr1N/aiodogstatsd) ![PyPI](https://img.shields.io/pypi/v/aiodogstatsd.svg?label=pypi%20version) ![PyPI - Downloads](https://img.shields.io/pypi/dm/aiodogstatsd.svg?label=pypi%20downloads) ![GitHub](https://img.shields.io/github/license/Gr1N/aiodogstatsd.svg) +[![Build Status](https://cloud.drone.io/api/badges/Gr1N/aiodogstatsd/status.svg)](https://cloud.drone.io/Gr1N/aiodogstatsd) [![codecov](https://codecov.io/gh/Gr1N/aiodogstatsd/branch/master/graph/badge.svg)](https://codecov.io/gh/Gr1N/aiodogstatsd) ![PyPI](https://img.shields.io/pypi/v/aiodogstatsd.svg?label=pypi%20version) ![PyPI - Downloads](https://img.shields.io/pypi/dm/aiodogstatsd.svg?label=pypi%20downloads) ![GitHub](https://img.shields.io/github/license/Gr1N/aiodogstatsd.svg) An asyncio-based client for sending metrics to StatsD with support of [DogStatsD](https://docs.datadoghq.com/developers/dogstatsd/) extension. diff --git a/aiodogstatsd/contrib/aiohttp.py b/aiodogstatsd/contrib/aiohttp.py index 56922d2..beb72bb 100644 --- a/aiodogstatsd/contrib/aiohttp.py +++ b/aiodogstatsd/contrib/aiohttp.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import AsyncIterator, Callable, Optional +from typing import AsyncIterator, Callable, Optional, cast from aiohttp import web from aiohttp.web_app import _Middleware @@ -68,7 +68,7 @@ async def middleware( response_status = e.status raise e except Exception as e: - response_status = HTTPStatus.INTERNAL_SERVER_ERROR.value + response_status = cast(int, HTTPStatus.INTERNAL_SERVER_ERROR.value) raise e finally: if _proceed_collecting( # pragma: no branch