diff --git a/.env.dev b/.env.dev index 44f19fe28..d9a7a016d 100644 --- a/.env.dev +++ b/.env.dev @@ -16,6 +16,8 @@ SELF_NICKNAME="小真寻" # 数据库配置 # 示例: "postgres://user:password@127.0.0.1:5432/database" +# 示例: "mysql://user:password@127.0.0.1:3306/database" +# 示例: "sqlite:data/db/zhenxun.db" 在data目录下建立db文件夹 DB_URL = "" # 系统代理 diff --git a/.github/workflows/bot_check.yml b/.github/workflows/bot_check.yml index b4502d641..ac532629e 100644 --- a/.github/workflows/bot_check.yml +++ b/.github/workflows/bot_check.yml @@ -3,8 +3,16 @@ name: 检查bot是否运行正常 on: push: branches: ["dev", "main"] + paths: + - zhenxun/** + - tests/** + - bot.py pull_request: branches: ["dev", "main"] + paths: + - zhenxun/** + - tests/** + - bot.py jobs: bot-check: @@ -28,7 +36,14 @@ jobs: uses: actions/cache@v3 with: path: ~/.cache/pypoetry - key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }} + key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('pyproject.toml') }} + + - name: Cache playwright cache + id: cache-playwright + uses: actions/cache@v3 + with: + path: ~/.cache/ms-playwright + key: playwright-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }} - name: Cache Data cache uses: actions/cache@v3 @@ -42,7 +57,9 @@ jobs: rm -rf poetry.lock poetry source remove ali poetry install --no-root - poetry run pip install pydantic==1.10 + + - name: Run tests + run: poetry run pytest --cov=zhenxun --cov-report xml - name: Check bot run id: bot_check_run diff --git a/.github/workflows/update_version.yml b/.github/workflows/update_version.yml new file mode 100644 index 000000000..9e788ae7b --- /dev/null +++ b/.github/workflows/update_version.yml @@ -0,0 +1,65 @@ +name: Update Version + +on: + pull_request_target: + paths: + - zhenxun/** + - resources/** + - bot.py + types: + - opened + - synchronize + branches: + - main + - dev + +jobs: + update-version: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Read current version + id: read_version + run: | + version_line=$(grep '__version__' __version__) + version=$(echo $version_line | sed -E 's/__version__:\s*v([0-9]+\.[0-9]+\.[0-9]+)(-.+)?/\1/') + echo "Current version: $version" + echo "current_version=$version" >> $GITHUB_OUTPUT + + - name: Check for version file changes + id: check_diff + run: | + if git diff --name-only HEAD~1 HEAD | grep -q '__version__'; then + echo "Version file has changes" + echo "version_changed=true" >> $GITHUB_OUTPUT + else + echo "Version file has no changes" + echo "version_changed=false" >> $GITHUB_OUTPUT + fi + + - name: Get commit hash + id: get_commit_hash + run: echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Update version file + if: steps.check_diff.outputs.version_changed == 'false' + run: | + current_version="${{ steps.read_version.outputs.current_version }}" + commit_hash="${{ steps.get_commit_hash.outputs.commit_hash }}" + new_version="v${current_version}-${commit_hash}" + echo "Updating version to: $new_version" + echo "__version__: $new_version" > __version__ + git config --global user.name "${{ github.event.pull_request.user.login }}" + git config --global user.email "${{ github.event.pull_request.user.login }}@users.noreply.github.com" + git add __version__ + git remote set-url origin https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git + git commit -m "chore(version): Update version to $new_version" + git push origin HEAD:${{ github.event.pull_request.head.ref }} + + - name: Check updated version + if: steps.check_diff.outputs.version_changed == 'false' + run: cat __version__ diff --git a/.gitignore b/.gitignore index 649322231..db7233b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -174,11 +174,9 @@ data/ /resources/image/prts/ /configs/config.py configs/config.yaml -./.env -./.env.dev plugins/csgo_server/ plugins/activity/ !/resources/image/genshin/alc/back.png !/data/genshin_alc/ .vscode/launch.json -/resources/template/my_info \ No newline at end of file +plugins_/ \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..78547a79a --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "charliermarsh.ruff", + "esbenp.prettier-vscode", + "ms-python.black-formatter", + "ms-python.isort", + "ms-python.python", + "ms-python.vscode-pylance" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index dc0ad84cc..6ab1cbda8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,7 +23,37 @@ "ujson", "unban", "userinfo", - "zhenxun" + "zhenxun", + "jsdelivr" ], - "python.analysis.autoImportCompletions": true + "python.analysis.autoImportCompletions": true, + "python.testing.pytestArgs": ["tests"], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff", // 默认使用 Ruff 格式化 + "editor.wordBasedSuggestions": "allDocuments", + "editor.formatOnType": true, + "editor.formatOnSave": true, // 保存时自动格式化 + "editor.codeActionsOnSave": { + "source.fixAll.ruff": "explicit", + "source.organizeImports": "explicit" + } + }, + "ruff.format.preview": false, + "isort.check": true, + "ruff.importStrategy": "useBundled", + "ruff.organizeImports": false, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[yaml]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[markdown]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } } diff --git a/Dockerfile b/Dockerfile index 18776e5a0..343d4d966 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,13 @@ WORKDIR /app/zhenxun COPY . /app/zhenxun +RUN apt update && \ + apt upgrade -y && \ + apt install -y --no-install-recommends \ + gcc \ + g++ && \ + apt clean + RUN pip install poetry -i https://mirrors.aliyun.com/pypi/simple/ RUN poetry install @@ -14,6 +21,8 @@ VOLUME /app/zhenxun/data /app/zhenxun/data VOLUME /app/zhenxun/resources /app/zhenxun/resources +VOLUME /app/zhenxun/.env.dev /app/zhenxun/.env.dev + RUN poetry run playwright install --with-deps chromium -CMD ["poetry", "run", "python", "bot.py"] \ No newline at end of file +CMD ["poetry", "run", "python", "bot.py"] diff --git a/README.md b/README.md index 884b7d691..fe7c82480 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@