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

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 4, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 4, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 4, 2025

      Smashing Animations Part 4: Optimising SVGs

      June 4, 2025

      I test AI tools for a living. Here are 3 image generators I actually use and how

      June 4, 2025

      The world’s smallest 65W USB-C charger is my latest travel essential

      June 4, 2025

      This Spotlight alternative for Mac is my secret weapon for AI-powered search

      June 4, 2025

      Tech prophet Mary Meeker just dropped a massive report on AI trends – here’s your TL;DR

      June 4, 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

      Beyond AEM: How Adobe Sensei Powers the Full Enterprise Experience

      June 4, 2025
      Recent

      Beyond AEM: How Adobe Sensei Powers the Full Enterprise Experience

      June 4, 2025

      Simplify Negative Relation Queries with Laravel’s whereDoesntHaveRelation Methods

      June 4, 2025

      Cast Model Properties to a Uri Instance in 12.17

      June 4, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      My Favorite Obsidian Plugins and Their Hidden Settings

      June 4, 2025
      Recent

      My Favorite Obsidian Plugins and Their Hidden Settings

      June 4, 2025

      Rilasciata /e/OS 3.0: Nuova Vita per Android Senza Google, Più Privacy e Controllo per l’Utente

      June 4, 2025

      Rilasciata Oracle Linux 9.6: Scopri le Novità e i Miglioramenti nella Sicurezza e nelle Prestazioni

      June 4, 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

    Security

    HPE StoreOnce Faces Critical CVE-2025-37093 Vulnerability — Urges Immediate Patch Upgrade

    June 4, 2025
    Security

    Google fixes Chrome zero-day with in-the-wild exploit (CVE-2025-5419)

    June 4, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    New Relic’s GitHub Copilot integration, Snyk’s AI Trust Platform, and DataRobot’s syftr framework – SD Times Daily Digest

    Tech & Work

    Community News: Latest PECL Releases (04.01.2025)

    Development

    All About the Filament v4 Beta Release

    Development

    I found a mini PC that can be a powerful Windows alternative – and it’s not a Mac

    News & Updates

    Highlights

    Development

    Are We on the Right Way for Evaluating Large Vision-Language Models? This AI Paper from China Introduces MMStar: An Elite Vision-Dependent Multi-Modal Benchmark

    April 3, 2024

    Large vision language models (LVLMs) showcase powerful visual perception and understanding capabilities. These achievements have…

    Truist Bank Data Allegedly Up for Sale on Dark Web: Employee Info, Transactions Exposed

    June 13, 2024

    Motherhood and Career Balance in Tech: Stories from Perficient LATAM

    May 19, 2025

    CVE-2025-41235 – Spring Cloud Gateway Server Untrusted Proxy Header Manipulation Vulnerability

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

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