GitHub Actions for Beginners: Automate Everything

GitHub Actions makes automation easy for developers. Whether you want to lint code, run tests, deploy apps, or just automate boring tasks — GitHub Actions has your back. In this guide, we'll walk through: What GitHub Actions are How workflows work Real-world automation examples How to create your first Action What is GitHub Actions? GitHub Actions is a CI/CD platform built right into GitHub. It lets you create workflows that run automatically based on events — like pushing code, opening pull requests, or on a schedule. Anatomy of a Workflow A typical GitHub Actions workflow lives in your repo at .github/workflows/. Here's what a minimal example looks like: name: Say Hello on: [push] jobs: greet: runs-on: ubuntu-latest steps: - name: Print Hello run: echo "Hello, GitHub Actions!" Key Parts: on: Triggers (e.g., push, pull_request, schedule) jobs: Independent units of work steps: Commands or actions run inside a job Example 1: Run Tests on Every Push name: Run Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Node uses: actions/setup-node@v4 with: node-version: '18' - run: npm install - run: npm test This will automatically run your tests for every commit and PR. Example 2: Auto Deploy to Vercel/Netlify/Firebase Using a custom deploy Action or CLI tool, you can deploy on push to main: on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - run: npx vercel --prod --token=${{ secrets.VERCEL_TOKEN }} Example 3: Auto-format Code with Prettier on: [push] jobs: format: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - run: npm ci - run: npx prettier --write . Add a commit step and you can even push formatting fixes automatically. Using Secrets Keep tokens and credentials safe: Go to your repo > Settings > Secrets and Variables Add secrets like VERCEL_TOKEN, GH_TOKEN, etc. Access them in workflows like: ${{ secrets.YOUR_SECRET_NAME }} Bonus: Use Marketplace Actions The GitHub Marketplace has thousands of reusable actions. Example: uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages folder: build Wrapping Up GitHub Actions is powerful, flexible, and beginner-friendly. Start with: Running tests Formatting code Deploying apps Then explore advanced workflows: matrix builds, reusable workflows, and self-hosted runners. Written by Utkarsh Singh, Full Stack Developer

Apr 11, 2025 - 12:36
 0
GitHub Actions for Beginners: Automate Everything

GitHub Actions makes automation easy for developers. Whether you want to lint code, run tests, deploy apps, or just automate boring tasks — GitHub Actions has your back.

In this guide, we'll walk through:

What GitHub Actions are

How workflows work

Real-world automation examples

How to create your first Action

What is GitHub Actions?
GitHub Actions is a CI/CD platform built right into GitHub. It lets you create workflows that run automatically based on events — like pushing code, opening pull requests, or on a schedule.

Anatomy of a Workflow
A typical GitHub Actions workflow lives in your repo at .github/workflows/. Here's what a minimal example looks like:

name: Say Hello

on: [push]

jobs:
greet:
runs-on: ubuntu-latest
steps:
- name: Print Hello
run: echo "Hello, GitHub Actions!"

Key Parts:
on: Triggers (e.g., push, pull_request, schedule)

jobs: Independent units of work

steps: Commands or actions run inside a job

Example 1: Run Tests on Every Push

name: Run Tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
  - uses: actions/checkout@v3
  - name: Set up Node
    uses: actions/setup-node@v4
    with:
      node-version: '18'
  - run: npm install
  - run: npm test

This will automatically run your tests for every commit and PR.

Example 2: Auto Deploy to
Vercel/Netlify/Firebase
Using a custom deploy Action or CLI tool, you can deploy on push to main:

on:
push:
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npx vercel --prod --token=${{ secrets.VERCEL_TOKEN }}

Example 3: Auto-format Code with Prettier

on: [push]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: npx prettier --write .

Add a commit step and you can even push formatting fixes automatically.

Using Secrets
Keep tokens and credentials safe:

Go to your repo > Settings > Secrets and Variables

Add secrets like VERCEL_TOKEN, GH_TOKEN, etc.

Access them in workflows like: ${{ secrets.YOUR_SECRET_NAME }}

Bonus: Use Marketplace Actions
The GitHub Marketplace has thousands of reusable actions. Example:

  • uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages folder: build

Wrapping Up
GitHub Actions is powerful, flexible, and beginner-friendly. Start with:

Running tests

Formatting code

Deploying apps

Then explore advanced workflows: matrix builds, reusable workflows, and self-hosted runners.

Written by Utkarsh Singh, Full Stack Developer