Skip to content

Commit

Permalink
Setup GitHub Actions for BogaBot (#40)
Browse files Browse the repository at this point in the history
Setup Github Actions with basic tests
  • Loading branch information
alexkumar520 authored Jan 18, 2025
1 parent fbb9cb8 commit c5718b2
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 4 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest
environment: boga_bot

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f ${{ github.workspace }}/.github/workflows/requirements.txt ]; then pip install -r ${{ github.workspace }}/.github/workflows/requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest

env:
DISCORD_BOT_API_KEY: ${{ secrets.DISCORD_BOT_API_KEY }}
URBAN_DICT_API_KEY: ${{ secrets.URBAN_DICT_API_KEY }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
GIF_API_KEY: ${{ secrets.GIF_API_KEY }}
TWITCH_API_KEY: ${{ secrets.TWITCH_API_KEY }}
TWITCH_SECRET: ${{ secrets.TWITCH_SECRET }}
WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
MC_SERVER_ADDR: ${{ secrets.MC_SERVER_ADDR }}
WACK_WRAPPERS_CHANNEL_ID: ${{ secrets.WACK_WRAPPERS_CHANNEL_ID }}
DEBUG_CHANNEL_ID: ${{ secrets.DEBUG_CHANNEL_ID }}
ALEX_USER_ID: ${{ secrets.ALEX_USER_ID }}
JAMES_USER_ID: ${{ secrets.JAMES_USER_ID }}
run: |
pytest ${{ github.workspace }}/.github/workflows/tests.py --doctest-modules
46 changes: 46 additions & 0 deletions .github/workflows/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
aiohappyeyeballs==2.4.4
aiohttp==3.11.11
aiosignal==1.3.2
annotated-types==0.7.0
anyio==4.7.0
asyncio-dgram==2.2.0
attrs==24.3.0
cachetools==5.5.0
certifi==2024.12.14
charset-normalizer==3.4.1
discord==2.3.2
discord.py==2.4.0
distro==1.9.0
dnspython==2.7.0
frozenlist==1.5.0
google-api-core==2.24.0
google-api-python-client==2.156.0
google-auth==2.37.0
google-auth-httplib2==0.2.0
googleapis-common-protos==1.66.0
h11==0.14.0
httpcore==1.0.7
httplib2==0.22.0
httpx==0.28.1
idna==3.10
jiter==0.8.2
mcstatus==11.1.1
multidict==6.1.0
openai==1.58.1
propcache==0.2.1
proto-plus==1.25.0
protobuf==5.29.2
pyasn1==0.6.1
pyasn1_modules==0.4.1
pydantic==2.10.4
pydantic_core==2.27.2
pyparsing==3.2.0
requests==2.32.3
rsa==4.9
setuptools==75.6.0
sniffio==1.3.1
tqdm==4.67.1
typing_extensions==4.12.2
uritemplate==4.1.1
urllib3==2.3.0
yarl==1.18.3
34 changes: 34 additions & 0 deletions .github/workflows/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
import os

main_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))

# Add the main directory to the system path
sys.path.append(main_dir)
import boba_math
import gifgenerate
import chatgpt_api
import youtube
import pytest
import weather
import urban_dict
import twitch_random


def test_gif_generate():
assert gifgenerate.generate_gif() != None

def test_youtube():
youtube.get_trending()

def test_weather():
assert weather.get_weather("LA")[0] not in ["Error. Try a different location.", "Request failed. Please try fixing the location or a new one."]

def test_define():
urban_dict.define("test")

def test_random():
urban_dict.random()

def test_twitch():
twitch_random.generate_channel()
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ __pycache__
main.sh
start.sh
boga.db
.venv
.venv
.pytest_cache
.env
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# BogaBot

`python main.py`
`python main.py`

When adding tests, you need to load .env file to the consts file.

Then run from root

`py -m pytest .github/workflows/tests.py`

or just

`pytest .github/workflows/tests.py`
3 changes: 1 addition & 2 deletions twitch_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def generate_channel():
global expiry_time
global access_token
if not expiry_time or expiry_time < datetime.now():
refresh_token()
print("Refreshed token!")
refresh_token()

header = {
'Client-ID' : TWITCH_API_KEY,
Expand Down

0 comments on commit c5718b2

Please sign in to comment.