Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Actions - You have an error in your yaml syntax

Running code from https://docs.github.com/en/free-pro-team@latest/actions/quickstart

why does this code create a syntax error:

- name: Checkout code
    uses: actions/checkout@v2

but this is fine:

- name: Checkout code
  uses: actions/checkout@v2

According to this YAML How many spaces per indent? there are no indentation requirements for YAML.

like image 805
Snowcrash Avatar asked Feb 24 '26 14:02

Snowcrash


1 Answers

It's correct that the number of spaces can be freely chosen, but for the same node it has to be equal.

This is a mapping with two keys:

name: Checkout code
uses: actions/checkout@v2

but if you write it like this:

name: Checkout code
  uses: actions/checkout@v2

then the uses: ... is seen as a continuation of the previous value for name. But it's invalid, because colons plus spaces aren't allowed in mapping values.

If it looked like that:

name: Checkout code
  more

it would be valid YAML, equal to:

name: Checkout code more

So inside of that mapping, always use the same amount of spaces.

May I also recommend my short tutorial?

like image 62
tinita Avatar answered Feb 27 '26 06:02

tinita



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!