What can be used to set a failed status of an action from its code?
A. @actions/github toolkit
B. JavaScript dist/ folder
C. Dockerfile CMD
D. a non-zero exit code
E. output variable
F. composite run step
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.
As a developer, what is the safest way to reference an action to prevent modification of the underlying code?
A. Use a commit hash.
B. Use a branch name.
C. Use a patch release tag.
D. Use a major release tag.
Explanation:
This question addresses security and integrity in GitHub Actions workflows. Since actions are reusable code from external repositories, referencing them safely is critical to prevent supply chain attacks. The primary risk is that a tag or branch name can be moved (e.g., v1 can be updated from v1.0.0 to v1.0.1), potentially introducing malicious code. The safest method must guarantee immutability.
Correct Option:
A. Use a commit hash:
This is the most secure and immutable reference. A full SHA-1 commit hash uniquely and permanently points to a specific, unchangeable snapshot of the code. Even if the repository is compromised later, the hash you used will always refer to the exact code you reviewed and intended to use, preventing any unintended modification.
Incorrect Option:
B. Use a branch name:
This is the least safe option. Branch names like main are mutable pointers that change with every push. Referencing a branch means your workflow automatically uses the latest code, which could be maliciously modified at any time, posing a significant security risk.
C. Use a patch release tag:
While more specific than a branch, a tag like v1.0.1 is still mutable. A tag can be deleted and recreated (force-pushed) to point to a different commit. This action is highly discouraged but possible, making it less safe than an immutable commit hash.
D. Use a major release tag:
Similar to a patch tag, a major tag like v1 is a moving target (e.g., v1 could point to v1.0.0, then later to v1.1.0). While it follows semantic versioning conventions, it is explicitly designed to be updated, making it unsafe for locking in a specific, unmodifiable version of the code.
Reference:
GitHub Docs, Security hardening for GitHub Actions: Using third-party actions" explicitly states: "You should consider pinning actions to a full length commit SHA... Pinning to a SHA is currently the only way to use an action as an immutable release." This establishes the commit SHA (hash) as the security best practice.
As a developer, you need to create a custom action written in Python. Which action type should you choose?
As a developer, you need to create a custom action written in Python. Which action type should you choose?
A. JavaScript action
B. composite run step
C. Python action
D. Docker container action
Explanation:
This question tests understanding of the three types of GitHub Actions and their appropriate use cases. There is no dedicated "Python action" type. While you can write the logic in Python, you must choose a supported action type as the execution wrapper. The choice depends on managing dependencies and the runtime environment.
Correct Option:
D. Docker container action:
This is the correct choice for a Python-based action. A Dockerfile allows you to explicitly define a custom environment, install specific Python versions, and bundle all required pip dependencies into an immutable image. This ensures the action runs consistently in an isolated environment, regardless of the GitHub-hosted runner's pre-installed software.
Incorrect Option:
A. JavaScript action:
While JavaScript actions are a primary type, they are not suitable for directly running Python code. You could theoretically shell out to a Python script from a JavaScript action, but this is a convoluted approach that would still require you to manually handle Python environment setup on the runner, defeating the purpose of a clean, self-contained action.
B. Composite run step:
A composite action is designed to group multiple runner shell commands into a single action. While you could run python script.py within it, this approach has a major drawback: it assumes Python and all necessary libraries are already available on the host runner. It does not provide a mechanism to package dependencies, leading to unreliable and non-portable actions.
C. Python action:
This is a distractor. There is no native "Python action" type as a first-class citizen in GitHub Actions. You must package your Python code within one of the three supported types: Docker, JavaScript, or Composite
Reference:
GitHub Docs, "About custom actions" defines the three types: Docker container, JavaScript, and composite actions. It states that Docker container actions "package the environment with the GitHub Actions code," which is the key requirement for ensuring a Python runtime and its dependencies are available.
As a DevOps engineer, you are trying to leverage an organization secret in a repo. The value received in the workflow is not the same as that set in the secret. What is the most likely reason for the difference?
A. There is a different value specified at the rego level.
B. There is a different value specified at the workflow level.
C. The Codespace secret doesn't match the expected value.
D. The Encrypt Secret setting was not configured for the secret.
E. There is a different value specified at the enterprise level.
Explanation:
This question addresses the hierarchy of secrets in GitHub, which is crucial for troubleshooting. When the same secret name is defined at multiple levels (Enterprise, Organization, Repository), the most specific level takes precedence for a given workflow. If a workflow uses an organization-level secret but receives a different value, the most probable cause is that a secret with the same name is overriding it at a higher priority level.
Correct Option:
A. There is a different value specified at the organization level.
This is the most likely scenario. The secret is being accessed at the repository level, but the value is defined and potentially different at the organization level, where it originates. If the question's intent with "rego level" was "repo level," then the logic reverses: a repository-level secret would override an organization-level one. Given standard hierarchy (Repo > Org > Env > Enterprise), a repo-level secret overrides all others for that repo, making it the most likely cause of a mismatch if a different value is set there.
Incorrect Option:
B. There is a different value specified at the workflow level:
There is no "workflow level" for secret definition. Secrets are defined at the Repository, Environment, Organization, or Enterprise levels, not within individual workflow files.
C. The Codespace secret doesn't match the expected value:
Codespaces have their own separate secret scope. A Codespace secret is used for development in a codespace and would not affect the value received by a workflow running on a GitHub Actions runner.
D. The Encrypt Secret setting was not configured for the secret:
All secrets in GitHub are automatically encrypted at rest. This is not a configurable setting; it is a core security feature. The encryption status cannot cause a value mismatch.
E. There is a different value specified at the enterprise level:
While possible, an enterprise secret would be overridden by an organization or repository secret for a repo within that org. It is less likely to be the direct cause for a single repository's workflow unless no overriding secret exists at the org or repo level.
Reference:
GitHub Docs, "Using secrets in GitHub Actions" explains the precedence order: "If a secret with the same name exists at multiple levels, the secret at the lowest level takes precedence." For a repository workflow, the order is: Repository secret > Organization secret > Enterprise secret.
Which default GitHub environment variable indicates the owner and repository name?
A. REPOSITORY NAME
B. GITHUB REPOSITORY
C. ENV REPOSITORY
D. GITHUB WORKFLOW REPO
Explanation:
This question tests knowledge of the default environment variables automatically set by the GitHub Actions runner. These variables provide context about the workflow run, including metadata about the repository where the workflow is executing. The variable's name follows the standard naming convention of being prefixed with GITHUB_.
Correct Option:
B. GITHUB_REPOSITORY:
This is the correct default environment variable. It contains the repository's full name in the format owner/repo-name. For example, if the workflow runs in the octocat/Hello-World repository, the value of $GITHUB_REPOSITORY (or ${{ github.repository }} in expression syntax) would be exactly octocat/Hello-World.
Incorrect Option:
A. REPOSITORY_NAME:
This is not a default GitHub Actions environment variable. The correct variable for just the repository name (without the owner) is GITHUB_REPOSITORY split on the '/', or accessed via the github.event.repository.name context.
C. ENV_REPOSITORY:
This is not a valid or existing default environment variable in GitHub Actions. The ENV prefix is not used for runner-provided context.
D. GITHUB_WORKFLOW_REPO:
This is a distractor and not a real variable. While descriptive, the officially defined variable is simply GITHUB_REPOSITORY.
Reference:
GitHub Docs, "Default environment variables" lists GITHUB_REPOSITORY and defines it as: "The owner and repository name. For example, octocat/Hello-World." This is the authoritative source confirming the correct variable name.
Which workflow event is used to manually trigger a workflow run?
A. create
B. workflow_dispatch
C. workflow_run
D. status
Explanation:
This question tests knowledge of GitHub Actions events that initiate a workflow run. Workflows are typically triggered automatically by events like push or pull_request. However, there are scenarios where an on-demand, manual trigger from the GitHub UI or API is required. GitHub provides a specific event type for this explicit purpose.
Correct Option:
B. workflow_dispatch:
This is the correct and dedicated event for manually triggering a workflow. It allows you to run a workflow on-demand from the GitHub repository's "Actions" tab, the REST API, or the CLI. You can also define optional inputs to parameterize the manual run, making it a flexible tool for operational tasks.
Incorrect Option:
A. create:
This event triggers a workflow when a Git reference (like a branch or tag) is created. It is an automatic event fired by a git push or similar Git operation, not a manual trigger from the UI.
C. workflow_run:
This event triggers a workflow after another workflow run has completed. It is used to create dependent workflows or post-processing steps (e.g., cleanup, notifications). It reacts to an automated or manual run but is not itself the manual trigger.
D. status:
This is not a valid workflow trigger event. Status checks are a related concept for pull requests, but you cannot define on: status in a workflow file.
Reference:
GitHub Docs, "Events that trigger workflows: workflow_dispatch" states: "You can manually trigger a workflow run using the workflow_dispatch event. You can trigger workflows on GitHub or using the REST API..." This is the definitive source for this functionality.
What are the two ways to pass data between jobs? (Choose two.)
A. Use the copy action with restore parameter to restore the data from the cache
B. Use the copy action to save the data that should be passed in the artifacts folder.
C. Use the copy action with cache parameter to cache the data
D. Use data storage.
E. Use job outputs
F. Use artifact storage.
Explanation:
This question addresses a key challenge in GitHub Actions: jobs run on fresh, isolated runner instances, so in-memory data does not persist. To share data from one job to a downstream job, you must explicitly use a persistence mechanism. GitHub provides two primary, integrated services for this purpose within a workflow run.
Correct Option:
E. Use job outputs:
This method allows you to pass small amounts of textual data, like an ID, version number, or result flag. You set an output in one job step using the ::set-output command (or echo "{name}={value}" >> $GITHUB_OUTPUT), and a dependent job can reference it via the needs context (e.g., ${{ needs.job_name.outputs.output_key }}).
F. Use artifact storage:
This is the method for passing files or directories. You use the actions/upload-artifact action in the producing job and the actions/download-artifact action in the consuming job. Artifacts are stored with the workflow run and are ideal for build outputs, logs, or test results.
Incorrect Option:
A. Use the copy action with restore parameter to restore the data from the cache:
This describes cache restoration, not creation or passing. Caching is for reusing dependencies, not for passing new data generated within a workflow run between jobs.
B. Use the copy action to save the data that should be passed in the artifacts folder:
There is no standard "copy action." The correct process uses the dedicated upload-artifact action. Simply saving files to a folder does not make them accessible to other jobs; they must be uploaded.
C. Use the copy action with cache parameter to cache the data:
Similar to A, this misrepresents caching. The cache is for speeding up workflows by reusing files from previous runs (like node_modules), not for passing unique data generated in the current run between its jobs.
D. Use data storage:
This is a vague, non-specific term and not a named feature or action within GitHub Actions. The platform's specific features are "artifact storage" and "job outputs."
Reference:
GitHub Docs, "Sharing data between jobs" details job outputs. The "Storing workflow data as artifacts" guide covers artifact storage. These are the two documented methods.
Which of the following scenarios requires a developer to explicitly use the GITHUB_TOKEN or github.token secret within a workflow? (Choose two.)
A. passing the GITHUB_TOKEN secret to an action that requires a token as an input
B. making an authenticated GitHub API request
C. checking out source code with the actions/checkout@v3 action
D. assigning non-default permissions to the GITHUB_TOKEN
Explanation:
The GITHUB_TOKEN is a special, automatically created secret for authentication within a workflow run. The question asks when a developer must explicitly reference it (e.g., ${{ secrets.GITHUB_TOKEN }} or as token: ${{ secrets.GITHUB_TOKEN }}). It is automatically used by many first-party actions like actions/checkout, but there are specific cases where you must pass it manually.
Correct Option:
A. Passing the GITHUB_TOKEN secret to an action that requires a token as an input:
This is correct. When using a third-party or custom action that requires a token input to interact with the GitHub API, you must explicitly pass ${{ secrets.GITHUB_TOKEN }} as the value for that input parameter. The action does not receive it automatically.
B. Making an authenticated GitHub API request:
This is correct. When using a script step with curl or a GitHub SDK (like @actions/github) to call the GitHub API directly from within the workflow, you must explicitly provide the GITHUB_TOKEN in the Authorization header. It is not injected into scripts automatically.
Incorrect Option:
C. Checking out source code with the actions/checkout@v3 action:
This is incorrect. The actions/checkout action automatically uses the GITHUB_TOKEN for authentication unless you specify a different token input. Explicitly passing it (with: token: ${{ secrets.GITHUB_TOKEN }}) is optional and redundant. The default behavior does not require the developer to write it.
D. Assigning non-default permissions to the GITHUB_TOKEN:
This is incorrect. You modify the token's permissions by using the permissions key at the workflow or job level (e.g., permissions: contents: read). This configuration controls the token's scope but does not constitute an explicit use of the token secret itself within a step. You are setting rules for it, not passing its value.
Reference:
GitHub Docs, "Automatic token authentication" explains that the token is automatically created and can be accessed via secrets.GITHUB_TOKEN. It clarifies that while the token is available, you must explicitly pass it when "sending the token to an action," which aligns with option A, and that for API requests, you need to use it to authenticate, aligning with option B.
As a developer, which workflow steps should you perform to publish an image to the GitHub Container Registry? (Choose three.)
A. Use the actions/setup-docker action
B. Authenticate to the GitHub Container Registry.
C. Build the container image.
D. Push the image to the GitHub Container Registry
E. Pull the image from the GitHub Container Registry
Explanation:
This question tests the core workflow for publishing a Docker image to the GitHub Container Registry (GHCR) from within a GitHub Actions workflow. The process follows standard container publishing logic: you must authenticate to the target registry, build the image with the correct tag, and then push it. While setup-docker is useful, it is not a mandatory step for the core publishing process if you use Docker's native build and push commands.
Correct Option:
B. Authenticate to the GitHub Container Registry:
Correct. This is an essential first step. You must log in to ghcr.io using the docker login command, typically with the automatic GITHUB_TOKEN as your password (echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin).
C. Build the container image: Correct.
You must create the Docker image using the docker build command, tagging it with the appropriate GHCR namespace (e.g., ghcr.io/owner/repo:tag). This step creates the artifact you intend to publish.
D. Push the image to the GitHub Container Registry:
Correct. After building and tagging, you use the docker push command to upload the image to the authenticated registry (docker push ghcr.io/owner/repo:tag). This completes the publication.
Incorrect Option:
A. Use the actions/setup-docker action:
Incorrect for the core steps. While actions/setup-docker is highly recommended to configure the Docker CLI and set up BuildKit on GitHub-hosted runners, it is a preparatory/setup step, not one of the three fundamental publishing steps. You can technically publish an image using a runner's pre-installed Docker without this action.
E. Pull the image from the GitHub Container Registry:
Incorrect. Pulling is a consumption step, not a publishing step. It is the opposite of the operation the question asks for.
Reference:
GitHub Docs, "Publishing Docker images" outlines the workflow. The core steps shown are: 1) Configure the package’s access permissions (relates to auth), 2) Authenticate to the Container registry, 3) Build and tag the Docker image, and 4) Push the Docker image to GHCR. This directly corresponds to options B, C, and D.
Where should workflow files be stored to be triggered by events in a repository?
A. .github/workflows/
B. .github/actions/
C. Nowhere; they must be attached to an act on in the GitHub user interface
D. anywhere
E. .workflows/
Explanation:
This question tests a fundamental rule for GitHub Actions: the specific directory where the GitHub Actions runner automatically discovers and executes workflow definition files. For a workflow to be triggered by repository events (like push or pull_request), its YAML file must be placed in a precise, well-known location within the repository's codebase to be recognized by the system.
Correct Option:
A. .github/workflows/:
This is the only correct location. Workflow YAML files (.yml or .yaml) must be stored in the .github/workflows/ directory at the root of your repository. Placing a file here automatically registers it with GitHub Actions, and it will be triggered based on the events defined in its on: key.
Incorrect Option:
B. .github/actions/:
This directory is used for storing the source code and metadata (like action.yml) for composite actions and JavaScript actions, not for workflow files. Workflow files placed here will not be triggered.
C. Nowhere;
they must be attached to an action in the GitHub user interface: This is false. While you can create a workflow via the UI, it writes a YAML file to the .github/workflows/ directory in your repository. All workflows are ultimately defined by YAML files stored in the repo.
D. anywhere:
This is incorrect. For automatic triggering, workflow files have a strict required location. Placing a .yml file in an arbitrary directory like /src or /docs will cause GitHub Actions to completely ignore it.
E. .workflows/:
This is a common distractor but not the correct directory name. The official and required directory name is .github/workflows/.
Reference:
GitHub Docs, "Workflow syntax for GitHub Actions" states: "You must store workflow files in the .github/workflows directory of your repository." This is a definitive, non-negotiable requirement for event-triggered workflows.
As a developer, you need to make sure that only actions from trusted sources are available for use in your GitHub Enterprise Cloud organization. Which of the following statements are true? (Choose three.)
A. Specific actions can individually be enabled for the organization, including version information.
B. GitHub-verified actions can be collectively enabled for use in the enterprise.
C. Actions can be restricted to only those available in the enterprise.
D. Actions created by GitHub are automatically enabled and cannot be disabled.
E. Individual third-party actions enabled with a specific tag will prevent updated versions of the action from introducing vulnerabilities.
F. Actions can be published to an internal marketplace
As a developer, your Actions workflow often reuses the same outputs or downloaded dependencies from one run to another. To cache dependencies for a job, you are using the GitHub cache action. Which input parameters are required for this action? (Choose two.)
A. dependency: the name and version of a package to cache or restore
B. key: the key created when saving a cache and the key used to search for a cache
C. cache-hit: the copy action key used with restore parameter to restore the data from the cache
D. path: the file path on the runner to cache or restore
E. ref: the ref name of the branch to access and restore a cache created
F. restore-keys: the copy action key used with cache parameter to cache the data
| Page 1 out of 6 Pages |