DEV Community

Harsh Pandhe
Harsh Pandhe

Posted on

GitHub Series: Day 4 โ€“ Automate Like a Boss with GitHub Actions ๐Ÿค–โš™๏ธ

Welcome back, developers! Yesterday, we learned how to branch and merge like Git ninjas. Today, weโ€™re going full automation mode with GitHub Actions โ€” your new best friend for building, testing, and deploying code without lifting a finger (well, almost ๐Ÿ˜Ž).


๐Ÿง  What are GitHub Actions?

Imagine having a robot that checks your code, runs tests, deploys apps, makes you coffee (okay, not that last oneโ€ฆ yet) โ€” all triggered by events like pushing to a branch or opening a pull request.
Thatโ€™s GitHub Actions. It's a powerful CI/CD (Continuous Integration / Continuous Deployment) system built right into GitHub.

Github


๐Ÿ”ฅ Why Use GitHub Actions?

  • โœ… Automate repetitive tasks
  • ๐Ÿงช Run tests every time code is pushed
  • ๐Ÿš€ Deploy apps automatically
  • ๐Ÿ“ฆ Build and publish packages
  • ๐Ÿค Boost collaboration with teams

๐Ÿ› ๏ธ Setting Up Your First GitHub Action

Hereโ€™s how to build a simple GitHub Action that runs tests when code is pushed:

1. Create a workflow file

Inside your repo, make this folder:

.github/workflows/
Enter fullscreen mode Exit fullscreen mode

Then create a file like ci.yml.

2. Add this starter config:

name: Run Python Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: Run tests
        run: pytest
Enter fullscreen mode Exit fullscreen mode

And boom โ€” your tests will now run automatically whenever you push code!


๐Ÿšฆ Common Use Cases

Use Case Trigger Example
Linting on: push Auto-check code style (e.g., with ESLint or Black)
Deployment on: push to main Deploy app to Vercel, Heroku, Netlify, etc.
Notifications on: issues Send Slack or Discord alerts
Testing on: pull_request Run unit tests before merging

๐Ÿงฉ Pro Tip: Use Actions from the Marketplace

Why reinvent the wheel? Head over to GitHub Marketplace and use thousands of pre-built actions.

Examples:

  • actions/checkout โ†’ Pulls repo code
  • actions/setup-node โ†’ Sets up Node.js
  • docker/build-push-action โ†’ Builds & pushes Docker images

Github

๐Ÿ’ก Best Practices

  • โœ… Keep workflows small and focused
  • ๐Ÿ” Use reusable workflows to avoid duplication
  • ๐Ÿงช Run tests before deploying
  • โฑ๏ธ Donโ€™t trigger workflows on every tiny change โ€” be specific with paths and branches

๐Ÿš€ Conclusion

GitHub Actions is your personal DevOps assistant. Whether you're solo-building a portfolio site or working in a team on a massive app, automation will save your time and sanity.

Tomorrow?

Weโ€™ll wrap this series with something close to every developerโ€™s heart โ€” Open Source Contributions ๐Ÿ’–
How to find cool projects, make meaningful PRs, and become a contributor!

Top comments (1)

Collapse
 
nevodavid profile image
Nevo David

pretty cool seeing automation getting this easy tbh - you reckon the hard part is setting it up or actually keeping all the jobs useful once the shine wears off?