Skip to Content

GitHub Actions: What File Defines the Steps to Execute in GitHub Action?

Learn which file is used to define the steps executed in a GitHub Action workflow. Prepare for the GitHub Actions certification exam with this detailed explanation.

Table of Contents

Question

In which file do you define the steps to execute in your GitHub Action?

A. In a workflow.yml (YAML) file
B. In the Dockerfile
C. In the package.json file

Answer

A. In a workflow.yml (YAML) file

Explanation

The workflow.yml file, under the .github/workflows directory, contains the steps of your action.

In GitHub Actions, the steps to execute in a workflow are defined in a YAML file with a .yml extension, typically named workflow.yml. This file is placed in the .github/workflows directory of your repository.

The workflow.yml file contains the configuration for your GitHub Actions workflow, including:

  1. The name of the workflow
  2. The events that trigger the workflow (e.g., push, pull request, schedule)
  3. The jobs that make up the workflow
  4. The steps within each job, which define the actions to be executed

Each step can run a command, execute a script, or use a pre-built action from the GitHub Actions marketplace. The steps are executed sequentially within a job, and jobs can be run in parallel or sequentially based on your workflow requirements.

Here’s a simple example of a workflow.yml file:

name: My Workflow
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run a script
run: echo "Hello, GitHub Actions!"

In this example, the workflow is triggered on a push event, runs on an Ubuntu environment, and consists of two steps: checking out the repository code and running a simple echo command.

By defining your workflow steps in the workflow.yml file, GitHub Actions can automatically execute the specified actions whenever the designated event occurs, streamlining your development and deployment processes.

GitHub Actions certification exam assessment practice question and answer (Q&A) dump including multiple choice questions (MCQ) and objective type questions, with detail explanation and reference available free, helpful to pass the GitHub Actions exam and earn GitHub Actions certification.