CodeBlanks Logo Icon CodeBlanks

Workflow file

Learn the structure of a workflow YAML file.

What is a workflow file?

GitHub Actions workflows are defined using YAML files located in the .github/workflows/ directory of a repository. Each file specifies the workflow name, the event that starts it, and the tasks it performs. These files commonly use the .yml or .yaml extension.

.github/
  workflows/
    tests.yml

The basic structure of a YAML file

YAML is a readable configuration format that uses indentation to create a hierarchy. In a workflow file, name defines the workflow name, on defines the starting event, and jobs defines the tasks to perform. Nested fields use spaces for indentation, which must remain consistent.

name: Test Workflow

on: push

jobs:
  test:
    runs-on: ubuntu-latest

Practice Write your first workflow file

Complete the contents of tests.yml. Set the workflow name to Basic CI, set the triggering event to push, and configure a job named test to run on ubuntu-latest.

Starter code

terminal
# Workflow adını yaz

# Başlangıç olayını yaz

# İş adını ve çalışma ortamını yaz

Sample solution

terminal
name: Basic CI

on: push

jobs:
  test:
    runs-on: ubuntu-latest

Expected output

Basic CI
push
test
ubuntu-latest

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 In which directory should a workflow YAML file be located?

  • .github/workflows/ Correct answer
  • public/workflows/
  • .git/workflows/
  • src/actions/

Explanation: GitHub Actions workflow files are located in the .github/workflows directory at the repository root.

2 Define the workflow name

Question
name: ____
on: push

jobs:
  test:
    runs-on: ubuntu-latest
Answer
name: Test Workflow
on: push

jobs:
  test:
    runs-on: ubuntu-latest

Explanation: The name field defines the displayed name of the workflow.

3 Workflow fields

Term Meaning
name Workflow name
on Triggering event
jobs Tasks to perform
runs-on Execution environment

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow