← Back to Blog

    How to Set Up a CI/CD Pipeline with GitHub Actions in 2025

    DevOpsGuyMarch 15, 20258 min read

    Looking for expert help with CI/CD?

    DevOpsGuy offers professional CI/CD pipeline setup services for teams across India. We handle GitHub Actions, Jenkins, GitLab CI, and more.

    Continuous Integration and Continuous Deployment (CI/CD) is the practice of automatically building, testing, and deploying your application every time code is pushed to a repository. In 2025, GitHub Actions has become one of the most widely adopted CI/CD platforms globally, and for good reason. It is built directly into GitHub, requires no external infrastructure to get started, and has a rich marketplace of pre-built actions for almost every deployment scenario imaginable.

    Whether you are a solo developer at a startup in Ahmedabad or an engineering team at an enterprise in Mumbai, setting up a GitHub Actions CI/CD pipeline will immediately improve your deployment reliability, reduce the time between writing code and seeing it in production, and eliminate the manual deployment errors that cause incidents. In this guide, we walk you through everything you need to know to set up a production-grade CI/CD pipeline with GitHub Actions in 2025.

    What Is GitHub Actions?

    GitHub Actions is GitHub's native CI/CD and automation platform. It allows you to define automated workflows using YAML files stored in your repository under .github/workflows/. Workflows are triggered by GitHub events, a push to a branch, a pull request being opened, a release being created, a scheduled cron job, or even an external webhook.

    Each workflow consists of one or more jobs. Jobs contain steps, which can be shell commands or reusable actions from the GitHub Marketplace. Jobs run on GitHub-hosted runners (Ubuntu, Windows, or macOS virtual machines) or on self-hosted runners that you manage on your own infrastructure, such as an EC2 instance or a Kubernetes pod.

    GitHub Actions became the CI/CD tool of choice for open-source and private projects alike because it eliminates the need to maintain a separate CI server like Jenkins, is free for public repositories, and deeply integrates with pull request workflows, branch protections, and GitHub Environments for deployment gates.

    Setting Up Your First GitHub Actions Workflow

    Step 1: Create the .github/workflows Directory

    GitHub Actions workflows live in a special directory in your repository root. Create it with:

    mkdir -p .github/workflows

    Any .yml or .yaml file you place in this directory will be automatically detected and registered as a workflow by GitHub. You can have multiple workflow files for different purposes, one for CI (run tests on PRs), one for CD (deploy on merge to main), one for scheduled maintenance tasks, and so on.

    Step 2: Define Your Workflow YAML

    A workflow file has three top-level sections: name (a human-readable label), on (the trigger events), and jobs (the work to perform). Jobs contain steps, which are either run commands or uses references to marketplace actions.

    The runs-on key specifies the runner type. For most CI workloads, ubuntu-latest is the most cost-efficient and fastest choice. For Windows-specific builds or macOS apps, use windows-latest or macos-latest.

    Step 3: Set Up GitHub Secrets

    For deployment workflows, you will need to authenticate with cloud providers or container registries. Never hardcode credentials in your workflow files. Instead, go to your repository's Settings > Secrets and variables > Actions and add secrets like AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or DOCKER_PASSWORD.

    These secrets are encrypted at rest and are never exposed in workflow logs, GitHub automatically redacts any value that matches a stored secret. Reference them in your workflow YAML as ${{ secrets.AWS_ACCESS_KEY_ID }}.

    Sample GitHub Actions CI/CD Workflow

    Below is a realistic production CI/CD workflow for a Node.js application that runs tests on every pull request and deploys to AWS ECS on every push to the main branch. Save this as .github/workflows/ci-cd.yml:

    .github/workflows/ci-cd.yml
    name: CI/CD Pipeline
    
    on:
      push:
        branches: [ main ]
      pull_request:
        branches: [ main ]
    
    env:
      AWS_REGION: ap-south-1
      ECR_REPOSITORY: my-app
      ECS_SERVICE: my-app-service
      ECS_CLUSTER: my-cluster
      CONTAINER_NAME: my-app
    
    jobs:
      test:
        name: Run Tests
        runs-on: ubuntu-latest
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
    
          - name: Set up Node.js
            uses: actions/setup-node@v4
            with:
              node-version: '20'
              cache: 'npm'
    
          - name: Install dependencies
            run: npm ci
    
          - name: Run linter
            run: npm run lint
    
          - name: Run unit tests
            run: npm test -- --coverage
    
          - name: Upload coverage report
            uses: actions/upload-artifact@v4
            with:
              name: coverage-report
              path: coverage/
    
      build-and-deploy:
        name: Build & Deploy to AWS ECS
        needs: test
        runs-on: ubuntu-latest
        if: github.ref == 'refs/heads/main' && github.event_name == 'push'
        environment: production
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
    
          - name: Configure AWS credentials
            uses: aws-actions/configure-aws-credentials@v4
            with:
              aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
              aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
              aws-region: ${{ env.AWS_REGION }}
    
          - name: Login to Amazon ECR
            id: login-ecr
            uses: aws-actions/amazon-ecr-login@v2
    
          - name: Build, tag, and push Docker image to ECR
            id: build-image
            env:
              ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
              IMAGE_TAG: ${{ github.sha }}
            run: |
              docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
              docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
              echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
    
          - name: Download ECS task definition
            run: |
              aws ecs describe-task-definition --task-definition my-app \
                --query taskDefinition > task-definition.json
    
          - name: Update ECS task definition with new image
            id: task-def
            uses: aws-actions/amazon-ecs-render-task-definition@v1
            with:
              task-definition: task-definition.json
              container-name: ${{ env.CONTAINER_NAME }}
              image: ${{ steps.build-image.outputs.image }}
    
          - name: Deploy to Amazon ECS
            uses: aws-actions/amazon-ecs-deploy-task-definition@v1
            with:
              task-definition: ${{ steps.task-def.outputs.task-definition }}
              service: ${{ env.ECS_SERVICE }}
              cluster: ${{ env.ECS_CLUSTER }}
              wait-for-service-stability: true

    This workflow: (1) runs on every push to main and every pull request, (2) executes lint and tests in the test job, (3) only proceeds to deployment if tests pass and the trigger is a push to main, (4) builds a Docker image, pushes it to ECR, and deploys the new task definition to ECS with a stability wait.

    Deploying to AWS with GitHub Actions

    AWS is the most common deployment target for GitHub Actions workflows. The official aws-actions organisation maintains a comprehensive suite of actions for authenticating with AWS, building and pushing Docker images to ECR, and deploying to ECS, EKS, Lambda, and Elastic Beanstalk.

    For security-conscious teams, we strongly recommend using OIDC (OpenID Connect) federation instead of long-lived AWS access keys. With OIDC, your GitHub Actions workflow requests a short-lived token from AWS IAM using GitHub's OIDC provider, no static credentials stored in GitHub Secrets at all. Set this up using the aws-actions/configure-aws-credentials action with the role-to-assume parameter.

    For EKS deployments, the workflow builds and pushes a Docker image to ECR, then uses kubectl or Helm to roll out the new image to the Kubernetes cluster. ArgoCD and Flux GitOps workflows are an even cleaner pattern, the pipeline updates a Helm values file in a Git repository, and ArgoCD automatically applies the change to the cluster.

    If you need help designing and implementing your AWS deployment pipeline, DevOpsGuy's CI/CD pipeline setup service covers GitHub Actions workflows for ECS, EKS, Lambda, and beyond.

    Best Practices for CI/CD Pipelines

    Use OIDC instead of static credentials

    Federated identity with OIDC eliminates long-lived secrets and reduces your attack surface. All major cloud providers support OIDC federation with GitHub Actions.

    Pin action versions to SHA hashes

    Instead of `uses: actions/checkout@v4`, use the full SHA `uses: actions/checkout@abc1234...` to prevent supply chain attacks where a tag is moved to malicious code.

    Separate CI and CD workflows

    Run tests on every pull request, but only deploy on merges to main. Use GitHub Environments with required reviewers for production deployments.

    Cache dependencies aggressively

    Use `actions/cache` for npm, pip, Maven, Gradle, and Docker layer caches to dramatically reduce build times across runs.

    Run security scans in CI

    Integrate Trivy for container image scanning, Snyk or OWASP Dependency-Check for dependency vulnerabilities, and Checkov for IaC security, all before code reaches production.

    Use matrix builds for multi-version testing

    Test against multiple versions of Node.js, Python, or other runtimes in parallel using GitHub Actions matrix strategy to catch compatibility issues early.

    Frequently Asked Questions

    Is GitHub Actions free to use?

    GitHub Actions is free for public repositories with no usage limits. For private repositories, GitHub provides 2,000 minutes per month on the free plan, 3,000 minutes on Team, and 50,000 minutes on Enterprise. Additional minutes are available at a per-minute rate based on the runner OS (Linux is cheapest, Windows and macOS cost more). Self-hosted runners on your own infrastructure are free regardless of plan.

    Can GitHub Actions deploy to AWS, GCP, and Azure?

    Yes. GitHub Actions has first-party or community actions for all major cloud providers. For AWS you use configure-aws-credentials with OIDC or access keys, then deploy to ECS, EKS, Lambda, or Elastic Beanstalk. For GCP, the auth action handles Workload Identity Federation or service account keys, enabling deployment to GKE, Cloud Run, or App Engine. For Azure, the azure/login action supports service principal or OIDC authentication for deploying to AKS, App Service, or Azure Functions.

    How do I secure secrets in GitHub Actions?

    Store all sensitive values (API keys, cloud credentials, database passwords) as encrypted GitHub Secrets under Settings > Secrets and variables > Actions. Never hardcode credentials in workflow YAML files or print them in logs. For production workloads, use OIDC (OpenID Connect) to authenticate to cloud providers without storing long-lived credentials at all, this is the recommended best practice. Additionally, use environment protection rules to require manual approval before deploying to production environments.

    Written by the DevOpsGuy engineering team.Meet the team →

    Ready to Automate Your Deployments?

    Setting up CI/CD pipelines takes time and expertise to get right. DevOpsGuy's CI/CD Pipeline Setup Service handles everything, from workflow design to cloud deployment integration, so your team can focus on building product.

    Shubham Sharma

    Head of Cloud, DevOps & Automation at DevOpsGuy. AWS Solutions Architect, CKA-certified Kubernetes engineer, and Platform Engineering specialist with experience delivering offshore DevOps for startups across the US, UK, and India.