AI Hints
CI/CD with GitHub Actions · Lesson 11 of 138

YAML Basics

Keys and values.

⏱ 2 min read▶ Video at 11:46🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Workflows are written in YAML, a simple format for data. It's designed to be easy for people to read. Most of it is just keys and values, with indentation showing what belongs to what.

YAML Basics
From the video: YAML Basics
  • Workflows are YAML
  • Easy for people to read
  • Keys, values, indentation

Keys and values

Each line is a key, a colon, a space, and a value. Values can be text, numbers, or true and false. Text usually doesn't need quotes. Indentation, with spaces, puts keys inside other keys, like timeout inside settings. And a dash starts an item in a list.

config.ymlyaml
team: shop
version: 3
active: true
owner: Sam

languages:
  - python
  - javascript

settings:
  timeout: 30
  region: eu-west

What the computer sees

Let's ask Python to read the file, and print what it understood. Every key became a name, the numbers became numbers, true became a real true value, languages became a list, and settings became a nested group. This is exactly what GitHub sees when it reads a workflow.

Terminal
python3 -c "import yaml, pprint; pprint.pprint(yaml.safe_load(open('config.yml')), sort_dicts=False)"
{'team': 'shop',
 'version': 3,
 'active': True,
 'owner': 'Sam',
 'languages': ['python', 'javascript'],
 'settings': {'timeout': 30, 'region': 'eu-west'}}

Summary

YAML is keys and values, with indentation for nesting and dashes for lists. Next, lists and maps, in more detail.

Key takeaways
  • key: value
  • Indent with spaces
  • - for list items
Next up: YAML Lists and Maps — nesting data