Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

GitHub Actions: Actions vs Jobs vs Steps

1. Introduction

In GitHub Actions, workflows are made up of various components, namely Actions, Jobs, and Steps. Understanding the differences between these components is essential for creating effective CI/CD pipelines.

2. Definitions

Actions

Actions are reusable units of code that can be shared and executed within workflows. They can be created by developers or can be found in the GitHub Marketplace.

Jobs

Jobs are a set of steps that execute on the same runner. They are defined in a workflow and can run sequentially or in parallel.

Steps

Steps are individual tasks that can run commands or actions. Each step runs in the context of a job and can reference outputs from previous steps.

3. Detailed Explanation

To better understand how Actions, Jobs, and Steps work together, let's review their structure in a GitHub Actions workflow.

name: CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v2
      - 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
    
Note: The example above defines a CI workflow with one job called "build", which contains multiple steps.

4. Best Practices

When working with Actions, Jobs, and Steps, consider the following best practices:

  • Use reusable Actions whenever possible to reduce redundancy.
  • Organize Jobs to run in parallel when dependencies allow.
  • Clearly name Steps to improve readability and maintainability.

5. FAQ

What is the difference between an Action and a Step?

An Action is a reusable piece of code that can be used across multiple workflows, whereas a Step is a single task that is executed within a Job.

Can Jobs run in parallel?

Yes, Jobs can be defined to run in parallel unless dependencies are specified that require them to run sequentially.

How can I share Actions?

You can share Actions by publishing them to the GitHub Marketplace or by using them directly from your repository.