gitgithubvuejs3github-actionseslint

Github action is failing but build marked as success in pull request


I have a GitHub action script to check lint for Vue 3 projects. The goal is to check es-lint, build, and output the result to the pull request conversation. But the step in which I output the errors is getting skipped even if the npm run lint throws an error.

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 }}

enter image description here

enter image description here


Solution

  • This command:

    npm run lint || echo "::set-output name=lint_result::fail"

    hides the error exit code returned by npm because || runs on error and echo itself completes with exit code 0.

    You need to change the if: condition to something like:

          - name: Create PR comment with lint results
            if: ${{ steps.lint.outputs.lint_result != '' }}
            uses: marocchino/sticky-pull-request-comment@v2
            with: