Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»How to Automate CI/CD with GitHub Actions and Streamline Your Workflow

    How to Automate CI/CD with GitHub Actions and Streamline Your Workflow

    April 14, 2025

    CI/CD stands for Continuous Integration and Continuous Delivery. It is a system or set of processes and methodologies that help developers quickly update codebases and deploy applications.

    The Continuous Integration (CI) part of CI/CD means that developers can always integrate or merge their changes into the shared repository without breaking anything. Continuous Delivery, on the other hand, means that the code changes are automatically prepared for release after testing and validation.

    CI/CD primarily involves various stages like building, testing, staging and deployment.

    • Build phase: This is where the code and its dependencies are compiled into a single executable. This is the first phase of Continuous Integration, and is triggered by an event like pushing code to the repository.

    • Test phase: Here, the built artifacts are tested to be sure that the code runs as expected.

    • Staging: Here, the application is run in a production-like environment so as to be sure it is production ready.

    • Deployment: Here, the application is automatically deployed to the end-users.

    In this article, I’m going to explain how GitHub Actions works. I’ll also talk about basic GitHub Actions concepts, and then we’ll use it to build an example CI/CD pipeline.

    What is GitHub Actions?

    GitHub Actions is a service or feature of the GitHub platform that lets developers create their own CI/CD workflows directly on GitHub. It runs jobs on containers hosted by GitHub. The tasks are executed as defined in a YAML file called a workflow. This workflow file has to live on the .github/workflows folder on the repository for it to work.

    Basic GitHub Actions Concepts

    GitHub Actions consists of events, jobs, tasks, runners, workflows, and various other features. Here is a brief explanation of the main concepts:

    Events: An event is basically something that happened. With GitHub, an event can be a push (when you push your code to the repository), a pull request, or even a cron job. These events trigger the CI/CD process.

    Tasks: When you use CI/CD, you want to be able to trigger an activity that should be done automatically. That activity is known as a task or step in GitHub. It could be building your code or testing it or deploying it.

    Each of those tasks has to be defined by commands. A GitHub Actions task usually consists of the name, and the instructions on what to do in the form of a command which starts with - run: or an Action which starts with - uses:.

    steps:
      - name: Checkout code
        uses: actions/checkout@v3
    
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16
    
      - name: Install dependencies
        run: npm install
    
      - name: Run tests
        run: npm test
    
      - name: Build project
        run: npm run build
    
      - name: Deploy
        run: echo "Deploy step goes here"
    

    Runner: A GitHub runner is a server that runs your tasks. It executes what is defined in your GitHub workflow. You can use your own runners or you can use the GitHub runners.

    Job: A job is a collection of steps that are being executed on the same runner. Jobs are defined in a file called the workflow.

    Workflow: The GitHub workflow is a series of jobs defined in a YAML file, that are triggered upon an event. The events do not trigger individual tasks. They can only trigger workflows. Then the tasks in the jobs of the workflow are executed.

    Contexts: These provide a way to access information about workflows, jobs, and environments in GitHub. They are accessed with the expression $${{ <context> }}. Examples include github, env, vars, and secrets. The github context is used to access information about the workflow. For example:

    $${{github.repository}} # should tell the name of the repository
    
    $${{github.actor}}  # should tell the username of user that initially triggered the workflow
    

    Secrets: This is used to store and access sensitive information that’s used by, and is available to, the workflow. Secrets are redacted when printed to the log. An example is $${{secrets.GITHUB_TOKEN}}.

    How to Build a Simple CI/CD Pipeline

    Here, we’re going to build an example workflow to deploy a simple HTML and CSS website to GitHub Pages. Follow the steps below:

    1. Go to the sample code in my repository and fork it from here.

    2. Go to the settings tab in the GitHub repository:

    Settings tab

    1. Go to the Pages settings:

      Pages settings menu

    2. Set the deployment source to the main branch:

      Setting deployment source to main branch in GitHub pages

    3. Go to the General Actions settings and scroll down to the bottom:

    4. Find General Actions setting

      At the bottom, set the Workflow permissions to read and write:

    Set workflow permissions to read and write

    1. In the GitHub repository, you can clone it to your PC or press the fullstop (.) on your keyboard to open GitHub Codespaces, the online version of VS Code.

    2. Go to the sidebar and click on create a new file:

      Creating new file

    3. Create a workflows folder and file. You can call it deploy.yaml.

      Creating a workflows folder and file named deploy.yaml

    4. Copy this code into the file:

    name: Deploy Static HTML and CSS to GitHub Pages
    
    # Trigger the workflow on push to the main branch
    
    on:
      push:
        branches:
          - main
    # Define what operating system the job should run on
    jobs:
      deploy:
        runs-on: ubuntu-latest
        permissions:
          contents: write
    
        steps:
        # Step 1: Checkout the repository
        - name: Checkout Code
          uses: actions/checkout@v4
    
        # Step 2: Check the files that have been checked out
        - name: Display files
          run: ls
    
        # Step 3: Deploy to GitHub Pages
        - name: Deploy
          uses: peaceiris/actions-gh-pages@v4
          with:
            github_token: ${{ secrets.GITHUB_TOKEN }}
            publish_dir: ./ # The HTML and CSS files lie in the root directory, hence that should be the publish directory
    
    1. Commit the code. You should see the job running when you go back to the repo:

    Running job

    When you’re done, go back to the home page of the repository and click on the Deployments section. There, you will see the GitHub Pages link to the deployment:

    GitHub Pages link

    When you’re done, your repository should look like this.

    Conclusion

    In this article, you learned about how the CI/CD process works. We also covered the basic concepts of GitHub Actions. Finally, we created an example CI/CD pipeline with GitHub Actions. If you enjoyed this article, share it with others. You can also reach me on LinkedIn or X.

    Source: freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow to Build a Local RAG App with Ollama and ChromaDB in the R Programming Language
    Next Article For some reason, you can get 43% off this brand-new QHD, 240Hz, HDMI 2.1 gaming monitor with an Amazon coupon

    Related Posts

    Development

    GPT-5 is Coming: Revolutionizing Software Testing

    July 22, 2025
    Development

    Win the Accessibility Game: Combining AI with Human Judgment

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Biometrics – can your fingerprint be ‘copied’ from a normal photo?

    Development

    Is your valentine for real? Six signs you might be falling for an online dating scam

    Development

    One of my favorite gaming PCs is 60% off right now

    News & Updates

    I upgraded my Pixel 9 Pro to Android 16 – here’s what I love (and what’s still missing)

    News & Updates

    Highlights

    Development

    How OpenTelemetry Improved Its Code Integrity for Arm64 by Working With Ampere

    July 16, 2025

    Learn how OpenTelemetry achieved 15% cost savings and improved reliability by adding Arm64 support with…

    CVE-2025-4164 – PHPGurukul Employee Record Management System SQL Injection Vulnerability

    May 1, 2025

    How the Model Context Protocol (MCP) Standardizes, Simplifies, and Future-Proofs AI Agent Tool Calling Across Models for Scalable, Secure, Interoperable Workflows Traditional Approaches to AI–Tool Integration

    May 5, 2025

    Error’d: Teamwork

    May 16, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.