Github 操作问题 - 错误:进程已完成,退出代码 2

发布于 2025-01-09 22:30:50 字数 1075 浏览 0 评论 0原文

我有以下 github 操作的代码:

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

但是当我提交并且操作开始运行时,我收到此错误:

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.   

这就在我的安装依赖项下。我错过了一些非常明显的东西吗?预先感谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天赋异禀 2025-01-16 22:30:50

是的 - 你有一个简单的错误:)

要在 run 下使用多个命令,你必须使用:
run: | 而不是 \

\ 稍后用于将一个 bash 命令分成多行

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文