Github Actions in Short

Table of contents

Using GitHub Actions lets you create custom workflows that can be triggered based on several events happening in your GitHub repository, such as pushes, pull requests, or issues. You might then automate tasks such as building, testing, or deploying code.

Core Concepts

  1. Workflows

A workflow is a configurable automated process that consists of one or more jobs. Workflows are defined in YAML files in the.github/workflows directory of your repository. Each workflow can be triggered by specific events such as a push to a branch or the creation of a pull request.

2. Jobs

Jobs are lists of steps that run on the same runner. Every job runs in a new process of a virtual environment. Jobs can be defined for running sequentially or parallelly according to the workflow.

  1. Steps

Steps are single actions of a job. They may execute commands, utilize actions or execute scripts. Steps will be executed in the sequence that they have been defined.

  1. Actions

Actions are reusable blocks of code. These can be grouped together to form workflows. You can build your own action or you can make use of a shared action provided by the community. Shared actions are found in the GitHub Marketplace.

  1. Runners

Runners are the servers running your workflows. GitHub offers hosted runners with lots of different operating systems or you host your own for more control over the environment.

Example

ConceptDescriptionExample
WorkflowA configurable automated process defined in YAML files.on: push triggers a workflow on every push to the repository.
EventSpecifies the activity that triggers the workflow.on: pull_request triggers on pull request creation or updates.
JobA collection of steps executed on the same runner.jobs: build defines a build job in the workflow.
StepIndividual tasks within a job, such as running commands or actions.- name: Install dependencies runs a script to install dependencies.
RunnerThe server that runs the workflow jobs.GitHub-hosted runners (Linux, Windows, macOS) or self-hosted runners.
ActionsReusable commands or code packages for common tasks.actions/checkout@v3 is used to check out the repository code.
SecretsEncrypted environment variables for secure credentials.Add API keys as secrets in the repository settings.
Matrix BuildsAllows running jobs in parallel with different configurations.Run tests on multiple Node.js versions using a matrix strategy.
ArtifactsFiles generated by a workflow that can be downloaded after execution.Build outputs stored using actions/upload-artifact.
EnvironmentDefines deployment targets or groups of secrets specific to an environment.Set up environments like staging or production.
TriggersEvents like push, pull_request, or schedule (cron jobs) that start workflows.on: schedule with a cron expression runs workflows periodically.
Conditional ExecutionSpecify conditions for running steps or jobs using if.if: github.event_name == 'push' runs a step only for push events.
CachingSave dependencies or files between jobs to speed up workflows.Use actions/cache to cache npm modules or Python dependencies.
NotificationsSend alerts or status updates based on workflow success or failure.Configure notifications for workflow failures via email or Slack integrations.