我有一个 GitHub 操作脚本来检查 Vue 3 项目的 lint。目标是检查 es-lint、构建并将结果输出到拉取请求对话。但是即使
npm run lint
抛出错误,我输出错误的步骤也会被跳过。
name: Lint Check
on:
pull_request:
branches:
- main # or the branch you want to run this on
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16' # Use the version required by your project
- name: Install dependencies
run: npm install
- name: Run lint
id: lint
run: |
npm run lint || echo "::set-output name=lint_result::fail"
- name: Create PR comment with lint results
if: failure()
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Lint Check
message: |
**Lint Check Failed** :x:
```
${{ steps.lint.outputs.lint_result }}
```
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
这个命令:
npm 运行 lint || echo "::set-output name=lint_result::fail"
隐藏
npm
返回的错误退出代码,因为 ||出错时运行,echo 本身完成并退出代码 0。
您需要将 if: 条件更改为:
- name: Create PR comment with lint results
if: ${{ steps.lint.outputs.lint_result != '' }}
uses: marocchino/sticky-pull-request-comment@v2
with: