Understanding YAML in GitHub Actions Quiz Quiz

Explore the essentials of YAML syntax and structure used in GitHub Actions, learn key principles for workflow configuration, and identify common errors to ensure reliable automation in your projects.

  1. YAML Syntax for Key-Value Pairs

    Which line correctly declares a key-value pair in a YAML workflow file?

    1. name -u003E Build and Test
    2. name: Build and Test
    3. name : Build and Test
    4. name = Build and Test

    Explanation: In YAML files, key-value pairs are declared by separating the key and the value with a colon and a space, as in the correct answer. Using an equals sign, arrow, or adding spaces before or after the colon is incorrect and will result in a parsing error. Option B uses an equal sign, which is not valid in YAML. Option C uses an arrow, which is also not valid. Option D places a space before the colon, which may cause the key to be misinterpreted.

  2. Anchors and Aliases in YAML

    How does YAML allow you to reuse a set of steps in multiple jobs within a workflow?

    1. By commenting sections
    2. By using indented lists
    3. By declaring variables
    4. By using anchors and aliases

    Explanation: Anchors and aliases let you define reusable blocks in YAML, reducing duplication by referencing a previously defined anchor with an alias. Declaring variables does not let you repeat complex blocks like steps. Indented lists are for basic data structures and not for reuse. Commenting sections only adds notes and has no effect on the workflow structure.

  3. Indentation and Structure Enforcement

    What happens if you mix tabs and spaces for indentation in a YAML workflow file?

    1. The indentation will be automatically fixed
    2. The workflow will run normally
    3. Only the first step will be executed
    4. The parser will throw a syntax error

    Explanation: Mixing tabs and spaces is not allowed in YAML and will cause a syntax error, preventing the workflow from running. YAML strictly requires using spaces for indentation. If mixed, the parser stops processing and reports an error. Option B is incorrect because the workflow will not run. Option C is not correct as none of the steps will execute. Option D is wrong as YAML parsers do not automatically fix indentation.

  4. Lists in YAML Within GitHub Workflows

    In a YAML workflow file, which way should you declare a list of environment variables?

    1. - VAR1=value1n- VAR2=value2
    2. environment:n VAR1: value1n VAR2: value2
    3. environment: [VAR1: value1, VAR2: value2]
    4. VAR1: value1, VAR2: value2

    Explanation: To declare environment variables in a YAML workflow, you use nested key-value pairs under the 'environment' key, properly indented. Option D is the correct format for specifying multiple environment variables. Option A uses a list syntax, which is not suitable for key-value pairs like environment variables. Option B attempts a single-line declaration, but with a syntax invalid in YAML. Option C mixes list and dictionary syntax incorrectly.

  5. Boolean Values Interpretation in YAML

    In YAML used for workflow conditions, which value will be interpreted as a Boolean ‘true’?

    1. yes
    2. on
    3. true
    4. ‘true’ (as a string in single quotes)

    Explanation: YAML recognizes unquoted true as a Boolean true, which is interpreted as a Boolean in conditions. Quoted 'true' is treated as a string, not a Boolean. 'yes' and 'on' are sometimes interpreted as Boolean true in plain YAML, but workflow parsers usually require 'true' or 'false' for clarity. Choosing the true Boolean value helps prevent ambiguity in workflow behaviors.