Tips for Writing YAML Files for GitHub Actions
YAML is very sensitive to spacing, indentation, and formatting. Here are some tips to avoid common issues:
-
Use consistent indentation
-
Always use 2 spaces per level (GitHub Actions doesn’t allow tabs).
-
Example:
Wrong indentation will throw a parsing error.
-
-
Watch out for spaces around colons
-
Correct:
-
Incorrect (common mistake):
-
-
Lists need dashes at the correct level
-
Example:
Or, for multiple items:
-
-
Environment variables
-
Use
env:at the right level. Putting it understeps:instead ofjobs:will not work. -
Example:
-
-
Run commands
-
Always indent
run:commands under the step name. -
Multi-line commands can use
|:
-
-
Check for invisible characters
-
Copy-pasting from Word, email, or some websites can introduce non-breaking spaces.
-
Always use a code editor like VS Code or JetBrains Rider for editing YAML.
-
-
Validate before pushing
-
You can use online YAML validators or the VS Code YAML extension to catch syntax issues before committing.
-
Adding these tips will help anyone—especially beginners—avoid the common CI YAML errors that are caused by simple spacing or indentation issues.