How to Set Up CI/CD on Github

CI/CD pipelines are DevOps practices that simplify the software development process

Handoyo Saputra | September 25, 2023

Ci CD

CI/CD stands for Continuous Integration and Continuous Deployment (or Continuous Delivery). It is a software development practice aimed at automating and streamlining the processes of development, testing, and software delivery.

Continuous Integration involves automatically merging code created by various team members into a shared repository. The goal is to prevent conflicts that may arise from changes made by different team members. By regularly integrating code, the team can identify and resolve integration issues more quickly.

Continuous Deployment or Continuous Delivery involves automating the testing and deployment of software to production environments continuously.

Whenever there is a code change that is integrated, an automated testing process is run to ensure that the software still functions correctly. If the testing is successful, the software can be automatically deployed to the production environment.

By combining CI/CD, development teams can produce software faster, more reliably, and more efficiently. It also helps reduce the risk of human errors and allows small changes to be deployed more frequently, supporting adaptive and responsive software development to meet market and user needs.

Setting Up CI/CD on Github via FTP

Before you begin, make sure you understand basic Git functions such as clone, add, commit, fetch, push, and pull.

  • Create an FTP account on your server.
  • Prepare a repository on Github and clone it to your local computer.
  • Open the repository on your local computer, then create a new file in the .github/workflows/ftp_deploy.yml.
  • Edit the ftp_deploy.yml file as follows, adjust the branch name and files you want to exclude. Here, I am using the main branch.
on:
  push:
    branches:
      - main
name: 🚀 Deploy website on push
jobs:
  web-deploy:
    name: 🧑‍💻 Deploy
    runs-on: ubuntu-latest
    steps:
    - name: 📨 Get latest code
      uses: actions/checkout@v3

    - name: 🗃️ Sync files
      uses: SamKirkland/FTP-Deploy-Action@v4.3.4
      with:
        server: ${{ secrets.FTP_HOST }}
        port: ${{ secrets.FTP_PORT }}
        server-dir: ${{ secrets.FTP_DIR }}
        username: ${{ secrets.FTP_USER }}
        password: ${{ secrets.FTP_PASS }}
        exclude: .env*
          - .git*
          - .git*/**
          - photos/*
          - assets/images/profile/*
  • Open your repository on Github, then click on "Settings" -> "Secrets and Variables" -> "Actions."
  • Click on "New Repository Secret." In the "Name" section, enter FTP_HOST and in the "Value" section, provide the domain or IP address of your server, then save it.
  • Click on "New Repository Secret." In the "Name" section, enter FTP_DIR and in the "Value" section, provide the directory path on your server, then save it.
  • Click on "New Repository Secret." In the "Name" section, enter FTP_PASS and in the "Value" section, provide the password for your FTP server, then save it.
  • Click on "New Repository Secret." In the "Name" section, enter FTP_USER and in the "Value" section, provide the username for your FTP server, then save it.
  • Click on "New Repository Secret." In the "Name" section, enter FTP_PORT and in the "Value" section, provide the FTP port, which is usually 21, then save it.
github secrets and variables
Github secrets and variables
  • Upload the ftp_deploy.yml file from your local computer to the server repository using git push.
  • To check if CI/CD is working correctly, add a new file to your local computer, then perform a git push. The file should appear on your server. If it still doesn't work, check for errors in the Actions menu on Github.
Github actions
Github actions
TagsCoding
TagsTips & Trick
visibility 649

Other Articles

Latest Articles