Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
      
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading