GH-200 - Author and maintain actions - Section 3.4

Implement workflow commands inside an action to set outputs, write environment files and emit log messages.

Implement workflow commands inside a custom action to set step outputs via GITHUB_OUTPUT and write environment variables to environment files. Use the actions toolkit libraries to emit debug, warning, and error log messages.

workflow commandsset outputGITHUB_OUTPUTactions toolkit

Practice question for this objective

Free sampleAuthor and maintain actionsmedium

A maintainer is authoring a composite action and wants action.yml to declare an output called report-url whose value comes from a step that has the id generate. The step writes the value to the file referenced by the GITHUB_OUTPUT environment variable. How should the action's metadata reference that step output so consumers can read it?

outputs:
  report-url:
    description: "Link to the generated report"
    value: <expression>
  • Avalue: ${{ jobs.generate.outputs.report-url }}, because the output is produced inside a job step and the jobs context exposes each step result for the metadata to forward to consumers.
  • Bvalue: ${{ env.report-url }}, because the step exported the value to the environment file, so reading it back through the env context lets the action surface the output to its consumers.
  • Cvalue: ${{ needs.generate.outputs.report-url }}, because the needs context carries forward outputs from the named unit so the action metadata can publish report-url to callers.
  • Dvalue: ${{ steps.generate.outputs.report-url }}, because a composite action output maps to a step output through the steps context using the step id and the output name written to GITHUB_OUTPUT. Correct
Bind a composite action output to a step result using the steps context with the step id and the output name from GITHUB_OUTPUT. A composite action declares each output's value with an expression, and the supported source for a step result is the steps context, written as steps.<id>.outputs.<name>. The generate step that wrote report-url to the GITHUB_OUTPUT file is therefore read as steps.generate.outputs.report-url. The jobs and needs contexts operate at workflow and job-dependency level and are unavailable inside an action, and env only carries values written to GITHUB_ENV.

Why A is wrong: Tempting because jobs do expose outputs at workflow level, but inside an action the jobs context is not available, so referencing step values through jobs returns nothing.

Why B is wrong: Tempting since GITHUB_OUTPUT looks like an environment file, but it feeds the steps context not env, and env would only work had the step written to GITHUB_ENV instead.

Why C is wrong: Tempting because needs surfaces outputs across dependent jobs, but it applies to job dependencies in a workflow, not to steps within a single composite action, so it resolves to nothing here.

Why D is correct: Composite action outputs bind to a step output via the steps context, so steps.generate.outputs.report-url correctly references the value the generate step wrote to GITHUB_OUTPUT.

See more GH-200 practice questions, answers explained.

More in this domain

Back to all Author and maintain actions objectives, or the GH-200 cert hub.

Examworthy is not affiliated with or endorsed by GitHub. Original, blueprint-aligned practice material only.