Skip to content

Chapter 2 of 9

Workflow Syntax and YAML Basics

Read and write valid workflow YAML with events, jobs, expressions, and defaults.

34 minutes 10 quick checksBy Subha Prasad
Lesson 2 of 9Course navigation

Lesson content

Read, practise, then check your understanding

Workflow Syntax and YAML Basics

A workflow file is a YAML mapping. GitHub interprets a small set of top-level keys such as name, on, permissions, env, defaults, concurrency, and jobs. YAML is concise, but indentation and data types matter; a misplaced space can change structure.

Core ideas

  • on accepts one event, a list of events, or a mapping containing event-specific filters.
  • jobs maps stable job identifiers to job configuration. The identifiers are used by dependencies and expressions.
  • Expressions inside ${{ ... }} read contexts such as github, inputs, needs, matrix, secrets, and vars.
  • env can be declared at workflow, job, or step scope; the narrowest declaration overrides broader values.

How it works

Validate syntax before merging with the editor schema or a workflow linter. Quote ambiguous YAML values, use spaces rather than tabs, and remember that workflow files must use .yml or .yaml inside .github/workflows. Expressions are evaluated by Actions, while shell variable expansion happens later on the runner.

Configuration example

name: Validate
run-name: "Validate ${{ github.ref_name }} by @${{ github.actor }}"

on:
  workflow_dispatch:
    inputs:
      mode:
        description: Validation mode
        type: choice
        options: [quick, full]
        default: quick

env:
  CI: "true"

jobs:
  check:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - run: echo "Mode is ${{ inputs.mode }}"

Read the example from top to bottom: the trigger creates a run, the job requests a runner, and each step receives only the context configured for it. Adapt names, versions, permissions, and commands to the repository rather than copying production credentials or policies blindly.

Production guidance

  • Keep job identifiers stable; changing one can break needs references and required-check configuration.
  • Prefer explicit values and small files over clever YAML anchors or deeply nested expressions.
  • Do not place secrets directly in YAML. Reference the secrets context at the narrowest step that needs it.

The chapter quiz follows this lesson and checks both the vocabulary and the operational decisions behind the configuration.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement correctly describes YAML?
Which term matches this explanation: The indentation-sensitive data format used for workflow definitions.
Which statement correctly describes workflow directory?
Which term matches this explanation: The .github/workflows directory where workflow files must be stored.
Which statement correctly describes on key?
Which term matches this explanation: The workflow field that declares triggering events.
Which statement correctly describes jobs key?
Which term matches this explanation: The workflow field containing independently scheduled units of work.
Which statement correctly describes indentation?
Which term matches this explanation: Whitespace that establishes YAML nesting and must remain consistent.

0 of 10 checks passed

Your progress is saved on this device.