codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
📦

Git & GitHub

30 / 63 topics
29Introduction to GitHub Actions30Creating and Managing Workflows31Using Secrets in GitHub Actions32Using Dependabot for Dependency Management33Code Review Best Practices on GitHub34Collaborating with Others on GitHub
Tutorials/Git & GitHub/Creating and Managing Workflows
📦Git & GitHub

Creating and Managing Workflows

Updated 2026-04-20
4 min read

Introduction

In this tutorial, we will explore how to create and manage workflows using GitHub Actions. GitHub Actions is a powerful automation tool that allows you to automate your software development workflow. You can set up continuous integration (CI), continuous deployment (CD), automated testing, and more directly within your GitHub repository.

Prerequisites

Before diving into creating workflows, ensure you have the following:

  • A GitHub account.
  • Basic knowledge of Git and version control systems.
  • Familiarity with YAML syntax, as GitHub Actions uses YAML files to define workflows.

Understanding Workflows

A workflow is a set of instructions for automating tasks. In GitHub Actions, workflows are defined in YAML files located in the .github/workflows directory of your repository. Each workflow file can contain one or more jobs, and each job consists of multiple steps.

Key Concepts

  • Workflow: A configuration file that defines the automation process.
  • Job: A set of steps that execute on a runner machine.
  • Step: An individual task within a job.
  • Event: The trigger for a workflow to run (e.g., push, pull request).
  • Runner: The environment where your jobs are executed.

Creating Your First Workflow

Let's create a simple workflow that runs tests whenever code is pushed to the main branch.

  1. Create the Workflow File

    Navigate to your repository on GitHub and go to the .github/workflows directory. If this directory doesn't exist, you can create it. Then, create a new file named ci.yml.

  2. Define the Workflow

    Open the ci.yml file and add the following content:

    name: CI
    
    on:
      push:
        branches:
          - main
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - uses: actions/checkout@v2
            with:
              fetch-depth: 0
    
          - name: Set up Node.js
            uses: actions/setup-node@v2
            with:
              node-version: '14'
    
          - name: Install dependencies
            run: npm install
    
          - name: Run tests
            run: npm test
    

    Explanation:

    • name: The name of the workflow.
    • on: Specifies the event that triggers the workflow. In this case, it runs on pushes to the main branch.
    • jobs: Contains one or more jobs. Here, we have a single job named build.
    • runs-on: Specifies the type of runner machine to use for the job. ubuntu-latest is a common choice for Node.js projects.
    • steps: A sequence of tasks that are executed in order.
  3. Commit and Push

    Commit the ci.yml file to your repository:

    git add .github/workflows/ci.yml
    git commit -m "Add CI workflow"
    git push origin main
    
  4. View Workflow Runs

    After pushing, navigate to the "Actions" tab in your GitHub repository. You should see the workflow running and you can monitor its progress.

Managing Workflows

Viewing Workflow History

You can view the history of all workflow runs by navigating to the "Actions" tab in your repository. Here, you can see a list of all workflows, their statuses, and details about each run.

Editing Workflows

To edit a workflow, simply navigate to the .github/workflows directory in your repository, open the desired workflow file, make changes, and commit them as usual.

Disabling Workflows

If you need to temporarily disable a workflow, you can rename or delete the workflow file. This will prevent it from running until you restore it.

Advanced Workflow Features

Conditional Steps

You can use conditions to control whether a step runs based on certain criteria. For example:

- name: Run tests only if Node.js version is 14
  run: npm test
  if: github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'ubuntu-latest'

Secrets

GitHub Actions allows you to store sensitive information as secrets, which can be used in your workflows. To use a secret:

  1. Go to your repository settings.

  2. Click on "Secrets" and then "Actions".

  3. Add a new secret (e.g., API_KEY).

  4. Use the secret in your workflow:

    - name: Use API key
      run: echo ${{ secrets.API_KEY }}
    

Matrix Strategy

The matrix strategy allows you to run jobs across multiple configurations, such as different operating systems or Node.js versions:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
        node-version: [12.x, 14.x]

    steps:
      - uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}

      - run: npm install

      - run: npm test

Best Practices

  • Keep Workflows Simple: Start with basic workflows and gradually add complexity as needed.
  • Use Secrets for Sensitive Data: Avoid hardcoding sensitive information like API keys or passwords in your workflow files.
  • Monitor Workflow Runs: Regularly check the "Actions" tab to ensure workflows are running as expected.
  • Optimize Runner Usage: Choose appropriate runners based on your project's requirements to optimize performance and cost.

Conclusion

GitHub Actions provides a robust framework for automating your software development processes. By creating and managing workflows, you can streamline your CI/CD pipeline, improve code quality, and enhance collaboration among team members. With the knowledge gained from this tutorial, you are now equipped to leverage GitHub Actions effectively in your projects.


PreviousIntroduction to GitHub ActionsNext Using Secrets in GitHub Actions

Recommended Gear

Introduction to GitHub ActionsUsing Secrets in GitHub Actions