add ci and one test case

This commit is contained in:
Benny
2023-02-13 19:41:57 +01:00
parent c7711aea08
commit 4b953b68ec
12 changed files with 1041 additions and 999 deletions

View File

@@ -1,8 +1,12 @@
name: build docker image
name: Build and push docker image
on:
push:
branches:
- 'master'
paths-ignore:
- '**.md'
- '**.yml'
- 'LICENSE'
jobs:
docker:
@@ -64,7 +68,35 @@ jobs:
with:
string: ${{ github.event.repository.full_name }}
- name: Build and push
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.8.0
with:
mongodb-version: "6.0"
- name: Build CI docker images
uses: docker/build-push-action@v2
with:
context: .
# due to the limitation of docker, we can only save one platform at a time.
# for CI purposes, we only need to save amd64 and then build multi-arch later
platforms: linux/amd64
load: true
tags: |
${{ steps.dh_string.outputs.lowercase }}
build-args: |
env=dev
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Restore database and run tests
run: |
sudo apt update && sudo apt install -y wget
wget -q https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.6.1.deb
sudo dpkg -i mongodb-database-tools-ubuntu2204-x86_64-100.6.1.deb
mongorestore --gzip --archive=assets/ci.gz
make ci-test
- name: Build and push docker images
uses: docker/build-push-action@v2
with:
context: .
@@ -86,4 +118,4 @@ jobs:
TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
curl "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=260260121&text=Normal%20Build%20complete!"
echo "Build complete!"
echo "YYeTsBot Build complete!"

View File

@@ -1,4 +1,4 @@
name: publish release
name: Publish golang one key release
on:
push:
tags:

View File

@@ -1,4 +1,4 @@
name: CI Test
name: Pull Request CI test
on:
pull_request:
@@ -6,18 +6,17 @@ on:
- master
paths-ignore:
- '**.md'
- '**.yml'
- 'LICENSE'
jobs:
ci:
name: Build Image Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Lower case for ghcr
id: ghcr_string
uses: ASzc/change-string-case-action@v1
- name: Checkout
uses: actions/checkout@v2
with:
string: ${{ github.event.repository.full_name }}
submodules: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
@@ -37,7 +36,7 @@ jobs:
platforms: linux/amd64
load: true
tags: |
ghcr.io/${{ steps.ghcr_string.outputs.lowercase }}
yyetsbot:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
@@ -46,6 +45,19 @@ jobs:
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.8.0
with:
mongodb-version: "6.0"
- name: Restore database and run tests
run: |
sudo apt update && sudo apt install -y wget
wget -q https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.6.1.deb
sudo dpkg -i mongodb-database-tools-ubuntu2204-x86_64-100.6.1.deb
mongorestore --gzip --archive=assets/ci.gz
make ci-test
- name: Install trivy
run: |
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
@@ -58,9 +70,9 @@ jobs:
id: trivy
with:
run: |
trivy image --no-progress --severity "HIGH,CRITICAL" ghcr.io/${{ steps.ghcr_string.outputs.lowercase }}
trivy image --no-progress --severity "HIGH,CRITICAL" yyetsbot:latest
- name: Comment CVE PR
- name: Comment on CVE PR
uses: thollander/actions-comment-pull-request@v1
with:
message: |

View File

@@ -1,36 +0,0 @@
name: Rapid upgrade
on:
issues:
types:
- opened
- reopened
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: emergency update from ssh
if: github.event.issue.labels[0].name == 'upgrade'
uses: appleboy/ssh-action@master
env:
TOKEN: ${{ secrets.BOT_TOKEN }}
with:
envs: TOKEN
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USERNAME }}
key: ${{ secrets.SSH_KEY }}
command_timeout: 30m
script: |
docker save bennythink/yyetsbot > /root/yyetsbot-old.tar
cd /root/YYeTsBot
make prod
docker-compose -f /home/WebsiteRunner/docker-compose.yml up -d
docker-compose -f /home/BotsRunner/docker-compose.yml up -d
curl "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=260260121&text=Rapid%20upgrade%20complete!"
echo "Rapid upgrade complete!"
- name: Close Issue
if: github.event.issue.labels[0].name == 'upgrade'
uses: peter-evans/close-issue@v1
with:
comment: Upgrade complete. Close this issue.

View File

@@ -83,3 +83,9 @@ universal:
release:
git tag $(shell git rev-parse --short HEAD)
git push --tags
ci-test:
docker run --rm bennythink/yyetsbot /bin/sh -c "cd /YYeTsBot/yyetsweb/tests;python -m unittest discover -p '*_test.py'"
test:
cd $(WEB)/tests;python -m unittest discover -p '*_test.py'

BIN
assets/ci.gz Normal file

Binary file not shown.

View File

@@ -8,7 +8,7 @@ pymongo==4.3.3
tornado==6.2
captcha==0.4
passlib==1.7.4
fakeredis==2.8.0
fakeredis==2.9.0
pytz==2022.7.1
filetype==1.2.0
requests[socks]
@@ -16,6 +16,6 @@ tqdm==4.64.1
retry==0.9.2
pymysql==1.0.2
git+https://github.com/tgbot-collection/python-akismet
openpyxl==3.1.0
openpyxl==3.1.1
zhconv==1.4.3
jinja2==3.1.2

View File

@@ -1,4 +1,4 @@
cat << EOF > /build/build/robots.txt
cat << EOF > /YYeTsBot/YYeTsFE/build/robots.txt
User-agent: *
Disallow: /
EOF

View File

@@ -14,7 +14,6 @@ import os
import random
import re
import string
import sys
import fakeredis
import redis
@@ -26,11 +25,13 @@ predefined_str = re.sub(r"[1l0oOI]", "", string.ascii_letters + string.digits)
class Redis:
def __init__(self):
if getattr(sys, '_MEIPASS', None):
self.r = redis.StrictRedis(host=os.getenv("redis") or "localhost", decode_responses=True)
try:
self.r.ping()
except redis.exceptions.ConnectionError:
# we can't connect to redis, either generated by pyinstaller(_MEIPASS), or forget to run it.
logging.info("%s Disable redis for standalone exe! %s", "#" * 10, "#" * 10)
self.r = fakeredis.FakeStrictRedis()
else:
self.r = redis.StrictRedis(host=os.getenv("redis") or "localhost", decode_responses=True)
def __del__(self):
self.r.close()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env python3
# coding: utf-8
import pathlib
import sys
import unittest
from tornado.testing import AsyncHTTPTestCase
sys.path.append(pathlib.Path(__file__).parent.parent.as_posix())
from server import RunServer
class YYeTsTest(AsyncHTTPTestCase):
def get_app(self):
return RunServer.application
class TestIndex(YYeTsTest):
def test_homepage(self):
response = self.fetch('/')
self.assertEqual(response.code, 200)
self.assertTrue(b'<!doctype html>' in response.body)
if __name__ == '__main__':
unittest.main()