Skip to content

Commit

Permalink
Merge pull request #50 from 9dogs/minor-refactoring-release
Browse files Browse the repository at this point in the history
Minor refactoring release
  • Loading branch information
9dogs authored Jan 15, 2024
2 parents 60dce36 + efb90f6 commit cb6d87e
Show file tree
Hide file tree
Showing 18 changed files with 1,064 additions and 1,215 deletions.
19 changes: 0 additions & 19 deletions .azure-pipelines/azure-pipelines.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .azure-pipelines/stage-lint.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .azure-pipelines/stage-publish.yml

This file was deleted.

59 changes: 0 additions & 59 deletions .azure-pipelines/stage-test.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
**

# Allowed
!.azure-pipelines
!tests
!tg_odesli_bot
!.deepsource.toml
!.dockerignore
!.editorconfig
!.gitignore
Expand All @@ -15,4 +13,3 @@
!poetry.lock
!pyproject.toml
!README.md
!setup.cfg
86 changes: 86 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Lint and test

on:
pull_request:
branches: ['master']
push:
branches: ['master']
tags: [ '*' ]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install poetry
run: pip install poetry

- name: Install dependencies
run: poetry install --with main,dev

- name: Run linters
run: make lint

test:
name: Test
strategy:
matrix:
python-version: ['3.10', '3.11']
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: pip install poetry

- name: Install dependencies
run: poetry install --with main,dev

- name: Run tests
run: make test

publish:
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install poetry
run: pip install poetry

- name: Publish to PyPI
run: poetry publish --build
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}

- name: Login to DockerHub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Build and push Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/tg-odesli-bot:${{ github.ref }} .
docker push ${{ secrets.DOCKER_USERNAME }}/tg-odesli-bot:${{ github.ref }}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python:3.10.5-bullseye AS builder
FROM python:3.11.7-bookworm AS builder

LABEL maintainer="[email protected]"
LABEL description="Telegram Bot to share music with Odesli (former Songlink) service."

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

ARG poetry_args='--no-dev'
ARG poetry_args='--without dev'

# Install & config poetry
RUN pip install poetry \
Expand All @@ -22,7 +22,7 @@ COPY . /opt/tg-odesli-bot
ENV PYTHONPATH "${PYTHONPATH}:/opt/tg-odesli-bot"


FROM python:3.10.5-slim-bullseye
FROM python:3.11.7-slim-bookworm

ARG UID=997
ARG GID=997
Expand Down
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@
fmt \
lint \
test \
build-dev \
build

all:
@echo "fmt Format code."
@echo "lint Lint code."
@echo "test Test code."
@echo "build-dev Build Docker dev image."
@echo "build Build Docker image."

FILES = tg_odesli_bot tests
IMAGE_NAME = 9dogs/tg-odesli-bot:latest

fmt:
poetry run black $(FILES)
poetry run isort $(FILES)
poetry run ruff format $(FILES)
poetry run ruff check --fix-only -e $(FILES)

lint:
poetry run black --check $(FILES)
poetry run isort --check-only $(FILES)
poetry run flake8 $(FILES)
poetry run pydocstyle $(FILES)
@if ! poetry run ruff format --check $(FILES); then \
echo "Run 'make fmt' to fix"; \
false; \
fi
poetry run ruff check $(FILES)
poetry run mypy $(FILES)

build-dev:
docker build -t $(IMAGE_NAME) --target=builder --build-arg poetry_args="--with main,dev" .
build:
docker build -t $(IMAGE_NAME) .

Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
bot:
build:
context: .
target: builder
args:
poetry_args: "--with main,dev"
command: ["/opt/tg-odesli-bot/.venv/bin/python", "-m", "tg_odesli_bot.bot"]
volumes:
- /opt/tg-odesli-bot/.venv
- .:/opt/tg-odesli-bot
Loading

0 comments on commit cb6d87e

Please sign in to comment.