From 0a44fb111fc18f1c15b66cade38925f1ac0051b9 Mon Sep 17 00:00:00 2001 From: linhemin Date: Mon, 10 Feb 2025 21:09:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ci(pylint):=20=E4=BC=98=E5=8C=96=20Pylint?= =?UTF-8?q?=20=E6=A3=80=E6=9F=A5=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化工作流结构,增加步骤名称和注释,提高可读性 - 修改文件读取逻辑,确保正确读取 Pylint 报告 - 优化 PR 评论内容,增加开头和结尾的友好提示 - 修正代码中的注释和日志信息,使用更自然的语言 --- .github/workflows/pylint_check.yml | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/pylint_check.yml diff --git a/.github/workflows/pylint_check.yml b/.github/workflows/pylint_check.yml new file mode 100644 index 0000000..3cff0c0 --- /dev/null +++ b/.github/workflows/pylint_check.yml @@ -0,0 +1,52 @@ +name: Pylint 检查 + +on: + pull_request: + types: [ opened, synchronize, reopened ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: 检出代码 + uses: actions/checkout@v2 + + - name: 设置 Python 环境 + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: 安装 Pylint + run: | + python -m pip install --upgrade pip + pip install pylint + + - name: 执行 Pylint 检查 + id: pylint_run + run: | + # 对整个代码库运行 Pylint,将输出写入文件 + pylint . > pylint-report.txt + + - name: 检查报告并发表评论 + if: always() + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const report = fs.readFileSync('pylint-report.txt', 'utf8').trim(); + if (!report) { + console.log("喵~ 没有发现 Pylint 错误哦!"); + return; + } + const pr = context.payload.pull_request; + if (!pr) { + console.log("喵~ 没有获取到 PR 信息哦!"); + return; + } + const author = pr.user.login; + const commentBody = `@${author} 亲亲,喵喵检测到以下 Pylint 警告或错误,请主人检查并修改喵~\n\n\`\`\`\n${report}\n\`\`\``; + await github.rest.issues.createComment({ + ...context.repo, + issue_number: pr.number, + body: commentBody + }); From 8054e9ca365414419af7a308d7fed8d1adb798cb Mon Sep 17 00:00:00 2001 From: linhemin Date: Mon, 10 Feb 2025 21:15:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?ci(pylint):=20=E4=BC=98=E5=8C=96=20Pylint?= =?UTF-8?q?=20=E6=A3=80=E6=9F=A5=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增安装依赖步骤,确保 requirements.txt 中的包被正确安装 - 优化 Pylint 安装步骤,提高代码清晰度 - 保持执行 Pylint 检查的逻辑不变 --- .github/workflows/pylint_check.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pylint_check.yml b/.github/workflows/pylint_check.yml index 3cff0c0..80ca00b 100644 --- a/.github/workflows/pylint_check.yml +++ b/.github/workflows/pylint_check.yml @@ -16,15 +16,20 @@ jobs: with: python-version: '3.x' - - name: 安装 Pylint + - name: 安装依赖 run: | python -m pip install --upgrade pip - pip install pylint + if [ -f requirements.txt ]; then + echo "喵~ 检测到 requirements.txt ,开始安装依赖包喵~" + pip install -r requirements.txt + fi + + - name: 安装 Pylint + run: pip install pylint - name: 执行 Pylint 检查 id: pylint_run run: | - # 对整个代码库运行 Pylint,将输出写入文件 pylint . > pylint-report.txt - name: 检查报告并发表评论