Search code examples
yamlformattinggithub-actions

Getting "You have an error in your yaml syntax on line X" in Github Actions


I am making a Github workflow for testing a lambda function correctness.

Here is a snippet of the workflow config:

name: push-lambda

on:
  push:
    branches:
      - main
env:
  PYTHON_VERSION: "3.9"

defaults:
  run:
    shell: bash

jobs:
  test_lambda:
    runs-on: ubuntu-latest
    steps:
      - name: Install python
      - uses: actions/setup-python@v4
      with:
        python-version: ${{ env.PYTHON_VERSION }}
      
      - name: Install bs4
        run: pip install bs4

      - name: Checkout repo
      - uses: actions/checkout@v3

      - name: Test function correctness
        run: python function.py
(...)

However, I keep getting a

You have an error in your yaml syntax on line 20

error message. Line 20 is the first steps: keyword. Can anyone spot where I am making a mistake?


Solution

  • There is an indentation problem in your YAML at line 20, in the Install python step.

    You're using:

    jobs:
      test_lambda:
        runs-on: ubuntu-latest
        steps:
          - name: Install python
          - uses: actions/setup-python@v4
          with:
            python-version: ${{ env.PYTHON_VERSION }}
    

    Instead of:

    jobs:
      test_lambda:
        runs-on: ubuntu-latest
        steps:
          - name: Install python
          - uses: actions/setup-python@v4
            with:
              python-version: ${{ env.PYTHON_VERSION }}
    

    The with field should be at the same level than the uses field.