Using GitHub Actions, how do you store flake8 exit code as a variable instead of failing the workflow?
Asked Answered
V

1

2

I have a GitHub Action workflow file that is doing multiple linting checks. flake8 is the first linting check and if it fails the entire workflow fails meaning the subsequent linting checks are name: lint

on:
  push:
  pull_request:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@main
      with:
        ref: ${{ github.head_ref }}
    - name: python
      uses: actions/setup-python@main
      with:
        # pulls latest version of python, alternatively specify exact version (i.e. 3.8 -> no quotes)
        python-version: '3.9'
    - name: install
      run: |
        pip install -r requirements.txt
    - name: Lint with flake8
      run: |
        # fail if there are any flake8 errors
        flake8 . --count --max-complexity=15 --max-line-length=127 --statistics
    ## subsequent linting jobs
Vestal answered 21/7, 2022 at 14:4 Comment(2)
See the continue-on-error optionInsolate
@Insolate this would work great. Is it possible to have a job output variable indicating that it failed that can be used by subsequent jobs?Vestal
I
4

You could use the continue-on-error in conjunction with the outcome of the step. From the doc:

steps.<step_id>.outcome string The result of a completed step before continue-on-error is applied. Possible values are success, failure, cancelled, or skipped. When a continue-on-error step fails, the outcome is failure, but the final conclusion is success.

As example:

  - name: Lint with flake8
    id: flake8
    continue-on-error: true
    run: |
      # fail if there are any flake8 errors
      flake8 . --count --max-complexity=15 --max-line-length=127 --statistics

  - name: Check if 'Lint with flake8' step failed
    if: steps.flake8.outcome != 'success'
    run: |
      echo "flake8 fails"
      exit 1
      
Insolate answered 21/7, 2022 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.