Parts Of A YAML File

In GitHub Actions, a YAML file is used to define workflows, which are a series of jobs that can be executed when certain events occur, such as pushing code to a repository or creating a pull request. Here is an example YAML file for a simple workflow:

name: My Workflow
on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Build project
        run: |
          npm install
          npm run build

Here’s an explanation of each part of the YAML file:

  1. name: This is the name of the workflow. It can be any string, and is used to identify the workflow in the GitHub Actions dashboard.
  2. on: This section defines the events that will trigger the workflow. In this case, the workflow will be triggered when code is pushed to the main branch.
  3. jobs: This section defines the individual jobs that make up the workflow. In this case, there is only one job called build.
  4. build: This is the name of the job. It can be any string, and is used to identify the job in the GitHub Actions dashboard.
  5. runs-on: This defines the operating system and version that the job will run on. In this case, the job will run on the latest version of Ubuntu.
  6. steps: This section defines the individual steps that make up the job. In this case, there are two steps.
  7. name: This is the name of the step. It can be any string, and is used to identify the step in the GitHub Actions dashboard.
  8. uses: This step uses the actions/checkout action to check out the code from the repository.
  9. run: This step runs a shell command to install the project’s dependencies and build the project.

Note that the YAML file must be placed in a .github/workflows directory in the root of the repository. The file name must end in .yml or .yaml.

Leave a Comment

Your email address will not be published. Required fields are marked *