DEV Community

Yash Sonawane
Yash Sonawane

Posted on

12 1 1 2 1

How to Set Up GitHub Actions for Any Project (Step-by-Step)

Automate your workflow like a pro — no matter what tech stack you use.

GitHub Actions is a powerful CI/CD tool built right into GitHub. Whether you're working with Node.js, Python, Go, Java, Docker, or any other stack, you can automate your builds, tests, deployments, and more — all with simple YAML configurations.

In this guide, I’ll walk you through setting up GitHub Actions for any project, from scratch. Perfect for beginners and a refresher for pros.


🚀 Step 1: Create a .github/workflows Directory

First, in the root of your project, create a directory called .github/workflows.

mkdir -p .github/workflows
Enter fullscreen mode Exit fullscreen mode

This is where all your GitHub Actions YAML files will live.


🛠️ Step 2: Add Your First Workflow File

Create a file like main.yml inside the .github/workflows directory:

# .github/workflows/main.yml
name: CI Pipeline

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

jobs:
  build:
    runs-on: ubuntu-latest

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

      - name: Set up Node.js (or your runtime)
        uses: actions/setup-node@v3
        with:
          node-version: '18'

      - name: Install dependencies
        run: npm install

      - name: Run tests
        run: npm test
Enter fullscreen mode Exit fullscreen mode

💡 Tip: Replace the runtime and commands according to your project (Python, Go, Java, etc.).


📦 Step 3: Customize for Your Stack

Here’s how to tweak it depending on your language:

Python Example:

      - uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      - run: pip install -r requirements.txt
      - run: pytest
Enter fullscreen mode Exit fullscreen mode

Go Example:

      - uses: actions/setup-go@v4
        with:
          go-version: '1.21'
      - run: go test ./...
Enter fullscreen mode Exit fullscreen mode

Docker Example:

      - name: Build Docker Image
        run: docker build -t my-app .
Enter fullscreen mode Exit fullscreen mode

🧩 Mix and match steps to suit multi-language or fullstack projects.


🧪 Step 4: Test the Workflow

Push your changes to GitHub. GitHub Actions will automatically trigger based on your config (e.g., push to main).

Go to the Actions tab in your repo to view the workflow run. Check logs, outputs, and errors in real-time.


📤 Step 5: Deploy (Optional)

You can add deployment steps easily:

Deploy to GitHub Pages:

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./public
Enter fullscreen mode Exit fullscreen mode

Deploy to SSH Server:

      - name: Deploy over SSH
        uses: appleboy/scp-action@master
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          key: ${{ secrets.PRIVATE_KEY }}
          source: "dist"
          target: "/var/www/app"
Enter fullscreen mode Exit fullscreen mode

🧠 Pro Tips

  • Use secrets to store credentials (API keys, SSH keys, etc.).
  • Split large workflows into multiple YAML files.
  • Use matrix strategy to test against multiple versions/environments.
  • Schedule jobs with on: schedule for cron-like tasks.

✅ Final Thoughts

GitHub Actions helps you ship faster with less manual work. Start simple, iterate often, and explore the GitHub Marketplace for thousands of prebuilt actions.

If you found this useful, follow me on Dev.to and let's connect on GitHub. Happy automating! ⚙️✨

Dynatrace image

Observability should elevate – not hinder – the developer experience.

Is your troubleshooting toolset diminishing code output? With Dynatrace, developers stay in flow while debugging – reducing downtime and getting back to building faster.

Explore Observability for Developers

Top comments (2)

Collapse
 
sofianeb profile image
Sofiane B

Well explained! I recently used it in my project to create a CI/CD pipeline. The simplicity of YAML, along with the comprehensive documentation, makes it an ideal tool for anyone looking to automate integration and deployment processes.

Collapse
 
nevodavid profile image
Nevo David

pretty cool seeing these setups broken down - i always mess something up the first try but once it clicks it just sticks

ITRS image

See What Users Experience in The Browser — Anywhere, Anytime

Simulate logins, checkouts, and payments on SaaS, APIs, and internal apps. Catch issues early, baseline web performance, and stay ahead of incidents. Easily record user journeys right from your browser.

Start Free Trial