Home > Mobile >  Github actions issue - Error: Process completed with exit code 2
Github actions issue - Error: Process completed with exit code 2

Time:02-25

I have following piece of code for github actions:

name: Python application

on:
  push:
    branches: [ main ]

jobs: 
  build: 
  
    runs-on: ubuntu-latest
    
    steps: 
    - uses: actions/checkout@v2
    - name: Install dependencies 
      run: /
        python -m pip install --upgrade pip
        python -m pip install numpy pytest
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test Selenium
      run: /
        python -m pytest -v -m devs

But when I commit, and actions start running, I get this error:

Run / python -m pip install --upgrade pip python -m pip install numpy pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
  / python -m pip install --upgrade pip python -m pip install numpy pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
  shell: /usr/bin/bash -e {0}
/home/runner/work/_temp/317511f5-0874-43d8-a0ae-2601804ff811.sh: line 1: syntax error near unexpected token `then'
Error: Process completed with exit code 2.   

And this is just under my Install dependencies. Am I missing something super obvious? Thank you in advance for the help.

CodePudding user response:

Yes - you have a simple mistake there :)

To have multiple commands under run you have to use: run: | not \

\ is used later on to have one bash command split into multiple lines

name: Python application

on:
  push:
    branches: [ main ]

jobs: 
  build: 
  
    runs-on: ubuntu-latest
    
    steps: 
    - uses: actions/checkout@v2
    - name: Install dependencies 
      run: |
        python -m pip install --upgrade pip
        python -m pip install numpy pytest
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test Selenium
      run: |
        python -m pytest -v -m devs
  • Related