Back to blog

Github Actions

3 min
Por Juliano Alves

GitHub Actions is a powerful continuous integration and continuous delivery (CI/CD) platform that allows you to automate your software development workflows directly in your GitHub repository.

What are GitHub Actions?#

GitHub Actions help you automate tasks within your software development life cycle. They are event-driven, meaning that you can run a series of commands after a specified event has occurred. For example, every time someone creates a pull request for your repository, you can automatically run a series of commands to build and test your code.

name: CI

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout 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

Key Components#

Here are the main components that make up GitHub Actions:

  • Workflows: The automated process that will run one or more jobs
  • Events: Specific activities that trigger a workflow to run
  • Jobs: A set of steps that execute on the same runner
  • Steps: Individual tasks that can run commands or actions
  • Actions: Standalone commands that can be combined into steps
  • Runners: Servers that run your workflows

Each of these components works together to create automation pipelines. Let's explore each one in detail.

Events#

Events are specific activities in your repository that can trigger a workflow run. Some common events include:

  • Push
  • Pull request
  • Issue creation
  • Scheduled events (cron)
  • Manual triggers
  • Repository dispatch

Here's an example of how to configure different events in your workflow:

Jobs#

Jobs are a set of steps that execute on the same runner. By default, a workflow with multiple jobs will run those jobs in parallel. You can also configure dependencies between jobs so they run sequentially.

Example of jobs in a workflow:

1. Workflows#

Workflows are automated procedures that you add to your repository. They are defined in YAML files stored in the .github/workflows directory of your repository.