Home > other >  Github actions syntax: Invalid workflow file
Github actions syntax: Invalid workflow file

Time:05-27

I started using github actions and I am trying to let a few lines of shell script running before I create a python package. But I can't get my code to run. It always stops on the line run: | - which is odd because I have been using this exact line before before (see further down). Does anyone know what I am doing wrong?

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/*   

CodePudding user response:

The file is in YAML syntax which highly depends on indentation.

Based on your example:

  • job1: and job2: must be at the same column.
  • Under steps:, name: and uses: must be at the same column.
  • ...

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
        # ...
  • Related