Update Single Folder on Live or Dev Server Via GitHub Using FTP

Overview

Overview of process
  • Setup credentials for accessing server via FTP on Host Server
  • Setup script to manage conditions for updating server via GitHub workflow
Setting Up FTP Credentials in GitHub
  • Login to GitHub
  • Select repository
  • Select ‘Settings’
  • Select ‘Security/Secrets and variables/actions’
  • Select ‘New repository secret’
  • Enter a unique Secret Username, for example ftp_live_username (All caps)
  • Enter a unique Secret Password, for example ftp_live_password (All caps)
  • Select ‘Add Secret’
Setup script to manage conditions for updating server
  • Select ‘Actions’
  • Select ‘set up a workflow yourself ->
  • Rename the file
    • example: ftp_deploy_live
    • Paste SCRIPT for Live Server or SCRIPT for Dev Server
  • Edit script
    • ‘server: *’
    • ‘username: ${{ secrets.FTP_SECRET_NAME}}’
    • ‘password: ${{ secrets.FTP_SECRET_NAME}}’
    • ‘server-dir: /wp-content/plugins/[plugin_name]
  • This assumes the server directory is to public_html
SCRIPT Dev Server (Single Folder)
# This is a basic workflow to help you get started with Actions
name: Deploy to Dev

# Controls when the workflow will run
on:
  # Triggers the workflow on push to the main "main" branch, this will also work for merging pull requests into "main"
  push:
    tags: [ "dev*" ]


  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "ftp-deploy"
  ftp-deploy:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout latest changes
        uses: actions/checkout@v3


      # Deploy custom plugin files to server via FTP
      - name: Deploy custom plugin changes via ftp
        uses: SamKirkland/FTP-Deploy-Action@v4.3.4
        with:
          server: ftp.sblik.com
          username: ${{ secrets.FTP_DEV_USERNAME }}
          password: ${{ secrets.FTP_DEV_PASSWORD }}         
          server-dir: /wp-content/plugins/*PLUGIN FOLDER NAME*/
          exclude: |
            **/exclude/**
            **/.github/**   
SCRIPT Dev Server (Multiple Folders)
# This is a basic workflow to help you get started with Actions
name: Deploy to Dev

# Controls when the workflow will run
on:
  # Triggers the workflow on push to the main "main" branch, this will also work for merging pull requests into "main"
  push:
    tags: [ "dev*" ]


  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "ftp-deploy"
  ftp-deploy:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout latest changes
        uses: actions/checkout@v3


      # Deploy custom plugin files to server via FTP
      - name: Deploy custom plugin changes via ftp
        uses: SamKirkland/FTP-Deploy-Action@v4.3.4
        with:
          server: ftp.sblik.com
          username: ${{ secrets.FTP_USERNAME }}
          password: ${{ secrets.FTP_PASSWORD }}         
          server-dir: /wp-content/plugins/*PLUGIN FOLDER NAME*/
          local-dir: ./src_custom_plugin/
          exclude: |
            **/exclude/**

      # Deploy PDF template files to server via FTP
      - name: Deploy PDF template changes via ftp
        uses: SamKirkland/FTP-Deploy-Action@v4.3.4
        with:
          server: ftp.sblik.com
          username: ${{ secrets.FTP_USERNAME }}
          password: ${{ secrets.FTP_PASSWORD }}         
          server-dir: /wp-content/uploads/PDF_EXTENDED_TEMPLATES/
          local-dir: ./src_pdf_template/
          exclude: |
            **/exclude/**           
SCRIPT for Live Server (Single Folder)
# This is a basic workflow to help you get started with Actions
name: Deploy to live

# Controls when the workflow will run
on:
  # Triggers the workflow on push to the main "main" branch, this will also work for merging pull requests into "main"
  push:
    branches: [ "main" ]
  # Ignores all branches for pull requests
  pull_request:
    branches-ignore: ["**"]
  # Ignores all branches for pull request target
  pull_request_target:
    branches-ignore: ["**"]


  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "ftp-deploy"
  ftp-deploy:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout latest changes
        uses: actions/checkout@v3


      # Deploy files to server via FTP
      - name: Deploy changes via ftp
        uses: SamKirkland/FTP-Deploy-Action@v4.3.4
        with:
          server: ftp.sblik.com
          username: ${{ secrets.FTP_LIVE_USERNAME }}
          password: ${{ secrets.FTP_LIVE_PASSWORD }}         
          server-dir: /wp-content/plugins/sb-sandbox-plugin/
          exclude: |
            **/exclude/**
            **/.github/**   
    
Live Server (Multiple Folders)
# This is a basic workflow to help you get started with Actions
name: Deploy to live

# Controls when the workflow will run
on:
  # Triggers the workflow on push to the main "main" branch, this will also work for merging pull requests into "main"
  push:
    branches: [ "main" ]
  # Ignores all branches for pull requests
  pull_request:
    branches-ignore: ["**"]
  # Ignores all branches for pull request target
  pull_request_target:
    branches-ignore: ["**"]


  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "ftp-deploy"
  ftp-deploy:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout latest changes
        uses: actions/checkout@v3


      # Deploy custom plugin files to server via FTP
      - name: Deploy custom plugin changes via ftp
        uses: SamKirkland/FTP-Deploy-Action@v4.3.4
        with:
          server: ftp.sblik.com
          username: ${{ secrets.FTP_USERNAME }}
          password: ${{ secrets.FTP_PASSWORD }}         
          server-dir: /wp-content/plugins/*PLUGIN FOLDER NAME*/
          local-dir: ./src_custom_plugin/
          exclude: |
            **/exclude/**

      # Deploy PDF template files to server via FTP
      - name: Deploy PDF template changes via ftp
        uses: SamKirkland/FTP-Deploy-Action@v4.3.4
        with:
          server: ftp.sblik.com
          username: ${{ secrets.FTP_USERNAME }}
          password: ${{ secrets.FTP_PASSWORD }}         
          server-dir: /wp-content/uploads/PDF_EXTENDED_TEMPLATES/
          local-dir: ./src_pdf_template/
          exclude: |
            **/exclude/**       
Set Branch Protection Rules
  • Select ‘Settings’
  • Select ‘Branches’
  • New
  • Name Branch ‘Main’
  • Set as follows:
Setup Code Owner for Review Purposes
  • Select ‘Code’
  • Select ‘.github’ folder
  • Select ‘Add file’
  • Name: ‘CODEOWNERS’
  • Content:
# These owners will be the default owners for everything in the repo. 
# Unless a later match takes precedence, they will be 
# requested for review when someone opens a pull request.
*       @andrenellin
PUSH TO LIVE
  • Branches/New
  • Name
    • AN/name_of_mini_project
  • Check branch is selected
  • Pull request to branch
  • Edit files
  • Stage files
  • Commit
  • Publish Branch
  • Create Pull request
  • Populate fields
  • Create

PUSH TO DEV
Visual Code
  • Pull latest ‘Main’ branch
  • Merge main branch into development branch
  • Save file
  • Stage changes
  • Commit changes to development branch
  • Tags/ Create tag
  • Add tag name
    • dev_{name of tag}
  • Show and Run Commands
    • GIt Push Tags
    • Select ‘Origin’
PHP Storm
  • Checkout your branch
  • Merge main into your branch.
    • If you do not merge main into your branch, and main contains edits that will conflict with your branch, pushing with tags will fail. This step is critical!
  • Make your edits
  • Add a Tag
    • Right Click over a file in your project/Git/New Tag
    • Enter the tag name. Example: dev_css_*
    • Create Tag
  • Push To Origin
    • Right Click over a file in your project/Git/Push
    • Select Push Tags
    • Select ‘All’ from the drop down
    • Select Push
Reviewer Review Pull Request
  • Login to HubSpot
  • Select repo
  • Select Pull requests
  • Sepect Pull reqeust
  • Add review
  • Merge to main