GitHub Actions YAML Workflow Syntax

How GitHub Actions workflow files are structured, what YAML formatting and validation tools change, and when reformatting or copy-pasting can break a workflow.

A GitHub Actions workflow is a YAML file stored in the .github/workflows directory of a repository, with a .yml or .yaml extension. GitHub reads it to decide when automation runs and what it does. Because the file is plain text with meaningful indentation, any tool that reformats, validates or passes it along can affect whether the workflow still works. This review explains the workflow syntax, what formatting and validation tools change, and where meaning can be lost.

The core structure of a workflow file

A workflow is a YAML mapping. The keys most readers meet first are name (a display label), on (the events that trigger the workflow), and jobs (the work to run). Each job has an identifier, a runner chosen with runs-on, and a list of steps. A step either calls a reusable action with uses, optionally passing inputs through with, or runs shell commands with run. Other common keys include env for environment variables, permissions for the token's access scope, needs for job ordering, if for conditions, and strategy.matrix for running a job across several value combinations.

name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10", "3.12"]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Run tests
        run: |
          python -m pip install -r requirements.txt
          python -m pytest

Values wrapped in ${{ }} are GitHub Actions expressions, evaluated by GitHub rather than by the YAML parser. To YAML they are ordinary strings. This split matters: a file can be perfectly valid YAML and still be an invalid or broken workflow.

What a YAML formatter or validator actually changes

In this context, "transformation" means formatting or validation, not reversing, mirroring or restyling characters. Nothing about workflow tooling involves visual effects like mirrored glyphs or decorative Unicode fonts, and applying those to a workflow file would make it unparseable. The relevant changes are to the stored characters of the file itself.

  • A formatter rewrites whitespace and layout: indentation width, spacing after colons and dashes, blank lines, and sometimes line wrapping.
  • It may change quoting style, adding, removing or switching between single and double quotes.
  • It may convert between flow style such as [main] and block style with one item per line.
  • If it works by parsing the file and re-emitting it, it may reorder keys or drop comments, depending on whether it preserves the original document.
  • A syntax validator changes nothing; it only reports whether the text is well-formed YAML.
  • A workflow-aware linter or schema check goes further, reporting unknown keys, misplaced keys or malformed expressions. Generic YAML validators do not do this.

Where reformatting can change meaning

Most whitespace changes are safe as long as nesting is preserved. The risks come from YAML rules that make some edits change the data rather than just its appearance.

Situation | What can go wrong | Safer form
Unquoted version numbers in a matrix | 3.10 is read as the number 3.1, so a job may request the wrong version | Quote it: "3.10"
Block scalar style on run | Switching from | (keep line breaks) to > (fold lines) can join shell commands onto one line | Keep | for multi-line scripts
The on key in generic YAML 1.1 tools | Some parsers and linters treat a bare on as a boolean, and a round-tripping tool may rewrite it | Leave on as written; GitHub reads it as the trigger key
An if condition starting with ! | ! begins a YAML tag, so the line can fail to parse | Wrap it as ${{ !cancelled() }} or quote it
Comments | Tools that parse and re-emit without preserving comments remove them | Use a formatter that preserves comments, or review the diff
Tabs used for indentation | YAML does not allow tabs for indentation | Use spaces only
# Risky: parsed as the number 3.1
python-version: [3.10, 3.12]

# Safe: kept as strings
python-version: ["3.10", "3.12"]

# Risky: a leading ! is a YAML tag indicator
if: !cancelled()

# Safe
if: ${{ !cancelled() }}

Will the file stay usable after copying or sharing?

Workflow YAML is plain text, so it survives copying intact when it moves between plain-text environments such as code editors, terminals and code blocks. Problems tend to appear when it passes through tools built for prose. Word processors, some chat apps, note-taking apps and email clients may convert straight quotes to curly quotes, replace ordinary spaces with non-breaking spaces, insert invisible characters, or collapse indentation. Any of these can produce parse errors, or can quietly change a key or value so it no longer matches what GitHub expects. These are general behaviors of rich-text software; no destination-specific tests were supplied, so behavior in a particular app should be checked rather than assumed.

  • Share workflow snippets inside code blocks or as attached files, not as formatted prose.
  • After pasting, run a YAML syntax check and, ideally, a workflow-aware linter before committing.
  • If a pasted file fails on a line that looks correct, suspect invisible or substituted characters, and retype the indentation and quotes.
  • Review the diff after any automated reformat, paying particular attention to quotes, block scalars and comments.

Search and editing are not affected by formatting as long as the characters stay standard. Searching a repository for a key or action name works the same before and after a whitespace-only reformat. Accessibility is a gap in the supplied evidence. Indentation carries structure in YAML, and how well a given screen reader or editor conveys nesting levels was not documented or tested here, so no claim is made about it.

Is reformatting or validation suitable for your workflow files?

For most teams, a comment-preserving formatter combined with a workflow-aware linter is a sound choice. The main benefit is consistent, readable files and early detection of syntax and structural mistakes before a push triggers a failed run. The decisive tradeoff is that reformatting can change data in a few specific cases, mainly unquoted numbers, block scalar style, a leading ! in conditions, and comment loss. Validation alone carries no such risk because it does not modify the file.

Leaving the file as hand-written plain text is preferable when a workflow is small and stable, when a tool cannot preserve comments that the team relies on, or when the only available formatter is a generic YAML tool that is not aware of GitHub Actions conventions. In those cases, run a validator and a workflow linter without accepting automatic rewrites.

Evidence gaps

This review relies on the documented structure of GitHub Actions workflows and general YAML rules. No specific formatter, linter or validator was tested, no copy-and-paste tests were run against named apps, and no assistive technology was evaluated. Claims about a particular tool's behavior, such as whether it preserves comments or key order, should be confirmed against that tool's documentation or with a quick test on a copy of your own workflow.