Evaluate your understanding of reusable workflows and composite actions with practical questions focusing on structure, invocation, and best practices. Assess your ability to implement automation efficiently and recognize key distinctions between these two powerful automation techniques.
Which option correctly shows how a workflow file can call a reusable workflow using the 'uses' keyword within a job?
Explanation: The correct syntax for invoking a reusable workflow is to use the 'uses' keyword followed by the repository and workflow file reference, such as 'deploy-workflow@main'. The first option refers to a local path, which is incorrect for reusable workflows. The third option contains a typo, using 'use' instead of 'uses'. The fourth option attempts to run a file directly rather than using the workflow's invocation mechanism.
How can you define input parameters for a composite action so the value can be passed when it is called?
Explanation: To accept input parameters in a composite action, they must be defined in the 'inputs' section at the root of the action definition file. Placing them under 'env' in jobs sets environment variables, not action inputs. Using 'with' inside steps is only for providing input values after they are defined, not for declaring them. Adding variables in the YAML header alone does not correctly define structured inputs.
Which of the following statements is true regarding the step types supported within composite actions?
Explanation: Composite actions are versatile and may contain both 'run' steps (for shell commands) and 'uses' steps (to wrap other actions). Limiting to only 'run' steps is incorrect, as is stating they must be shell scripts. The 'call' keyword is not valid; workflows can't be invoked directly from composite actions in this manner.
In a scenario where a reusable workflow sets an output called 'deploy-url', how can the calling workflow access this output?
Explanation: The output from a reusable workflow is accessed in the calling workflow using the syntax 'jobs.u003Cjob_idu003E.outputs.deploy-url'. Referencing 'steps.deploy-url' is suited for step outputs, not workflow outputs. There is no global 'outputs.deploy-url' variable without further context. The environment variable approach does not provide access to workflow outputs directly.
What is a primary advantage of using a composite action for repeated logic, such as setting up environment variables and running tools, across multiple workflows?
Explanation: Composite actions are designed to promote code reuse by grouping several steps into a single reusable action, making workflow files cleaner and more manageable. They are not the exclusive mechanism for running shell scripts, nor do they inherently make steps execute faster. Artifact management is not a built-in feature of composite actions without explicit configuration.