Github 操作语法:工作流文件无效

Github actions syntax: Invalid workflow file

我开始使用 github 操作,我试图在创建 python 包之前让几行 shell 脚本 运行ning。但是我无法将我的代码获取到 运行。它总是停在行 run: | - 这很奇怪,因为我之前一直在使用这条确切的行(见下文)。有谁知道我做错了什么?

name: Python packaging

on: [push]

jobs:
    job1:
        name: Update version
        runs-on: ubuntu-latest
        steps:
            - name: checkout repo
               uses: actions/checkout@v3

               # ----- This is where the error occurs. Error message: 
               # Check failure on line 11 in .github/workflows/main.yml 
               # GitHub Actions / .github/workflows/main.yml
               # Invalid workflow file 
               # You have an error in your yaml syntax on line 11

            - name: Increase version
               run: |
               old_version=$(grep -oP '(?<=0.0.)[0-99]+' contrib/_version.py)
               new_version=$(($old_version + 1))
               str="__version__=\"0.0."
               out="$str$new_version\""
               sed -i '1s/.*/'$out'/' contrib/_version.py

     job2:
        name: Build and upload
        needs: job1
        runs-on: ubuntu-latest
        strategy:
          matrix:
            python-version: ["3.9"]
        steps:
        - name: checkout repo
            uses: actions/checkout@v3
        - name: Set up Python ${{ matrix.python-version }}
            uses: actions/setup-python@v3
            with:
            python-version: ${{ matrix.python-version }}
        - name: Install dependencies
            run: |
            python -m pip install --upgrade pip setuptools wheel
            python -m pip install setuptools wheel
            python -m pip install --upgrade build
            python -m pip install --upgrade twine
            if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
        - name: Create package
            run: |
            python3 -m build
        - name: Upload to Test PyPI
            env:
            TWINE_USERNAME: "__token__"
            TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
            TWINE_REPOSITORY_URL: "https://test.pypi.org/legacy/"
            run: |
            twine check dist/*
            twine upload --verbose --skip-existing dist/*   

文件采用 YAML 语法,高度依赖于缩进。

根据您的示例:

  • job1:job2: 必须在同一列。
  • steps: 下,name:uses: 必须在同一列。
  • ...

name: Python packaging

on: [push]

jobs:
    job1:
        name: Update version
        runs-on: ubuntu-latest
        steps:
            - name: checkout repo
              uses: actions/checkout@v3

            - name: Increase version
              run: |
                old_version=$(grep -oP '(?<=0.0.)[0-99]+' contrib/_version.py)
                new_version=$(($old_version + 1))
                str="__version__=\"0.0."
                out="$str$new_version\""
                sed -i '1s/.*/'$out'/' contrib/_version.py

    job2:
        name: Build and upload
        # ...