From fb66f55668ffc591e140b46bbd73a0c94ceb186e Mon Sep 17 00:00:00 2001 From: Mifarse Date: Sun, 31 Oct 2021 17:12:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=83=20abo?= =?UTF-8?q?ut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 11 ++++------- TelegramBot/bot.py | 11 ++++++++++- TelegramBot/messages/messages.py | 10 ++++++++-- docker-compose.yml | 4 ++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6e3d347..bab4d9e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,17 +1,13 @@ name: deploy-to-Yandex-Cloud -# Controls when the workflow will run on: workflow_dispatch: + release: + types: [published] -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" deploy: - # The type of runner that the job will run on runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job steps: - name: webfactory/ssh-agent uses: webfactory/ssh-agent@v0.5.3 @@ -23,12 +19,13 @@ jobs: echo "${{ secrets.key }}" > "$HOME/key" chmod 600 "$HOME/key" - - name: Pull repo and restart Docker containers + - name: Restart Bot at Yandex Cloud run: ssh -i $HOME/key carolyn@${{ secrets.HOST }} -o StrictHostKeyChecking=no ' cd Carolyn && git pull && + export CAROLYN_DEPLOY_INFO=$(git describe --always) docker-compose down && docker-compose up -d ' diff --git a/TelegramBot/bot.py b/TelegramBot/bot.py index fa03b97..2762ea9 100644 --- a/TelegramBot/bot.py +++ b/TelegramBot/bot.py @@ -4,6 +4,7 @@ import logging import requests import time import datetime +import os import telegram from telegram import ( @@ -394,9 +395,15 @@ def variant(update: Update, context: CallbackContext): msg.edit_text(text=MESSAGES.Variant.get(data["student"]["number"])) +def about(update: Update, context: CallbackContext): + """Получить инфу о развертывании бота.""" + deploy_info = os.environ.get("CAROLYN_DEPLOY_INFO") + update.message.reply_html(MESSAGES.Deploy.about(deploy_info)) + + def error(update: Update, context: CallbackContext): LOG.error(msg="Exception while handling an update:", exc_info=context.error) - if context.error is not None: + if context.error is not None and update is not None: update.message.reply_text("Ой, кажется у меня %s" % repr(context.error)) update.message.reply_sticker(MESSAGES.Stickers.DEAD) return ConversationHandler.END @@ -485,6 +492,7 @@ def main() -> None: sub_handler = CommandHandler("sub", sub) unsub_handler = CommandHandler("unsub", unsub) variant_handler = CommandHandler("variant", variant) + about_handler = CommandHandler("about", about) dispatcher.add_handler(start_handler) dispatcher.add_handler(grades_handler) @@ -492,6 +500,7 @@ def main() -> None: dispatcher.add_handler(sub_handler) dispatcher.add_handler(unsub_handler) dispatcher.add_handler(variant_handler) + dispatcher.add_handler(about_handler) dispatcher.add_error_handler(error) # Начало работы бота diff --git a/TelegramBot/messages/messages.py b/TelegramBot/messages/messages.py index 4e8bd9f..a048a43 100644 --- a/TelegramBot/messages/messages.py +++ b/TelegramBot/messages/messages.py @@ -29,8 +29,9 @@ class Messages: TIMEOUT = "🕛 Время запроса вышло" @staticmethod - def get(name: str, assignment: list, how_to_display: str, - notes: str, deadline: str): + def get( + name: str, assignment: list, how_to_display: str, notes: str, deadline: str + ): is_float, n_cols, n_rows = how_to_display.split(",") n_cols, n_rows = int(n_cols), int(n_rows) summary = f"{name}:\n" @@ -110,6 +111,11 @@ class Messages: } return cases.get(err, "😟 Возникли неполадки") + class Deploy: + @staticmethod + def about(git_info): + return f"ℹ️ Информация о сборке:\n{git_info}" + class Spreadsheets: pass diff --git a/docker-compose.yml b/docker-compose.yml index 78e283c..1e1e0ae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,12 +7,12 @@ services: build: ./SpreadsheetsService ports: - "5000:5000" - environment: - SECRETKEY: "HELLO-WORLD-@21XX 15AF" volumes: - ./SpreadsheetsService:/app telegrambot: container_name: "carolyn-telegrambot" + environment: + - CAROLYN_DEPLOY_INFO restart: always build: ./TelegramBot volumes: