mirror of
https://github.com/tgbot-collection/YYeTsBot.git
synced 2025-11-25 19:37:34 +08:00
add ci and one test case
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
name: build docker image
|
name: Build and push docker image
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
- '**.yml'
|
||||||
|
- 'LICENSE'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
docker:
|
||||||
@@ -64,7 +68,35 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
string: ${{ github.event.repository.full_name }}
|
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
|
uses: docker/build-push-action@v2
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
@@ -86,4 +118,4 @@ jobs:
|
|||||||
TOKEN: ${{ secrets.BOT_TOKEN }}
|
TOKEN: ${{ secrets.BOT_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
curl "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=260260121&text=Normal%20Build%20complete!"
|
curl "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=260260121&text=Normal%20Build%20complete!"
|
||||||
echo "Build complete!"
|
echo "YYeTsBot Build complete!"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: publish release
|
name: Publish golang one key release
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: CI Test
|
name: Pull Request CI test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -6,18 +6,17 @@ on:
|
|||||||
- master
|
- master
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
|
- '**.yml'
|
||||||
|
- 'LICENSE'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
ci:
|
||||||
name: Build Image Test
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
- name: Lower case for ghcr
|
|
||||||
id: ghcr_string
|
|
||||||
uses: ASzc/change-string-case-action@v1
|
|
||||||
with:
|
with:
|
||||||
string: ${{ github.event.repository.full_name }}
|
submodules: true
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
@@ -37,7 +36,7 @@ jobs:
|
|||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
load: true
|
load: true
|
||||||
tags: |
|
tags: |
|
||||||
ghcr.io/${{ steps.ghcr_string.outputs.lowercase }}
|
yyetsbot:latest
|
||||||
cache-from: type=local,src=/tmp/.buildx-cache
|
cache-from: type=local,src=/tmp/.buildx-cache
|
||||||
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
||||||
|
|
||||||
@@ -46,6 +45,19 @@ jobs:
|
|||||||
rm -rf /tmp/.buildx-cache
|
rm -rf /tmp/.buildx-cache
|
||||||
mv /tmp/.buildx-cache-new /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
|
- name: Install trivy
|
||||||
run: |
|
run: |
|
||||||
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
|
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
|
||||||
@@ -58,9 +70,9 @@ jobs:
|
|||||||
id: trivy
|
id: trivy
|
||||||
with:
|
with:
|
||||||
run: |
|
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
|
uses: thollander/actions-comment-pull-request@v1
|
||||||
with:
|
with:
|
||||||
message: |
|
message: |
|
||||||
36
.github/workflows/rapid_upgrade.yaml
vendored
36
.github/workflows/rapid_upgrade.yaml
vendored
@@ -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.
|
|
||||||
6
Makefile
6
Makefile
@@ -83,3 +83,9 @@ universal:
|
|||||||
release:
|
release:
|
||||||
git tag $(shell git rev-parse --short HEAD)
|
git tag $(shell git rev-parse --short HEAD)
|
||||||
git push --tags
|
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
BIN
assets/ci.gz
Normal file
Binary file not shown.
@@ -8,7 +8,7 @@ pymongo==4.3.3
|
|||||||
tornado==6.2
|
tornado==6.2
|
||||||
captcha==0.4
|
captcha==0.4
|
||||||
passlib==1.7.4
|
passlib==1.7.4
|
||||||
fakeredis==2.8.0
|
fakeredis==2.9.0
|
||||||
pytz==2022.7.1
|
pytz==2022.7.1
|
||||||
filetype==1.2.0
|
filetype==1.2.0
|
||||||
requests[socks]
|
requests[socks]
|
||||||
@@ -16,6 +16,6 @@ tqdm==4.64.1
|
|||||||
retry==0.9.2
|
retry==0.9.2
|
||||||
pymysql==1.0.2
|
pymysql==1.0.2
|
||||||
git+https://github.com/tgbot-collection/python-akismet
|
git+https://github.com/tgbot-collection/python-akismet
|
||||||
openpyxl==3.1.0
|
openpyxl==3.1.1
|
||||||
zhconv==1.4.3
|
zhconv==1.4.3
|
||||||
jinja2==3.1.2
|
jinja2==3.1.2
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cat << EOF > /build/build/robots.txt
|
cat << EOF > /YYeTsBot/YYeTsFE/build/robots.txt
|
||||||
User-agent: *
|
User-agent: *
|
||||||
Disallow: /
|
Disallow: /
|
||||||
EOF
|
EOF
|
||||||
@@ -14,7 +14,6 @@ import os
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import sys
|
|
||||||
|
|
||||||
import fakeredis
|
import fakeredis
|
||||||
import redis
|
import redis
|
||||||
@@ -26,11 +25,13 @@ predefined_str = re.sub(r"[1l0oOI]", "", string.ascii_letters + string.digits)
|
|||||||
|
|
||||||
class Redis:
|
class Redis:
|
||||||
def __init__(self):
|
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)
|
logging.info("%s Disable redis for standalone exe! %s", "#" * 10, "#" * 10)
|
||||||
self.r = fakeredis.FakeStrictRedis()
|
self.r = fakeredis.FakeStrictRedis()
|
||||||
else:
|
|
||||||
self.r = redis.StrictRedis(host=os.getenv("redis") or "localhost", decode_responses=True)
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.r.close()
|
self.r.close()
|
||||||
|
|||||||
1869
yyetsweb/templates/js/sample.json
vendored
1869
yyetsweb/templates/js/sample.json
vendored
File diff suppressed because it is too large
Load Diff
28
yyetsweb/tests/router_test.py
Normal file
28
yyetsweb/tests/router_test.py
Normal 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()
|
||||||
Reference in New Issue
Block a user