Free GitHub Actions and Workflow Automation Questions and Answers — Questions and Answers
Question 1: What is GitHub Actions primarily used for?
- Monitoring CPU usage
- Automating code workflows (Correct answer)
- Encrypting repositories
- Designing UI elements
Correct answer: Automating code workflows
GitHub Actions is primarily used for automating various code-related workflows, such as continuous integration (CI), continuous delivery (CD), and other custom tasks. It allows developers to define automated processes that run in response to GitHub events, streamlining development cycles and improving efficiency. This reduces manual effort and speeds up releases.
Question 2: Which file defines a GitHub Actions workflow?
- workflow.json
- main.workflow
- action.yaml
- .github/workflows/*.yml (Correct answer)
Correct answer: .github/workflows/*.yml
GitHub Actions workflows are defined in YAML files located within the `.github/workflows/` directory in your repository. These YAML files specify the events that trigger the workflow, the jobs to be executed, and the steps within each job. This structured format clearly outlines the automated process for your project.
Question 3: What triggers a GitHub Actions workflow?
- Only manual button click
- Predefined cron jobs only
- GitHub events like push or PR (Correct answer)
- Compiling code
Correct answer: GitHub events like push or PR
GitHub Actions workflows are triggered by specific events that occur in your repository, such as a `push` to a branch, the opening or updating of a `pull_request`, or even scheduled `cron` jobs. These event-driven triggers allow for highly flexible and automated CI/CD pipelines. This ensures workflows run exactly when needed.
Question 4: What is a 'job' in GitHub Actions?
- A separate repository
- A GitHub organization
- A unit of steps within a workflow (Correct answer)
- A code editor plugin
Correct answer: A unit of steps within a workflow
In GitHub Actions, a 'job' is a set of steps that execute on the same runner, which is a virtual machine or container. Workflows can contain one or more jobs, which can run sequentially or in parallel. This allows for organized execution of tasks like building, testing, and deploying your code.
Question 5: Which virtual environments can GitHub Actions use?
- Only Linux
- macOS, Windows, and Ubuntu (Correct answer)
- Only macOS
- GitHub-hosted only
Correct answer: macOS, Windows, and Ubuntu
GitHub Actions provides a variety of virtual environments, known as runners, to execute your workflows. These include popular operating systems like Ubuntu (Linux), Windows, and macOS. This flexibility allows you to test and build your applications across different platforms, ensuring compatibility and broad coverage.
Question 6: What is the purpose of a 'step' in a GitHub Action job?
- To store logs
- To manage permissions
- To execute a command or action (Correct answer)
- To switch branches
Correct answer: To execute a command or action
A 'step' in a GitHub Actions job represents a single task that is executed as part of the workflow. Each step can either run a shell command directly or execute a predefined 'action' (a reusable piece of code). This allows for granular control over the workflow's operations, enabling precise automation of tasks.
What is GitHub Actions primarily used for?