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.)
Aauthor
Bbranding
Cname
Dinputs
Edescription
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.
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?
Auses: octo-org/ci-tools@v2 with path: lint
Buses: ./lint@v2
Cuses: octo-org/ci-tools/lint/action.yml@v2
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.
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?
AThe output is dropped until it is declared in action.yml
BThe output can be used; declaring it documents it
CThe output works only for steps in the action itself
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.
A composite action step has if: !startsWith(github.ref, 'refs/tags/'). The action fails to load with a YAML error. What fixes it?
AWrite the condition as ${{ !startsWith(github.ref, 'refs/tags/') }}
BReplace the step's if with continue-on-error
CMove !startsWith(github.ref, 'refs/tags/') into the workflow that calls the action
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.
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?
AINPUT_API-KEY
BINPUT_API_KEY
CAPI_KEY
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.
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?
AIn .github/workflows, next to the workflow files
BIn the repository root, both in one action.yml
CIn subfolders of .github/actions, such as .github/actions/build
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.