What Is GitHub Actions?
GitHub Actions is a built-in automation platform within GitHub that lets you create workflows triggered by events in your repository — like a push to main, a pull request, or a scheduled cron job. It's widely used for Continuous Integration and Continuous Deployment (CI/CD), automating testing, building, and deploying code.
This guide walks you through setting up a basic CI/CD pipeline for a Node.js application, but the concepts apply to any stack.
Prerequisites
- A GitHub repository with your project code
- Basic familiarity with Git and terminal commands
- A deployment target (e.g., a cloud server, Vercel, or AWS)
Step 1: Create the Workflow Directory
GitHub Actions workflows are defined in YAML files inside a special folder at the root of your repo:
.github/
workflows/
ci.yml
Create this folder structure in your project. You can have multiple workflow files — one for CI, one for deployment, etc.
Step 2: Write Your First Workflow File
Here's a minimal CI workflow that runs tests on every push and pull request:
name: CI Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
Breaking Down the Key Parts
- on: Defines the trigger events. Here it fires on pushes and PRs to main.
- jobs: Each job runs in an isolated environment (a GitHub-hosted runner).
- runs-on: Specifies the runner OS — ubuntu-latest is most common.
- steps: Sequential commands and actions to execute.
- uses: References a pre-built Action from the GitHub Marketplace.
Step 3: Add a Deployment Job
Once tests pass, you can chain a deployment step. This example deploys to a server via SSH after a successful test run:
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to server
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/myapp
git pull origin main
npm ci
pm2 restart myapp
Notice the use of ${{ secrets.* }}. Never hardcode credentials in workflow files. Store sensitive values in Settings → Secrets and variables → Actions in your GitHub repo.
Step 4: Commit and Push
Once your workflow file is committed and pushed to main, GitHub automatically detects it. Navigate to the Actions tab in your repository to see your pipeline run in real time, view logs for each step, and debug failures.
Step 5: Iterate and Expand
A basic pipeline is just the start. Consider adding:
- Linting: Add an ESLint or Prettier check step before tests.
- Code coverage: Publish test coverage reports as PR comments.
- Environment-specific deployments: Deploy to staging on feature branches, production on main.
- Caching: Use
actions/cacheto cachenode_modulesand speed up runs. - Notifications: Send Slack alerts on deployment success or failure.
Tips for a Reliable Pipeline
- Keep workflows fast — slow pipelines kill developer momentum.
- Use specific action versions (e.g.,
@v4) rather than@latestto avoid unexpected breakage. - Fail fast: structure jobs so obvious failures (like linting) run before slow ones (like tests).
- Review the GitHub Actions usage limits on your plan — free minutes are generous but not unlimited.
Final Thoughts
GitHub Actions is one of the most accessible CI/CD tools available today, especially if you're already hosting code on GitHub. A well-configured pipeline catches bugs earlier, automates repetitive deployment steps, and gives your whole team confidence to ship faster.