Skip to content

GH-200 · Domain 3: Author and maintain actions · 19% of the exam

Task 3.2: Define action structure and metadata

The action metadata file and its inputs, outputs, runs and branding, where files live in the repository, and workflow commands used from inside an action.

Study it

  • The action metadata file and workflow commands inside actions

    Lesson coming

Sample questions

Try each one before opening the answer. Every option is explained, with the GitHub documentation page that proves it.

Question 1 · choose 3

A developer is writing the smallest valid action.yml for a new action. Which three top-level keys are required? (Choose THREE.)

  1. Aauthor
  2. Bbranding
  3. Cname
  4. Dinputs
  5. Edescription
  6. Fruns
Show the answer and why
  • Aauthor

    Incorrect

    author is optional.

  • Bbranding

    Incorrect

    branding is optional and used for the Marketplace badge.

  • Cname

    Correct

    The name is required and shown in the Actions tab.

  • Dinputs

    Incorrect

    inputs are optional; an action may take none.

  • Edescription

    Correct

    A short description is required.

  • Fruns

    Correct

    runs is required and sets how the action executes.

An action metadata file requires name, description and runs. author, inputs, outputs and branding are optional. runs sets how the action executes.

Question 2 · choose 1

The repository octo-org/ci-tools holds three actions in the folders lint, test and deploy, each with its own action.yml. How does a workflow in another repository use the lint action at tag v2?

  1. Auses: octo-org/ci-tools@v2 with path: lint
  2. Buses: ./lint@v2
  3. Cuses: octo-org/ci-tools/lint/action.yml@v2
  4. Duses: octo-org/ci-tools/lint@v2
Show the answer and why
  • Auses: octo-org/ci-tools@v2 with path: lint

    Incorrect

    Actions don't take a path input to pick a subfolder.

  • Buses: ./lint@v2

    Incorrect

    A ./ path refers to the caller's own workspace and takes no ref.

  • Cuses: octo-org/ci-tools/lint/action.yml@v2

    Incorrect

    The reference names the directory, not the metadata file.

  • Duses: octo-org/ci-tools/lint@v2

    Correct

    An action in a subdirectory is referenced by its path after the repository name.

Workflows can use an action in a subdirectory of a repository with {owner}/{repo}/{path}@{ref}, where the path names the directory that holds the action's metadata file.

Question 3 · choose 1

A JavaScript action writes url=... to GITHUB_OUTPUT, but its action.yml has no outputs section. A reviewer says the url output can't be used until it is declared. What is true?

  1. AThe output is dropped until it is declared in action.yml
  2. BThe output can be used; declaring it documents it
  3. CThe output works only for steps in the action itself
  4. DThe output must also be listed in the workflow's job outputs
Show the answer and why
  • AThe output is dropped until it is declared in action.yml

    Incorrect

    Undeclared outputs of JavaScript and Docker actions are still set.

  • BThe output can be used; declaring it documents it

    Correct

    Outputs can be set and used without a declaration, though declaring them is better practice.

  • CThe output works only for steps in the action itself

    Incorrect

    Later steps in the workflow can read it.

  • DThe output must also be listed in the workflow's job outputs

    Incorrect

    Job outputs are only for passing values to other jobs.

Output parameters let an action declare data that it sets for later steps. If you don't declare an output in the metadata file of a JavaScript or Docker container action, you can still set it and use it in a workflow. Composite action outputs must be declared with a value.

Question 4 · choose 1

A composite action step has if: !startsWith(github.ref, 'refs/tags/'). The action fails to load with a YAML error. What fixes it?

  1. AWrite the condition as ${{ !startsWith(github.ref, 'refs/tags/') }}
  2. BReplace the step's if with continue-on-error
  3. CMove !startsWith(github.ref, 'refs/tags/') into the workflow that calls the action
  4. DUse endsWith instead, which needs no negation
Show the answer and why
  • AWrite the condition as ${{ !startsWith(github.ref, 'refs/tags/') }}

    Correct

    An expression starting with ! must use the ${{ }} syntax or be quoted, because ! has a meaning in YAML.

  • BReplace the step's if with continue-on-error

    Incorrect

    That changes behavior instead of fixing the condition.

  • CMove !startsWith(github.ref, 'refs/tags/') into the workflow that calls the action

    Incorrect

    The condition can stay in the action once it is written correctly.

  • DUse endsWith instead, which needs no negation

    Incorrect

    That tests a different thing and isn't needed.

if conditionals are evaluated as expressions, so ${{ }} can usually be omitted. When the expression starts with !, which is reserved notation in YAML, it must use ${{ }} or be escaped with quotes or parentheses.

Question 5 · choose 1

A developer saved an action's metadata as metadata.yml in the repository root, and workflows can't use the action. What should the file be called?

  1. Aworkflow.yml
  2. BDockerfile
  3. Cpackage.json
  4. Daction.yml, or action.yaml
Show the answer and why
  • Aworkflow.yml

    Incorrect

    Workflow files live in .github/workflows.

  • BDockerfile

    Incorrect

    That builds a container image; it isn't metadata.

  • Cpackage.json

    Incorrect

    That describes a Node.js package, not the action.

  • Daction.yml, or action.yaml

    Correct

    The metadata file must use one of these names; action.yml is preferred.

Actions require a metadata file that uses YAML syntax, and the file name must be either action.yml or action.yaml; action.yml is the preferred form.

Question 6 · choose 1

A JavaScript action's metadata declares an input named api-key. The action's code reads the value straight from process.env instead of using the toolkit. Which environment variable holds the value?

  1. AINPUT_API-KEY
  2. BINPUT_API_KEY
  3. CAPI_KEY
  4. DINPUT_APIKEY
Show the answer and why
  • AINPUT_API-KEY

    Correct

    The input name is converted to uppercase, and the hyphen stays as it is.

  • BINPUT_API_KEY

    Incorrect

    Only spaces in the name are replaced with underscores; the hyphen is kept.

  • CAPI_KEY

    Incorrect

    Input variables are named with the INPUT_ prefix.

  • DINPUT_APIKEY

    Incorrect

    The hyphen isn't dropped from the name.

For each input, GitHub creates an environment variable named INPUT_<VARIABLE_NAME>, converting the name to uppercase letters and replacing spaces with _ characters. Hyphens stay: in the metadata reference's example, the inputs num-octocats and octocat-eye-color are read as INPUT_NUM-OCTOCATS and INPUT_OCTOCAT-EYE-COLOR.

Question 7 · choose 1

A JavaScript action declares outputs: result: with no further keys. Validation complains about the output. What does it need?

  1. AA description
  2. BA value
  3. CA type
  4. DA default value
Show the answer and why
  • AA description

    Correct

    Each declared output requires a description.

  • BA value

    Incorrect

    A JavaScript action sets its output values from its code at run time.

  • CA type

    Incorrect

    Outputs have no type key.

  • DA default value

    Incorrect

    Outputs don't take defaults.

outputs.<output_id>.description is required for every declared output, and outputs have no type or default keys.

Question 8 · choose 1

A team keeps two private actions in the same repository as its application and workflows, and doesn't plan to share them. Where does GitHub recommend storing them?

  1. AIn .github/workflows, next to the workflow files
  2. BIn the repository root, both in one action.yml
  3. CIn subfolders of .github/actions, such as .github/actions/build
  4. DIn a branch named actions
Show the answer and why
  • AIn .github/workflows, next to the workflow files

    Incorrect

    That folder is read as workflow files.

  • BIn the repository root, both in one action.yml

    Incorrect

    One metadata file describes one action.

  • CIn subfolders of .github/actions, such as .github/actions/build

    Correct

    GitHub recommends .github/actions when actions share a repository with other code.

  • DIn a branch named actions

    Incorrect

    Actions are referenced by path and ref, not stored on a branch by convention.

For actions that won't be shared, any location in the repository works, but when action, workflow and application code share a repository, GitHub recommends storing actions in the .github directory, for example .github/actions/action-a.

Practice domain 3 →Practice all domains →