mirror of
https://github.com/Faridik/Carolyn.git
synced 2026-07-08 05:11:52 +00:00
Merge pull request #15 from Faridik/add-deploy-action
В боте добавилось отображание версии, в GitHub можно развернуть бота по кнопке
This commit is contained in:
commit
82ea404e30
33
.github/workflows/deploy.yml
vendored
33
.github/workflows/deploy.yml
vendored
@ -1,22 +1,33 @@
|
||||
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:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v2
|
||||
- name: webfactory/ssh-agent
|
||||
uses: webfactory/ssh-agent@v0.5.3
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.KEY }}
|
||||
|
||||
# Runs a set of commands using the runners shell
|
||||
- name: Connect to Yandex Cloud SSH
|
||||
- name: Set up keys for Yandex Cloud
|
||||
run: |
|
||||
echo Hello world.
|
||||
echo "${{ secrets.key }}" > "$HOME/key"
|
||||
chmod 600 "$HOME/key"
|
||||
|
||||
- name: Deploy bot at Yandex Cloud
|
||||
run:
|
||||
ssh -i $HOME/key carolyn@${{ secrets.HOST }} -o StrictHostKeyChecking=no
|
||||
'
|
||||
cd Carolyn &&
|
||||
git pull &&
|
||||
export CAROLYN_DEPLOY_ID="$(git rev-parse HEAD)" &&
|
||||
export CAROLYN_DEPLOY_VERSION="$(git describe --tags)" &&
|
||||
echo "$CAROLYN_DEPLOY_VERSION, $CAROLYN_DEPLOY_ID" &&
|
||||
docker-compose down &&
|
||||
docker-compose up -d
|
||||
'
|
||||
|
||||
@ -4,6 +4,7 @@ import logging
|
||||
import requests
|
||||
import time
|
||||
import datetime
|
||||
import os
|
||||
|
||||
import telegram
|
||||
from telegram import (
|
||||
@ -394,9 +395,16 @@ def variant(update: Update, context: CallbackContext):
|
||||
msg.edit_text(text=MESSAGES.Variant.get(data["student"]["number"]))
|
||||
|
||||
|
||||
def about(update: Update, context: CallbackContext):
|
||||
"""Получить инфу о развертывании бота."""
|
||||
commit_id = os.environ.get("CAROLYN_DEPLOY_ID", "")
|
||||
verison = os.environ.get("CAROLYN_DEPLOY_VERSION", "")
|
||||
update.message.reply_html(MESSAGES.Deploy.about(commit_id, verison))
|
||||
|
||||
|
||||
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 +493,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 +501,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)
|
||||
|
||||
# Начало работы бота
|
||||
|
||||
@ -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"<b>{name}</b>:\n"
|
||||
@ -110,6 +111,11 @@ class Messages:
|
||||
}
|
||||
return cases.get(err, "😟 Возникли неполадки")
|
||||
|
||||
class Deploy:
|
||||
@staticmethod
|
||||
def about(commit_id: str, git_describe):
|
||||
return f"ℹ️ Версия сборки:\n<a href='https://github.com/Faridik/Carolyn/commit/{commit_id}'>{git_describe}</a>"
|
||||
|
||||
class Spreadsheets:
|
||||
pass
|
||||
|
||||
|
||||
@ -7,12 +7,13 @@ services:
|
||||
build: ./SpreadsheetsService
|
||||
ports:
|
||||
- "5000:5000"
|
||||
environment:
|
||||
SECRETKEY: "HELLO-WORLD-@21XX 15AF"
|
||||
volumes:
|
||||
- ./SpreadsheetsService:/app
|
||||
telegrambot:
|
||||
container_name: "carolyn-telegrambot"
|
||||
environment:
|
||||
CAROLYN_DEPLOY_ID: ${CAROLYN_DEPLOY_ID}
|
||||
CAROLYN_DEPLOY_VERSION: ${CAROLYN_DEPLOY_VERSION}
|
||||
restart: always
|
||||
build: ./TelegramBot
|
||||
volumes:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user