-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci cd , record games and players to db #5
Changes from all commits
4c83723
fd01c43
ba02dbd
259b1d1
6b590f5
1d7dde3
850ab81
76c8c0e
dc4bdf1
bb065f8
190b3ca
c70d3ea
66e7f0a
a849dc7
857ac4c
9db18cb
be82341
5e1233c
163ccae
c18b2ae
097bf11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__pycache__ | ||
.venv | ||
venv |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: CI/CD with Docker Compose | ||
env: | ||
REPO_NAME: ${{ github.event.repository.name }} | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
build: | ||
runs-on: [self-hosted] | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: executing remote ssh commands using password | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
key: ${{ secrets.PRIVATE_KEY }} | ||
script: | | ||
cd ./_work/${{ env.REPO_NAME }}/${{ env.REPO_NAME }} | ||
docker compose build --no-cache | ||
|
||
deploy: | ||
needs: [build] | ||
runs-on: [self-hosted] | ||
steps: | ||
- name: SSH into production server and deploy | ||
uses: appleboy/ssh-action@master | ||
env: | ||
TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_TELEGRAM_BOT_TOKEN }} | ||
DEVELOPER_CHAT_ID: ${{ secrets.DEVELOPER_CHAT_ID }} | ||
SQLITE_DB_FILE_PATH: ${{ vars.SQLITE_DB_FILE_PATH }} | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
key: ${{ secrets.PRIVATE_KEY }} | ||
script: | | ||
cd ./_work/${{ env.REPO_NAME }}/${{ env.REPO_NAME }} | ||
docker compose down | ||
docker compose up -d | ||
docker compose ps | ||
envs: TELEGRAM_BOT_TOKEN,DEVELOPER_CHAT_ID,SQLITE_DB_FILE_PATH |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
import logging | ||
|
||
from telegram import Update | ||
from telegram.ext import ContextTypes | ||
|
||
from src.data_models.Player import Player | ||
from src.services.db_service import save_player | ||
|
||
|
||
async def receive_poll_answer( | ||
update: Update, context: ContextTypes.DEFAULT_TYPE | ||
) -> None: | ||
# TODO save polls to db and query them instead saving them to bot_data | ||
"""Summarize a users poll vote""" | ||
answer = update.poll_answer | ||
if not answer.option_ids: | ||
return # It's retake poll action, ignore it | ||
if not answer.option_ids: # Poll retract, delete previous vote | ||
del context.bot_data[answer.poll_id]["results"][update.effective_user.id] | ||
return | ||
if context.bot_data: | ||
answered_poll = context.bot_data[answer.poll_id] | ||
user_id = update.effective_user.id | ||
result = answered_poll["questions"][answer.option_ids[0]] | ||
context.bot_data[answer.poll_id]["results"][user_id] = result | ||
await save_player( | ||
Player( | ||
telegram_user_id=user_id, | ||
username=update.effective_user.username, | ||
first_name=update.effective_user.first_name, | ||
full_name=update.effective_user.full_name, | ||
last_name=update.effective_user.last_name, | ||
is_bot=update.effective_user.is_bot, | ||
language_code=update.effective_user.language_code, | ||
) | ||
) | ||
else: | ||
# failed to save poll answer. | ||
# Ussually happens for polls that are sent to the bot before it started and not updated | ||
# TODO save polls to db and query them instead saving them to bot_data | ||
return | ||
logging.error( | ||
"Failed to save poll answer. Usually happens for polls that are sent to the bot before it " | ||
"started and not updated", | ||
exc_info=True, | ||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,24 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
from datetime import datetime | ||||||||||||||||||||||||||||||||||||||||||||||||||
from typing import Literal | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
from pydantic import BaseModel | ||||||||||||||||||||||||||||||||||||||||||||||||||
from pydantic import BaseModel, field_validator | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
class Game(BaseModel): | ||||||||||||||||||||||||||||||||||||||||||||||||||
playroom_id: int | ||||||||||||||||||||||||||||||||||||||||||||||||||
end_time: datetime | ||||||||||||||||||||||||||||||||||||||||||||||||||
result: Literal["Hitler Canceler", "Fascist Law", "Hitler Death", "Liberal Law"] | ||||||||||||||||||||||||||||||||||||||||||||||||||
poll_id: int | ||||||||||||||||||||||||||||||||||||||||||||||||||
chat_id: int | ||||||||||||||||||||||||||||||||||||||||||||||||||
results: dict # Literal["Hitler Canceler", "Fascist Law", "Hitler Death", "Liberal Law"] | ||||||||||||||||||||||||||||||||||||||||||||||||||
creator_id: int | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
@field_validator("results", mode="after") | ||||||||||||||||||||||||||||||||||||||||||||||||||
@classmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||
def validate_results(cls, v: dict) -> Literal["CH", "DH", "FW", "LW"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||
outcomes = set(v.values()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
if "I'm Canceler Hitler" in outcomes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
return "CH" | ||||||||||||||||||||||||||||||||||||||||||||||||||
if "I'm Dead Hitler" in outcomes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
return "DH" | ||||||||||||||||||||||||||||||||||||||||||||||||||
if "I'm Liberal Winner" in outcomes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
return "LW" | ||||||||||||||||||||||||||||||||||||||||||||||||||
if "I'm Fascistic Winner" in outcomes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
return "FW" | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+13
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - def validate_results(cls, v: dict) -> Literal["CH", "DH", "FW", "LW"]:
+ # Adjust the method or the attribute type to ensure consistency. Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,18 @@ | ||||||||||||||||||||||
from typing import Optional | ||||||||||||||||||||||
|
||||||||||||||||||||||
from pydantic import BaseModel | ||||||||||||||||||||||
from pydantic import BaseModel, field_validator | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
class Player(BaseModel): | ||||||||||||||||||||||
telegram_user_id: int | ||||||||||||||||||||||
username: str | ||||||||||||||||||||||
first_name: Optional[str] = None | ||||||||||||||||||||||
last_name: Optional[str] = None | ||||||||||||||||||||||
is_bot: bool = False | ||||||||||||||||||||||
first_name: Optional[str | None] | ||||||||||||||||||||||
full_name: Optional[str | None] | ||||||||||||||||||||||
last_name: Optional[str | None] | ||||||||||||||||||||||
is_bot: Optional[bool] = False | ||||||||||||||||||||||
language_code: Optional[str | None] | ||||||||||||||||||||||
Comment on lines
+9
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the use of - first_name: Optional[str | None]
+ first_name: Optional[str] Apply this change to Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
@field_validator("is_bot", mode="after") | ||||||||||||||||||||||
@classmethod | ||||||||||||||||||||||
def validate_bot(cls, v: bool) -> str: | ||||||||||||||||||||||
return "TRUE" if v else "FALSE" # sqlite3 does not support boolean type | ||||||||||||||||||||||
Comment on lines
+15
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - def validate_bot(cls, v: bool) -> str:
+ def validate_bot(cls, v: bool) -> bool:
- return "TRUE" if v else "FALSE"
+ return v Committable suggestion
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure the error message concatenation is intentional. It appears there might be a missing space between
"TELEGRAM_BOT_TOKEN env variable"
and"wasn't purposed."
Committable suggestion