Dev tools

GitHub Actions: A Practical Guide to CI/CD

GitHub Actions step by step: workflows, jobs and runners, a first CI workflow, caching, matrices, secrets, deployments, security hardening and costs.

By OmniAI Editorial · Nov 23, 2026 · 10 min read

GitHub Actions is GitHub's built-in automation platform. You describe workflows in YAML files inside your repository, and GitHub runs them on virtual machines when something happens: a push, a pull request, a release, a schedule or a manual click. Most teams use it for CI/CD: running tests and linters on every pull request, building artifacts and container images, and deploying to staging and production.

Because it lives next to the code, there's no separate CI server to set up, and thousands of reusable actions cover common tasks from checking out code to deploying to every major cloud. That convenience comes with responsibilities: workflows run with access to your code and secrets, so they need the same care as production code. This GitHub Actions tutorial explains the core concepts, builds a first CI workflow step by step, adds caching, test matrices and deployments, and covers secrets, security hardening, costs and debugging.

GitHub Actions at a Glance

ConceptWhat it is
WorkflowA YAML file in .github/workflows/ describing automation
Event (trigger)What starts a workflow: push, pull_request, schedule, workflow_dispatch, release and many more
JobA set of steps that runs on one runner; jobs run in parallel unless they depend on each other
StepA single shell command (run) or a reusable action (uses)
ActionA reusable unit, such as actions/checkout, published in a repository or the Marketplace
RunnerThe machine that executes a job: GitHub-hosted (Linux, Windows, macOS) or self-hosted
SecretAn encrypted value, such as an API key, available to workflows
EnvironmentA deployment target (for example production) with its own secrets and protection rules
ArtifactFiles saved from a run, such as build outputs or test reports
CostStandard GitHub-hosted runners are free for public repositories; private repositories use the plan's included usage, then pay as you go

What Is GitHub Actions?

What is GitHub Actions in plain terms? It's an event-driven automation service built into GitHub. GitHub added CI/CD capabilities to Actions in 2019, and it has since become one of the most widely used CI/CD systems, especially for open-source projects, which run on standard hosted runners for free.

The model is simple: when an event happens, run these jobs on these machines. A workflow can do almost anything you can script: run tests, build Docker images, publish packages, label issues, update documentation, send notifications or deploy infrastructure.

A GitHub Actions Tutorial: Your First CI Workflow

An orange event circle with an arrow into a workflow box holding two columns of steps, then arrows to two servers
An event triggers a workflow; its jobs run on runners, each as a list of steps.

This step-by-step example adds continuous integration to a Node.js project. The same pattern works for any language.

Step 1: Create the workflow file

In your repository, create .github/workflows/ci.yml:

name: CI

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm run lint
      - run: npm test

Step 2: Understand what it does

  • on runs the workflow for pushes to main and for every pull request.
  • permissions: contents: read limits what the automatic GITHUB_TOKEN can do, a security best practice.
  • runs-on: ubuntu-latest picks a GitHub-hosted Linux runner.
  • actions/checkout fetches your code; actions/setup-node installs Node.js and caches npm downloads.
  • The run steps install dependencies exactly from the lock file, lint and test.

Step 3: Commit and watch it run

Push the file. Open the Actions tab in your repository to see the run, with live logs for every step. On pull requests, the result appears as a check, and you can make it required in the branch protection rules or rulesets, so code can't merge until CI passes.

Step 4: Add a status badge (optional)

The workflow page offers a badge you can paste into your README, showing whether the main branch is passing.

A Fuller GitHub Actions Workflow

As projects grow, a GitHub Actions workflow usually picks up a few more features.

Test matrices

Test several versions or operating systems in parallel:

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        node: [20, 22]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm test

That creates four jobs, one per combination. fail-fast: false lets the others finish even if one fails, so you see every broken combination at once.

Caching

Downloading dependencies on every run wastes minutes. Many setup actions have built-in caching (as with cache: npm above); for anything else, actions/cache stores and restores folders keyed on a hash of your lock file.

Job dependencies and artifacts

Jobs run in parallel by default. Use needs to order them and artifacts to pass files between them:

  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist/

Avoiding duplicate runs

Add a concurrency group so a new push cancels the previous, now outdated run on the same branch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

Deploying With GitHub Actions

For CD, add a deploy job that runs only on the main branch and targets an environment:

  deploy:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: production
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: dist
      - run: ./scripts/deploy.sh

Environments add control:

  • Required reviewers: a person must approve before the job runs.
  • Wait timers and branch restrictions: only certain branches can deploy.
  • Environment secrets: production credentials are only available to jobs targeting production.

The id-token: write permission enables OpenID Connect (OIDC). Instead of storing long-lived cloud keys as secrets, the workflow requests a short-lived token that your cloud provider (AWS, Azure, Google Cloud and others) trusts for this specific repository and branch. It's the recommended way to deploy to the cloud from Actions.

GitHub Actions Secrets

GitHub Actions secrets store sensitive values such as API keys and passwords, encrypted at rest and masked in logs. They can be set at three levels:

LevelScopeTypical use
RepositoryAll workflows in one repositoryTokens for a single project
EnvironmentJobs targeting that environmentProduction and staging credentials
OrganisationSelected repositories in an organisationShared tokens, such as a package registry

Use them in a workflow as ${{ secrets.NAME }}, usually passed into a step's environment. Rules that matter:

  • Prefer OIDC over stored cloud credentials where possible.
  • Secrets aren't passed to workflows triggered by pull requests from forks, which protects public repositories. Be very careful with the pull_request_target trigger, which does run with secrets in the context of the base repository.
  • Never echo secrets or write them to files that become artifacts.
  • Rotate secrets periodically and after any suspected exposure.
  • Keep `GITHUB_TOKEN` permissions minimal with the permissions key, as in the examples above.

Security Hardening

Three action boxes, the first ticked and the middle one outlined in orange, beside a padlock
Pin third-party actions to a full commit, grant the token only what it needs, and keep secrets out of untrusted runs.

Workflows run code with access to your repository and secrets, which makes them a target. A real example: in March 2025, the popular third-party action tj-actions/changed-files was compromised. Attackers repointed its version tags to malicious code that printed CI secrets into workflow logs, exposing secrets in public repositories that used it. The incident was tracked as CVE-2025-30066 and added to CISA's Known Exploited Vulnerabilities catalogue.

The lessons, as a checklist:

  1. Pin third-party actions to a full commit SHA, not a tag such as @v45, because tags can be moved. Add a comment with the version for readability, and let a dependency bot propose updates.
  2. Prefer actions from GitHub and well-known publishers, and review what others do before using them.
  3. Set `permissions` explicitly at the workflow or job level, starting from read-only.
  4. Use OIDC for cloud access instead of long-lived keys.
  5. Protect environments with required reviewers for production.
  6. Treat user-controlled input as untrusted: don't interpolate issue titles, branch names or pull request text directly into run scripts.
  7. Restrict self-hosted runners to private repositories you control; never let public pull requests run on them.

Our guide to software supply chain security covers the wider picture.

Runners and Costs

Runner typeWhat it isCost model
Standard GitHub-hostedFresh Linux, Windows or macOS VM per jobFree in public repositories; private repositories draw on included usage, then are billed per minute
Larger GitHub-hostedMore CPU and memory, GPU optionsBilled, including for public repositories
Self-hostedYour own machines or cloud instancesYou pay for the infrastructure; useful for special hardware or networks

On GitHub Actions cost, minute rates differ by operating system, with macOS and Windows costing more than Linux, so keep most jobs on Linux. Check GitHub's current billing documentation for your plan's included usage and rates.

To cut usage: cache dependencies, cancel outdated runs with concurrency, use path filters so documentation changes don't run full test suites, and in a monorepo, run only the jobs affected by a change. Our comparison of monorepo vs polyrepo covers affected-only builds.

Reusable Workflows and Composite Actions

When several repositories need the same pipeline, don't copy it:

  • Reusable workflows (on: workflow_call) let one workflow call another, centralising a standard CI or deploy pipeline.
  • Composite actions bundle several steps into one action you can uses: anywhere.

Both reduce drift and make security fixes a one-place change.

Debugging Failing Workflows

  • Read the step logs in the Actions tab; expand the failing step.
  • Re-run with debug logging enabled from the run page for more detailed output.
  • Check the event: many surprises come from triggers (pull_request vs push) and branch filters.
  • Validate YAML: indentation errors are the most common cause of workflows not starting.
  • Reproduce locally with community tools such as act, which runs workflows in containers, keeping in mind it isn't identical to GitHub's runners.

GitHub Actions vs Other CI Tools

GitHub ActionsGitLab CI/CDCircleCIJenkins
Where it livesBuilt into GitHubBuilt into GitLabSeparate SaaSSelf-hosted server
ConfigurationYAML per workflow.gitlab-ci.ymlYAMLGroovy pipelines or UI
ReuseMarketplace actions, reusable workflowsTemplates, componentsOrbsPlugins, shared libraries
Best forProjects already on GitHubProjects on GitLabTeams wanting a dedicated CI serviceFull control, on-premises needs

If you're weighing a move away from GitHub entirely, our guide to GitHub alternatives compares the options and their CI.

Common Mistakes

  • Broad default token permissions instead of explicit read-only.
  • Third-party actions pinned to tags rather than commit SHAs.
  • Secrets in logs from debug echo statements.
  • No caching, making every run slow and expensive.
  • Running everything on macOS or Windows when Linux would do.
  • Using `pull_request_target` to run untrusted code with secrets.

FAQ

Is GitHub Actions free?

Standard GitHub-hosted runners are free for public repositories. Private repositories use the plan's included usage, then pay as you go; self-hosted runners don't consume GitHub-hosted minutes.

Where do GitHub Actions workflows live?

In YAML files under .github/workflows/ in your repository.

What is the difference between a workflow, a job and a step?

A workflow is the whole automation file. It contains jobs, each running on its own runner. Each job is a sequence of steps, which are commands or actions.

Can GitHub Actions deploy to AWS, Azure or Google Cloud?

Yes. The recommended approach uses OpenID Connect so the workflow gets short-lived cloud credentials without storing long-lived keys.

Can I run GitHub Actions on my own servers?

Yes, with self-hosted runners. Use them for special hardware or private networks, and avoid exposing them to untrusted public pull requests.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog