From 09981f9109a501ff8493abdeed229ff02189a65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sat, 20 Jan 2024 11:02:44 +0300 Subject: [PATCH 01/10] chore: add `ms-python.isort` to recommendations vscode ext --- .vscode/extensions.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index f50b38f..8763a3a 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,6 +3,7 @@ "ms-python.python", "ms-python.vscode-pylance", "ms-python.black-formatter", + "ms-python.isort", "ms-azuretools.vscode-docker", "hangxingliu.vscode-systemd-support", "benspaulding.procfile" From a0c4bd0923f35ab17febdb04f9193d13dd23aa2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sat, 20 Jan 2024 18:07:27 +0300 Subject: [PATCH 02/10] refactor: change policykit identity to unix group --- koyunotlatan.pkla | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koyunotlatan.pkla b/koyunotlatan.pkla index 0d6ed18..1873347 100644 --- a/koyunotlatan.pkla +++ b/koyunotlatan.pkla @@ -1,5 +1,5 @@ [Allow koyunotlatan user to manage start/stop/restart/reload/enable/disable systemd services] -Identity=unix-user:koyunotlatan +Identity=unix-group:koyunotlatan Action=org.freedesktop.systemd1.manage-units;org.freedesktop.systemd1.manage-unit-files;org.freedesktop.systemd1.manage-unit-files;org.freedesktop.systemd1.set-environment;org.freedesktop.systemd1.reload-daemon ResultAny=yes ResultInactive=yes From 669b43a7d02f53aa95d9e07734ab6b63b3e40489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sun, 21 Jan 2024 21:38:37 +0300 Subject: [PATCH 03/10] ci: add `release` workflow --- .github/workflows/release.yml | 37 +++++++++++++++++++++++++++++++++++ scripts/release.sh | 22 +++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/release.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fef81c1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release new version + +on: + push: + tags: + - v*.*.* + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Copy service files via SSH password + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + source: "koyunotlatan/*,koyunotlatan/data/*,scripts/*,koyunotlatan.service,koyunotlatan.timer,koyunotlatan.pkla,praw.example.ini,requirements.txt,LICENSE,pyproject.toml" + target: /home/koyunotlatan/service + + - name: Setup service via SSH + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + script: | + /home/koyunotlatan/service/scripts/release.sh + + # Fulfill credentials for praw.ini + perl -pe 's//${{ secrets.PRAW_USERNAME }}/g; s//${{ secrets.PRAW_PASSWORD }}/g; s//${{ secrets.PRAW_CLIENT_ID }}/g; s//${{ secrets.PRAW_CLIENT_SECRET }}/g' /home/koyunotlatan/service/praw.example.ini > /home/koyunotlatan/service/praw.ini diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100644 index 0000000..61c7795 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +export WORKDIR=/home/koyunotlatan/service + +# Set virtual enviroment directory as enviroment variable +export VIRTUAL_ENV=$WORKDIR/.venv + +# Check $VIRTUAL_ENV enviroment variable exist +if [[ -n "$VIRTUAL_ENV" ]]; then + # Create virtual enviroment if not exist + if [[ ! -d "$VIRTUAL_ENV" ]]; then + python3 -m venv $VIRTUAL_ENV + chown -R koyunotlatan_ci:koyunotlatan $VIRTUAL_ENV + fi + + # Install dependencies with virtual enviroment + $VIRTUAL_ENV/bin/pip install -r $WORKDIR/requirements.txt +fi + +systemctl daemon-reload +systemctl enable koyunotlatan.timer +systemctl start koyunotlatan.service From 6aa807f0fceba2474f973d49810c3b98288e624f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sun, 21 Jan 2024 21:41:59 +0300 Subject: [PATCH 04/10] refactor: change `NO_REPLY` var to be driven by the `PYTHONENV` var --- koyunotlatan/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koyunotlatan/constants.py b/koyunotlatan/constants.py index 21421c4..1e38a9f 100644 --- a/koyunotlatan/constants.py +++ b/koyunotlatan/constants.py @@ -20,8 +20,8 @@ BOT_ACTIVE_SUBREDDITS: str try: - NO_REPLY = bool(strtobool(os.environ.get('NO_REPLY', default='True'))) PYTHONENV = os.environ.get('PYTHONENV', default='development') + NO_REPLY = bool(strtobool(os.environ.get('NO_REPLY', default='true' if PYTHONENV == 'production' else 'false'))) BASE_LOG_DIR = '/var/log/koyunotlatan' BOT_CLIENT_ID = os.environ.get('BOT_CLIENT_ID', default='') From 0709cea4e1010f4946079ddc5243e17f01225848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sun, 21 Jan 2024 21:48:04 +0300 Subject: [PATCH 05/10] refactor: remove notice that the comment is from a bot --- koyunotlatan/runner.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/koyunotlatan/runner.py b/koyunotlatan/runner.py index 7782076..050a58d 100644 --- a/koyunotlatan/runner.py +++ b/koyunotlatan/runner.py @@ -49,12 +49,13 @@ def __init__(self, reddit: Reddit): self.search_limit = 20 self.post_limit = 50 self.alike_value = 1.35 - self.reply_comment = """ -{comment} + self.reply_comment = "{comment}" +# self.reply_comment = """ +# {comment} -^(If you have **any comments or suggestions** about the bot, please mention **Asim-Abi** by replying to **the bot comment**) +# ^(If you have **any comments or suggestions** about the bot, please mention **Asim-Abi** by replying to **the bot comment**) -^(This comment was automatically picked by **the koyunkırpan algorithm**)""" +# ^(This comment was automatically picked by **the koyunkırpan algorithm**)""" self.load_replies() self.load_commented_on() From 6156173f12b9f9fe0cbe9427102abba93205ab6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sun, 21 Jan 2024 21:48:58 +0300 Subject: [PATCH 06/10] chore: add `act` secrets to gitignore --- .gitignore | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 0d912c9..0e27e51 100644 --- a/.gitignore +++ b/.gitignore @@ -121,6 +121,9 @@ venv.bak/ .env* !.env*.example +# Github Act Secrets +*.secrets + # Spyder project settings .spyderproject .spyproject @@ -145,18 +148,6 @@ dmypy.json # Cython debug symbols cython_debug/ -### venv ### -# Virtualenv -# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ -[Bb]in -[Ii]nclude -[Ll]ib -[Ll]ib64 -[Ll]ocal -[Ss]cripts -pyvenv.cfg -pip-selfcheck.json - ### VisualStudioCode ### .vscode/* !.vscode/settings.json From 2b30355acc0020703b8f83ce8ccf46ff4692828b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sun, 21 Jan 2024 21:52:33 +0300 Subject: [PATCH 07/10] refactor: remove `PYTHONENV` from service env Use enviroment variable or fallback value --- koyunotlatan.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koyunotlatan.service b/koyunotlatan.service index e1a4fb9..fec8b72 100644 --- a/koyunotlatan.service +++ b/koyunotlatan.service @@ -6,7 +6,7 @@ After=network-online.target local-fs.target [Service] Type=exec ExecStart=/home/koyunotlatan/service/.venv/bin/python /home/koyunotlatan/service/koyunotlatan/main.py $OPTIONS -Environment=PYTHONUNBUFFERED=true PYTHONPATH=/home/koyunotlatan/service PYTHONENV=production +Environment=PYTHONUNBUFFERED=true PYTHONPATH=/home/koyunotlatan/service SyslogIdentifier=koyunotlatan NotifyAccess=all User=koyunotlatan From 4da8a40ed92b1ed072feaa7003c71dadccb0cfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sun, 21 Jan 2024 21:54:27 +0300 Subject: [PATCH 08/10] refactor: reword timer description --- koyunotlatan.timer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koyunotlatan.timer b/koyunotlatan.timer index 53fcebc..602b82d 100644 --- a/koyunotlatan.timer +++ b/koyunotlatan.timer @@ -1,5 +1,5 @@ [Unit] -Description="Koyun Otlatan timer that runs on every hour" +Description="Koyun Otlatan timer" Wants=koyunotlatan.service [Timer] From 7e6b0967083af30621478631c8333f2398ba1a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sun, 21 Jan 2024 21:55:09 +0300 Subject: [PATCH 09/10] ci: start timer on release workflow --- scripts/release.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/release.sh b/scripts/release.sh index 61c7795..19edb08 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -19,4 +19,5 @@ fi systemctl daemon-reload systemctl enable koyunotlatan.timer +systemctl start koyunotlatan.timer systemctl start koyunotlatan.service From 4c9a279b01635794a902c6b711dca2d2c459a0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?As=C4=B1m=20Tahir?= Date: Sun, 21 Jan 2024 21:56:14 +0300 Subject: [PATCH 10/10] refactor: remove `BASE_LOG_DIR` from `.env` file --- .env.example | 1 - 1 file changed, 1 deletion(-) diff --git a/.env.example b/.env.example index 4f79fdf..4134824 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,5 @@ NO_REPLY=True PYTHONUNBUFFERED=true -BASE_LOG_DIR=logs PYTHONENV=development BOT_CLIENT_ID=''