Question 1
Choose 1
What can be used to set a failed status of an action from its code?
Correct answer:
D. a non-zero exit code
Explanation:
This question tests the fundamental mechanism for signaling a failure in a GitHub Actions workflow step. When an action runs, its underlying code (whether JavaScript, shell script, or container process) must communicate its success or failure back to the Actions runner. The primary and universal way to do this is through the process's exit status code.
Correct Option:
D. a non-zero exit code:
This is the correct answer. The GitHub Actions runner interprets any command or script that terminates with a non-zero exit code as a failure. This is a standard convention in process management and shell scripting. For a custom action, if the main entry point (e.g., main.js, a shell script, or a Docker container's main process) exits with a non-zero code, the runner immediately marks that step as failed and, by default, stops the workflow.
Incorrect Option:
A. @actions/github toolkit:
This is a client library for interacting with the GitHub API, not for setting the action's status. While related to action development, it cannot directly signal a failure to the runner.
B. JavaScript dist/ folder:
This is the compiled output directory for TypeScript/JavaScript actions. It contains the runnable code but is not a mechanism for signaling status.
C. Dockerfile CMD:
This instruction defines the default command for a Docker container action. While the command's exit code will set the status, the CMD itself is just a configuration. The failure mechanism is still the non-zero exit code of the process it runs.
E. output variable:
Outputs are used to pass data between job steps, not to control the step's execution status. Setting an output does not affect whether the step is considered successful or failed.
F. composite run step:
This is a type of action that groups multiple run commands. It is a construct, not a method for signaling failure. The failure of any command within it (via a non-zero exit code) causes the composite step to fail.
Reference:
GitHub Docs,Workflow commands for GitHub Actions: Setting an exit code" – It states, "You can use the exit command to immediately end an action and set an exit code. If the exit code is not set, the exit code of the last run command is used as the exit code of the step." This underscores that the runner is governed by the exit code of the process.
This question tests the fundamental mechanism for signaling a failure in a GitHub Actions workflow step. When an action runs, its underlying code (whether JavaScript, shell script, or container process) must communicate its success or failure back to the Actions runner. The primary and universal way to do this is through the process's exit status code.
Correct Option:
D. a non-zero exit code:
This is the correct answer. The GitHub Actions runner interprets any command or script that terminates with a non-zero exit code as a failure. This is a standard convention in process management and shell scripting. For a custom action, if the main entry point (e.g., main.js, a shell script, or a Docker container's main process) exits with a non-zero code, the runner immediately marks that step as failed and, by default, stops the workflow.
Incorrect Option:
A. @actions/github toolkit:
This is a client library for interacting with the GitHub API, not for setting the action's status. While related to action development, it cannot directly signal a failure to the runner.
B. JavaScript dist/ folder:
This is the compiled output directory for TypeScript/JavaScript actions. It contains the runnable code but is not a mechanism for signaling status.
C. Dockerfile CMD:
This instruction defines the default command for a Docker container action. While the command's exit code will set the status, the CMD itself is just a configuration. The failure mechanism is still the non-zero exit code of the process it runs.
E. output variable:
Outputs are used to pass data between job steps, not to control the step's execution status. Setting an output does not affect whether the step is considered successful or failed.
F. composite run step:
This is a type of action that groups multiple run commands. It is a construct, not a method for signaling failure. The failure of any command within it (via a non-zero exit code) causes the composite step to fail.
Reference:
GitHub Docs,Workflow commands for GitHub Actions: Setting an exit code" – It states, "You can use the exit command to immediately end an action and set an exit code. If the exit code is not set, the exit code of the last run command is used as the exit code of the step." This underscores that the runner is governed by the exit code of the process.