YAML (Yet Another Markup Language) is a clean, human-readable format used extensively in DevOps and infrastructure tools - and it's what we use to define workflows in GitHub Actions. If you're new to YAML, here's a quick introduction to help you understand the essentials before diving into workflows.
✅ What is YAML?
YAML is a way to organize data using key-value pairs. It is similar to how dictionaries work in Python or objects in JavaScript.
It is indentation-sensitive and uses spaces, not tabs.
YAML is used to create configuration files that are easy to read and organize.
🔤 Primitive Data Types in YAML
YAML supports three basic primitive types:
Strings
Can be unquoted:
name: John
Or quoted (useful for special characters):
name: "John Doe"
Numbers
Example:
age: 30
Booleans
true or false
🧱 Dictionaries (Nested Key-Value Pairs)
You can define nested dictionaries by indenting child keys:
config:
path: "dir/file.yaml"
environment: "staging"
This is commonly used in GitHub Actions under keys like jobs
, steps
, etc.
📚 Arrays (Lists)
YAML uses a dash -
to define list items:
env:
- development
- staging
- production
Lists can also contain complex objects:
env:
- name: development
enable: phpmyadmin
- name: staging
enable: ['phpmyadmin', 'logzio']
- name: production
enable: 'logzio'
You can even nest arrays within arrays or objects:
env:
- name: development
enable:
- phpmyadmin
- lints
- tests:
depends-on: phpunit
🧠 Indentation Rules
YAML relies on indentation to define structure:
Always use consistent spaces (typically 2).
Misaligned indentation results in invalid YAML.
Valid:
name: My Workflow
environment: staging
Invalid:
name: My Workflow
environment: staging # ❌ Wrong indentation
Hierarchical Example:
config:
environment: staging
This implies: config.environment = staging
💡 Final Tips
Choose 2 or 4 spaces and stick to it throughout the file.
Quoting strings is optional, but necessary when the value includes special characters or starts with a number.
✍️ Why YAML Matters for GitHub Actions
YAML is the language GitHub Actions uses to:
Define triggers (
on: push
)Configure jobs and steps
Set environments, secrets, and conditionals
Understanding YAML helps you avoid syntax errors and build powerful automation workflows efficiently.