How to use GitHub Actions for CI/CD

By

Tagged: Git

A practical deep dive into GitHub Actions: workflows, runners, job graphs, artifacts, caching, security, deployments, and debugging.

GitHub Actions lets you run automation right inside a GitHub repository.

GitHub Actions homepage showing a build, test, and publish workflow

Most people first run into it through a small CI workflow: you push some code, GitHub installs your dependencies, runs the tests, and puts a green checkmark on the commit. That works great until you start adding multiple jobs, deployments, secrets, pull requests from forks, or reusable workflows. At that point, the YAML file is describing machines, data flow, permissions, and trust boundaries, not just a list of commands.

In this guide, we’ll build that mental model first, then put together a complete pipeline that tests, builds, stores an artifact, and deploys it. You can also grab the free Testing, Debugging & CI/CD Handbook to read offline.

The GitHub Actions mental model

Every workflow starts with an event: a push, a pull request, a release, a manual click, a schedule, or any of the other signals GitHub fires. That event kicks off a workflow run, which holds one or more jobs, and each job runs a list of steps in order.

Here’s how those pieces nest:

event
  -> workflow run
      -> job
          -> step
          -> step
      -> job
          -> step

Understanding those boundaries saves a lot of confusion later because state is shared at one level and isolated at the next. Steps inside the same job all run on the same machine, so a file created in step one is right there for step two. Jobs don’t work like that: each job spins up its own runner, which means a file from one job won’t show up in another unless you explicitly pass it across.

You can always look up individual keys in GitHub’s workflow syntax reference whenever you forget one, as long as you keep straight which boundary you’re working inside.

GitHub Actions workflow syntax reference in the GitHub documentation

Where workflows live

Workflow files live inside .github/workflows/ and are written in YAML:

.github/
  workflows/
    ci.yml
    deploy.yml

A single repository can have as many workflows as you need. I like to split CI and deployment into separate files whenever they have different triggers or permissions, because a test workflow shouldn’t get access to a production credential just because a deploy step somewhere else needs it. Also note that the filename doesn’t control when a workflow runs; the on key inside the file does.

Start with the smallest workflow

Here’s about the smallest working workflow you can write:

name: Hello

on: push

jobs:
  hello:
    runs-on: ubuntu-latest
    steps:
      - run: echo 'Hello from GitHub Actions'

Save that as .github/workflows/hello.yml, commit it, and push it to GitHub.

A hello.yml GitHub Actions workflow open in an editor

When the push event fires, GitHub spins up an Ubuntu runner for the hello job, runs the shell command, logs the output, and throws the runner away when it’s done. The hello key is just the job ID, and it only has to be unique within this file. Inside the job we have a single step, though in practice steps either run a shell command with run or call a reusable action with uses.

Choose the right event

The on key can listen to more than one event at a time:

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

With that config, the workflow fires in three cases:

  • someone pushes to main
  • a pull request targets main
  • someone triggers it manually from the Actions tab

Notice a subtle difference in how branch filters behave. On push, the filter matches the branch receiving the commit, while on pull_request it matches the target branch the PR is merging into.

You can narrow triggers further by filtering paths:

on:
  pull_request:
    paths:
      - 'src/**'
      - 'package.json'
      - 'package-lock.json'

That way, a docs-only edit skips the full application workflow. Watch out if you mix path filters with required status checks, though: if branch protection expects a check from a workflow that never ran, the pull request will sit there waiting for it forever. Plan your required checks and path filters together, and check Events that trigger workflows whenever you need the exact rules for a specific event.

Manual inputs

You can also give workflow_dispatch inputs, which comes in handy for maintenance jobs or controlled deployments:

on:
  workflow_dispatch:
    inputs:
      environment:
        description: Where to deploy
        required: true
        type: choice
        options:
          - staging
          - production

Inside the job, you read whatever the user picked through the inputs context:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploying to $DEPLOY_ENVIRONMENT"
        env:
          DEPLOY_ENVIRONMENT: ${{ inputs.environment }}

Notice that I put the expression into an environment variable instead of dropping it straight into the run command. That keeps user-controlled text behind a normal shell variable boundary, because pull request titles, issue bodies, branch names, and manual inputs can all contain shell characters that do things you didn’t ask for.

Scheduled workflows

To run a workflow on a timer, use schedule with standard cron syntax:

on:
  schedule:
    - cron: '0 6 * * *'

That asks GitHub for a run every day at 06:00 UTC, and the workflow file has to live on the default branch for the schedule to fire at all.

Don’t rely on GitHub Actions when you need exact timing. Scheduled runs are best effort, so they can start late during busy periods, and GitHub can disable them completely on inactive public repositories. UTC brings a small timezone catch too: if you want something to run at 07:00 in Rome year-round, daylight saving time shifts the UTC offset twice a year, so you either have to handle both offsets in your workflow or pick a scheduler that understands timezones.

Contexts and expressions

GitHub Actions hands workflow metadata to your YAML through contexts. The ones you’ll reach for most often are:

  • github for the repository, event, commit, branch, and workflow run
  • runner for the current runner
  • job for the current job
  • steps for step outcomes and outputs
  • needs for completed dependency jobs and their outputs
  • matrix for the current matrix combination
  • vars for configuration variables
  • secrets for secrets

You read from a context using GitHub’s expression syntax:

${{ expression }}

Here’s a practical example that limits a job to pushes on main:

jobs:
  deploy:
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - run: echo 'deploying'

GitHub evaluates that if condition before it even assigns the job to a runner. Once the job does start, the shell gets its own set of environment variables as well:

- run: echo "ref=$GITHUB_REF"

Those two forms look close enough to trip people up, but they execute at different stages. This first form is evaluated by GitHub Actions:

if: github.ref == 'refs/heads/main'

This second form is evaluated later by Bash on the runner:

if [ "$GITHUB_REF" = "refs/heads/main" ]; then
  echo 'main branch'
fi

Not every context works in every key or for every event, so keep the contexts guide bookmarked when you’re not sure what’s available where.

Runners and isolation

A runner is the machine that executes your job. GitHub-hosted runners are the easiest place to start because GitHub maintains the Linux, Windows, and macOS images for you. Except for the smaller single-CPU runner, every GitHub-hosted job boots into a fresh virtual machine and gets wiped as soon as the job finishes.

That clean-slate model comes with a few practical consequences:

  • your repository isn’t on the machine until you check it out
  • installed dependencies disappear when the job ends
  • files carry over from one step to the next inside the same job
  • files don’t carry over between separate jobs
  • preinstalled tools can change whenever GitHub updates a runner image

That’s why almost every workflow opens with actions/checkout:

steps:
  - uses: actions/checkout@v7
  - run: ls

Skip that step and the runner has an empty workspace with none of your repository files.

You can also bring your own machine as a self-hosted runner if you want more control, access to private networks, or faster builds. The trade-off is security and upkeep: a persistent machine can hold onto files and background processes across runs, so you never want untrusted pull request code executing on a runner that can reach production systems. I default to GitHub-hosted runners and only reach for self-hosted ones when a workload really needs special hardware, private network access, or a controlled machine image.

Build a reproducible Node.js CI job

Here’s a realistic CI workflow for a Node.js project:

name: CI

on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-node@v7
        with:
          node-version: '24'
          cache: npm

      - run: npm ci
      - run: npm test
      - run: npm run build

actions/setup-node pins the exact Node.js version you want instead of relying on whatever happens to be preinstalled on the runner image. Passing cache: npm speeds things up by caching npm’s package downloads rather than node_modules itself. Then npm ci installs the exact dependency tree from package-lock.json and fails right away if the lockfile and package.json are out of sync, which is great in CI for catching incomplete dependency updates.

Everything the workflow runs should work on your own laptop too. I keep the real test and build logic in package.json scripts or regular project scripts instead of burying 80 lines of shell code inside YAML, so the workflow stays focused on wiring the steps together.

Steps share one workspace

Every step in a job runs in the same workspace directory, so the second step here has no trouble reading report.txt:

steps:
  - run: npm test > report.txt
  - run: wc -l report.txt

Environment variables are a little different, since a shell process can’t modify its parent environment after it exits. When you need to compute a value in one step and use it in the next, write it to the $GITHUB_ENV file that GitHub gives you:

steps:
  - run: echo 'APP_ENV=staging' >> "$GITHUB_ENV"
  - run: echo "$APP_ENV"

That variable shows up in every step after this one, though not in the step that wrote it. If you already know the value ahead of time, skip $GITHUB_ENV and set it with a regular job-level env block instead:

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      NODE_ENV: test

Jobs form a dependency graph

By default, GitHub runs all the jobs in a workflow in parallel, which works well when tasks like linting and testing don’t depend on each other:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: npm ci
      - run: npm run lint

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: npm ci
      - run: npm test

When one job has to wait for others to pass first, wire them up with needs:

jobs:
  build:
    needs: [lint, test]
    runs-on: ubuntu-latest
    steps:
      - run: npm run build

Here, build only kicks off once both lint and test succeed. Keep in mind that build still starts on a fresh runner without the checkout or installed dependencies from the earlier jobs, so in a real workflow you’ll include its own setup steps.

I try to group jobs around independent outcomes rather than individual commands, because spinning up a separate job for a three-second lint command often burns more time booting a runner than it saves.

Pass small values between jobs

When a step needs to hand a value off to something else, write it to $GITHUB_OUTPUT:

steps:
  - id: version
    run: |
      VERSION=$(node -p "require('./package.json').version")
      echo "value=$VERSION" >> "$GITHUB_OUTPUT"

Any later step in the same job can read that output right away:

- run: echo "version=${{ steps.version.outputs.value }}"

To pass that value to another job, expose it as a job output:

jobs:
  package:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.version.outputs.value }}
    steps:
      - uses: actions/checkout@v7
      - id: version
        run: |
          VERSION=$(node -p "require('./package.json').version")
          echo "value=$VERSION" >> "$GITHUB_OUTPUT"

  release:
    needs: package
    runs-on: ubuntu-latest
    steps:
      - run: echo "releasing $RELEASE_VERSION"
        env:
          RELEASE_VERSION: ${{ needs.package.outputs.version }}

Outputs work well for small strings like a version number, an artifact ID, or a generated URL. For files, use an artifact instead.

Artifacts are not caches

Caches and artifacts both store files, but they do completely different jobs. A cache is just there to speed up future runs, so your workflow still has to work cleanly on a cache miss. Package manager downloads and rebuildable compiler data belong in a cache.

An artifact preserves something your workflow produced so another job can download it or you can inspect it after the run finishes. Things that make sense as artifacts include:

  • the application build
  • test reports
  • screenshots from failed browser tests
  • coverage reports
  • logs needed to diagnose a failure

Here’s a build job uploading a static site as an artifact:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
          cache: npm
      - run: npm ci
      - run: npm run build

      - uses: actions/upload-artifact@v7
        with:
          name: site
          path: dist/
          if-no-files-found: error
          retention-days: 7

A separate deploy job can then pull down that exact build:

jobs:
  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v8
        with:
          name: site
          path: dist/
      - run: find dist -maxdepth 2 -type f | head

Because the deploy job grabs the artifact instead of rebuilding the site from scratch, you end up deploying the exact same files you just verified. Also keep in mind what GitHub’s dependency caching guide points out: restored caches count as untrusted input, so never put secrets in one.

Use a matrix for real compatibility requirements

A matrix lets you fan out one job definition into multiple runs with different parameters. For instance, if you maintain a Node.js library that supports both Node 22 and 24, you can test them side by side:

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        node: [22, 24]

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm test

GitHub spins up two independent jobs for that config, and setting fail-fast: false keeps the second one running even if the first fails so you see the full picture. You can cross that with multiple operating systems too:

strategy:
  matrix:
    os: [ubuntu-latest, windows-latest, macos-latest]
    node: [22, 24]

runs-on: ${{ matrix.os }}

That turns a single job into six. Only expand a matrix to combinations you genuinely promise to support, because every extra dimension multiplies build time, runner minutes, and failure noise fast. For an app deployed on Linux, I usually test just the production Node.js version on Linux and save the big matrix for libraries with cross-platform users.

Conditions and failure behavior

By default, a step only runs if the steps before it succeeded. When you need something to run anyway, like uploading diagnostic logs after a test fails, you can attach an if condition to it:

- uses: actions/upload-artifact@v7
  if: failure()
  with:
    name: test-results
    path: test-results/
    if-no-files-found: ignore

The four status check functions you’ll reach for most are:

  • success()
  • failure()
  • cancelled()
  • always()

Be careful with always(). It’s great for cleanup or uploading reports, because you want those even when something broke, but it also runs when a workflow gets cancelled. If a step shouldn’t run after a cancellation, use a more specific condition instead.

If you have a non-critical step that shouldn’t break the whole job when it fails, you can tell Actions to keep going:

- run: npm run optional-report
  continue-on-error: true

Just don’t put continue-on-error on a required check, or your pull request will turn green even though a real requirement failed.

I also put timeouts on commands that can hang so they don’t sit there burning runner minutes:

- run: npm test
  timeout-minutes: 15

Control overlapping runs

Push two commits in a row and GitHub Actions will happily run two copies of the same workflow at once. For regular CI checks, the older run is usually wasted work by the time the new commit lands, so you can cancel it automatically:

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

Putting the workflow name in the concurrency group keeps this rule scoped to one workflow, and adding the ref keeps different branches from cancelling each other.

Deployments are a different story. If you kill a deploy halfway through, you can leave your server or host in an unknown state. Unless your deploy command can be interrupted safely, tell Actions to queue production deploys instead of cancelling them:

concurrency:
  group: production-deploy
  queue: max

With that setting in place, production deploys run one at a time instead of stepping on each other. For every workflow you add, decide upfront whether an older run should be cancelled, skipped, or allowed to finish.

Variables, secrets, and environments

GitHub Actions gives you four places to store values, depending on how sensitive they are and where they’re used:

  • workflow env values, written directly in your YAML file
  • configuration variables, read from the vars context
  • repository secrets, read from the secrets context
  • environment secrets, scoped to a specific deployment environment

If a value is public, like an app URL, keep it as configuration rather than hiding it as a secret:

env:
  APP_URL: https://flaviocopes.com

An API token belongs in secrets:

- run: npm run deploy
  env:
    DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}

You can add repository secrets under Settings → Secrets and variables → Actions. GitHub automatically masks matching secret values in workflow logs, though you shouldn’t rely on that for safety. If a script transforms, encodes, or splits a secret, it can still leak into the output, so never print secrets at all.

When a pull request comes from a fork, GitHub doesn’t pass repository secrets to normal workflows. That keeps untrusted code from reading your credentials.

For production deployments, set up a dedicated environment like production:

jobs:
  deploy:
    environment:
      name: production
      url: https://flaviocopes.com

An environment lets you restrict which branches can deploy, store separate secrets, add a wait timer, or require manual approval before the job starts. Any secrets attached to that environment only unlock once those protection rules pass. You can check the official deployments and environments reference to see which rules are included on your GitHub plan.

Minimize GITHUB_TOKEN permissions

Every job gets a GITHUB_TOKEN automatically so actions can talk to the GitHub API or interact with the repository. Instead of leaning on whatever account-wide default is set, declare the exact permissions your workflow needs at the top:

permissions:
  contents: read

As soon as you declare even one permission, every other permission defaults to none. If a single job needs extra access, override it on that job alone:

jobs:
  release:
    permissions:
      contents: write

That way, the release job can create a release or a tag while your test job stays locked down.

If you deploy using OpenID Connect, you’ll need to grant this permission to the deploy job:

permissions:
  contents: read
  id-token: write

Adding id-token: write lets the job ask GitHub for a signed identity token, and your cloud provider checks that the repository, workflow, branch, or environment matches its trust policy before issuing access. Whenever a cloud provider supports OpenID Connect, I prefer it over storing a long-lived cloud key in GitHub. The workflow gets a short-lived credential for that single run instead of holding a permanent admin token.

Treat actions as dependencies

When you add a line like this to a workflow, you’re running code maintained in another repository:

- uses: owner/action@v3

That action can read your workspace, hit the network, and use any credential available to the job. Before pulling in a third-party action, check who owns it, read through the source code and release history, and verify the inputs and permissions it asks for.

Major version tags are easy to read in tutorials:

- uses: actions/checkout@v7

For a security-sensitive workflow, pin external actions to a full commit SHA you’ve reviewed:

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

Tags can be moved to point at different code later, while a full SHA always refers to the exact commit you checked. Dependabot can keep those GitHub Actions references updated for you.

Pull requests are a security boundary

Most CI workflows end up running code straight out of the repository:

- run: npm ci
- run: npm test

Remember that a pull request can edit package.json, install scripts, tests, build scripts, and your app code. Until someone reviews it, treat all of that as untrusted code.

With the standard pull_request trigger, GitHub restricts permissions on pull requests from forks and hides your repository secrets. pull_request_target works the opposite way: it runs in the context of the base repository and can receive write permissions and secrets. Never use pull_request_target to check out and run untrusted pull request code in a privileged job.

Be careful with event metadata too. Anyone can put shell characters in a pull request title, so if you need it in a script, pass it through an environment variable and quote it rather than interpolating it straight into a shell command. If you’re building any workflow that mixes outside contributions with privileged automation, read GitHub’s secure use reference first.

Reuse the right layer

When you notice duplication creeping into your workflows, reach for the smallest layer that fits. I think of it in three levels:

  1. a project script for commands you also want to run locally
  2. a composite action for a group of steps you repeat across workflows
  3. a reusable workflow for complete jobs and shared policy

Start by putting the logic in a regular script:

{
  "scripts": {
    "check": "npm run lint && npm test && npm run build"
  }
}

Then your workflow stays short and easy to read:

- run: npm run check

When a project script isn’t enough, you have two GitHub Actions options to pick from. A composite action bundles several steps together so they run as a single step inside a job, which works well when multiple workflows repeat the same setup sequence. A reusable workflow operates at the job level and can define its own jobs, runners, permissions, inputs, secrets, and outputs, making it the right fit when several repositories need to share the same deployment policy.

GitHub’s Reusing workflow configurations page has a side-by-side comparison if you’re deciding between them. Either way, don’t rush to abstract a workflow the first time you see three repeated lines. Wait until the steps settle down and the shared boundary is clear.

Run tests with a service container

If your integration tests need PostgreSQL, Redis, or another backing service, GitHub Actions can spin up a service container right alongside a Linux job:

jobs:
  integration:
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:18
        env:
          POSTGRES_PASSWORD: test-password
          POSTGRES_DB: app_test
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v7
      - run: npm ci
      - run: npm run test:integration
        env:
          DATABASE_URL: postgresql://postgres:test-password@localhost:5432/app_test

Because the job runs directly on the runner and maps the container’s port, your tests can connect to PostgreSQL on localhost:5432. GitHub handles starting the container before your steps run and tearing it down when the job finishes. If your job itself also runs inside a container, the networking changes slightly, and the service container guide walks through how that works.

Always use a throwaway test password here, never a credential copied from your production database.

A complete test, build, and deploy workflow

This workflow puts all of those pieces together. It tests against our supported Node.js versions, builds the site once, saves the output as an artifact, and deploys that exact artifact when code lands on main:

name: CI

on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        node: [22, 24]

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-node@v7
        with:
          node-version: ${{ matrix.node }}
          cache: npm

      - run: npm ci
      - run: npm test

  build:
    needs: test
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-node@v7
        with:
          node-version: '24'
          cache: npm

      - run: npm ci
      - run: npm run build

      - uses: actions/upload-artifact@v7
        with:
          name: site-${{ github.sha }}
          path: dist/
          if-no-files-found: error
          retention-days: 7

  deploy:
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    needs: build
    runs-on: ubuntu-latest

    concurrency:
      group: production-deploy
      queue: max

    environment:
      name: production
      url: https://flaviocopes.com

    permissions:
      contents: read

    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-node@v7
        with:
          node-version: '24'
          package-manager-cache: false

      - run: npm ci

      - uses: actions/download-artifact@v8
        with:
          name: site-${{ github.sha }}
          path: dist/

      - run: npm run deploy:ci
        env:
          DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}

Trace a single pull request through this file and you can see why each rule is there. Opening the PR kicks off two test jobs in parallel, one on Node 22 and one on Node 24. If you push another commit while they’re still running, Actions cancels the old run so you’re not waiting on stale results. Runs on main aren’t cancelled, though, so a quick follow-up commit can’t kill a production deploy halfway through.

Once both test jobs pass, the build job starts on a fresh runner, installs from the lockfile, builds the site once, and uploads dist/ as an artifact. Because this is still a pull request, the deploy condition evaluates to false and production stays untouched.

After you merge the PR, the push to main triggers the workflow again. Tests and the build run first, and then the deploy job pauses for whatever protection rules you’ve set on the production environment. Once it’s cleared to go, it downloads the artifact from that same workflow run instead of rebuilding from scratch, and the production concurrency group queues deploys so two of them never run at once.

I also disable the package manager cache in the privileged deploy job so it installs its deploy tool fresh from the lockfile instead of restoring a cache created in a lower-trust context. The deploy token is only exposed to the final command, and if your host supports OIDC, replace that stored token with short-lived authentication instead.

The deploy command itself depends on where you host.

Debug a failing workflow

When a run turns red, always start with the first step that failed, since later errors are usually just fallout from it. Here’s what I check first:

  • a file exists on your machine but was never committed
  • the job is running in the wrong working directory
  • the lockfile is out of sync with package.json
  • the runner is on a different runtime version than your local setup
  • a secret or GITHUB_TOKEN permission is missing
  • a filename differs only by letter case and fails on Linux
  • a command assumes Zsh when the runner defaults to Bash
  • one job expects files that were created on another runner
  • a forked pull request tries to read a secret it can’t access

Small habits make debugging much faster. Give every meaningful step a clear name so you can scan the log at a glance:

- name: Run unit tests
  run: npm test

When you need to check what triggered a run or which ref it’s using, print a few specific, safe context values:

- name: Show run context
  run: echo "event=$EVENT_NAME ref=$REF_NAME sha=$COMMIT_SHA"
  env:
    EVENT_NAME: ${{ github.event_name }}
    REF_NAME: ${{ github.ref_name }}
    COMMIT_SHA: ${{ github.sha }}

Just don’t dump the entire github context into the logs, since it can include values you didn’t mean to expose.

You can also add a readable summary to the run:

- run: echo '## Build completed' >> "$GITHUB_STEP_SUMMARY"

And whenever a shell block starts getting complicated, pull it out into a script in your repo and test it locally. Iterating on a regular script beats pushing YAML commits over and over just to see what breaks.

Keep workflows fast and affordable

The easiest way to speed up CI and cut runner minutes is to skip work you don’t need. Start with these changes:

  • narrow your triggers to the branches and paths that matter
  • cancel outdated CI runs when a newer commit arrives
  • drop matrix combinations you don’t support anymore
  • cache rebuildable dependencies
  • keep artifacts only as long as you need them
  • run independent jobs in parallel
  • combine tiny commands when runner startup takes longer than the work itself

Measure before you assume a cache helps. Uploading and restoring a huge cache can easily take longer than reinstalling the dependency.

Self-hosted runners aren’t automatically cheaper either, once you factor in machine maintenance, patching, isolation, scaling, and the risk of persistent credentials.

How I use GitHub Actions

I treat GitHub Actions as a clean, independent wrapper around the same commands I already run locally. My favorite CI workflow is boring: check out the repo, pick the runtime, install from the lockfile, run the tests, and build the project.

I always keep deployment authority separate from pull request checks. Anything that deploys gets its own trigger condition, environment, concurrency rule, and tightest possible permissions.

On this site, Cloudflare Pages handles normal deployments whenever I push to the repo, so I don’t need GitHub Actions rebuilding and uploading the site on every commit. I do run a scheduled GitHub workflow as a morning backup for future-dated posts, calling a Cloudflare deploy hook just in case. A scheduled Cloudflare Worker handles the punctual publishing since GitHub’s cron schedule can run late, and I wrote up the whole setup in How I auto-publish scheduled posts with a Cloudflare Worker cron.

In general, if a hosting platform’s native Git integration already handles deploys well, I stick with that and only add GitHub Actions for checks or automation the platform doesn’t give me.

When I would not use GitHub Actions

GitHub Actions handles a lot of automation well, but some jobs are a bad fit.

Don’t rely on it for anything that has to start at an exact minute. Scheduled workflows are best effort, so a run can start late. It’s also the wrong tool for a general application server or a long-running background worker, because jobs are temporary and have execution limits.

Think twice before moving high-volume, compute-heavy builds into Actions, too. A specialized CI platform or build service can be faster and easier to control. And I’d stay away from self-hosted runners if your only goal is saving a few minutes. Once you keep a persistent runner around, you’re taking on infrastructure and a security boundary you have to maintain.

If your hosting platform’s repository integration already gives you previews, production deploys, logs, and rollbacks with less code, skip the custom deployment workflow altogether.

GitHub Actions works best when your automation reacts to repository events, lives versioned in the repo, and fits GitHub’s permission model. Before you write the YAML, map out the event, the job graph, the data flow, the permissions each job needs, and how you’ll recover if a run fails.

Want me to talk about your product? You can sponsor this site.

Related posts about git: