Skip to content

How To Use

Ryan Valizan edited this page Sep 15, 2020 · 6 revisions

Guide to Using Script

Introduction

NOTICE: Most arguments still work, Wiki update coming soon after big changes in v1.1.0 release!

  • Live WordPress branch: -b
    wp-git-sync.sh -b $LIVE_BRANCH

Requirements

  • Web server have git capability -- think this is the most important one
    • Git version 2.6+ has been tested
  • A method to store your secrete variables such as
    • username
    • password/token
  • SSH access to execute scripts on WordPress server
    • note: cron can serve as a slower alternative to SSH
  • Some kind of CI pipeline or cron job to hook into after a branch update event triggers an agent to run the script remotely

Capabilities

  • Parameter options for dynamic use
  • Separated functions
  • Is executed through an ssh call to your WordPress web server

Features

  • Check a git repo on a WordPress web server for changes
  • Stashes changes before working on merges
  • Pulls in latest release/master branch from development repository — on Azure DevOps, GitHub, BitBucket, etc.
  • Merges new changes from DevOps into WordPress Live branch
  • Returns WordPress updates and changes using git stash pop
  • Commits the new changes on top of the latest master branch head
  • Pushes WordPress live branch back to the development repository for the team to handle PR to DevOps master.

Essentially, it allows WordPress developers to be more hands off with their shared hosting WordPress server backends, while still fully benefitting from any of the many source control repository and project board sites for git — but while using WordPress at the same time.

Argument Options

  # Server side live branch to use
  -b|--branch) #optional -- default is live

  # Branch to commit and push changes to
  -d|--devbranch) #optional 0-- default is dev

  # Only fetching for changes on the server
  -fe|--fetch) #optional

  # Full url and authentication for script to use for server side git commands
  -fo|--fullorigin) #semi-optional -- if empty gitrepo, token, and tokenuser are required

  # Repo URL string I.E. gibhub.com/user/repo-name | dev.azure.com/org/project/_git/repo
  -g|--gitrepo) #semi-optional -- if empty fullorigin string is required

  # Custom commit message to use if changes are detected
  -m|--message) #optional -- default is Server Side Commit

  # What should the script do when changes are detected.
  # Commit or Stop
  -o|--onchange) #optional -- default is commit

  # Where is the project found on the remote web server
  -pd|--projectdir) #optional -- wordpress is default

  # Branch where releases will be coming in from Azure DevOps
  -sb|--stagebranch) #optional -- default is stage

  # Throw an error if changes are detected but don't commit & still update the web server
  -se|--softerror) #optional -- default is false

  # Auth token to use for remote server talking to Azure DevOps
  -to|--token) #semi-optional -- if empty fullorigin string is required

  # Only stash tracked files before updating
  -tr|--tracked) #optional -- default is false & true is not tested!

  # Auth user to use for remote server talking to Azure DevOps
  -u|--tokenuser) #semi-optional -- if empty fullorigin string is required

Use Scenarios

Update remote server with new release

Shell Script:

bash wp-git-sync.sh \
  -fo $https_repo_with_user_and_token

Azure DevOps Pipeline:

Place the script in your root project directory, then add the task shown below.

YAML Example:
note: This example uses Azure Key store variables

pool:
  name: NameOfAgentPool

steps:
- task: SSH@0
  displayName: pushChanges
  inputs:
    sshEndpoint: 'DEVOPS_SSH_ENDPOINT'
    runOptions: script
    scriptPath: 'wp-git-sync.sh'
    args: '-fo "https://$(DevOpsTokenUser):$(DevOpsToken)@ORGANIZATION-NAME.visualstudio.com/$(System.TeamProject)/_git/$(Build.Repository.Name)"

Classic Editor Example:

PipelineScreen

Console Log:

WordPress-SSH-Git-CI


Fetch changes on remote server

Shell Script:

bash wp-git-sync.sh \
  -fo $https_repo_with_user_and_token
  -fe

Azure DevOps Pipeline:

Place the script in your root project directory, then add the task shown below.

YAML Example:
note: This example uses Azure Key store variables

pool:
  name: NameOfAgentPool

steps:
- task: SSH@0
  displayName: fetchChanges
  inputs:
    sshEndpoint: 'DEVOPS_SSH_ENDPOINT'
    runOptions: script
    scriptPath: 'wp-git-sync.sh'
    args: '-fo "https://$(DevOpsTokenUser):$(DevOpsToken)@ORGANIZATION-NAME.visualstudio.com/$(System.TeamProject)/_git/$(Build.Repository.Name)" \
            -fe'

Classic Editor Example:

PipelineScreen

Console Log:

WordPress-SSH-Git-CI

Clone this wiki locally