Hosting

Replacing Jenkins with GitHub Actions

By:

Nick Stewart
Nick Stewart

on 8/14/2023

Deploying code bases to staging and production websites can be done a million ways, with the bare minium manually FTP'ing the files over or at the other end Docker boxes that build and deploy. At VIA, historically we have used Jenkins CLI to handle this for us. As time has gone on, we found ourselves wanting to move to something more nimble and that fit more of our current workflow. Enter GitHub Actions.

GitHub Actions

GitHub Actions are basically workflows that are trigged by Git actions and live inside GitHub. For example, you want to build and deploy to production when a branch is merged into main.

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

Actions are written as YAML files and live in the.github folder in the project repo.

Example Scenario and Workflow

For an example scenario, let's say we have a small WordPress website hosted on WP-Engine that needs its theme built as part of the deployment. The workflow will consist of the trigger, setup, build, and deployment.

The trigger is simple, since we want to start the workflow when a branch is merged into main, our production branch.

name: Build and Deploy to WPE PROD
on:
  push:
    branches:
      - master
  workflow_dispatch:
jobs:

Next we want to setup the virtual box and dependencies, such as Node. GitHub Actions allows you to configure things such as PHP version, Python version, etc... In this example, we are using latest Ubuntu box, Node 18x, and installing the root and theme Node dependencies.

Note that npm ci is used instead of npm i, as ci is to be used "in automated environments such as test platforms, continuous integration, and deployment".

  build-and-deploy:
    runs-on: ubuntu-latest
    if: ${{ github.repository_owner == 'viastudio' }}
    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18.x'
          cache: 'npm'
      - name: Install root node dependencies
        run: npm ci --prefer-offline --no-audit
      - name: Install theme node dependencies
        working-directory: ./wp-content/themes/theme
        run: npm ci --prefer-offline --no-audit

Now that everything is setup and installed, the theme can be built

      - run: npm run build

The final step is deployment. With GitHub Actions, there is Marketplace to share actions, which conveniently there is a WP-Engine deployment action. To use it, just specify the action and give it your SSH secret key and WP-Engine environment name.

Note that you can store the SSH secret key in the GitHub organization or repo's Secret Manager so it does not appear in the workflow as plaintext.

      - name: Deploy to WP Engine
        uses: wpengine/github-action-wpe-site-deploy@v3.0
        with:
          WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_KEY }}
          WPE_ENV: enviroment_name

Now you have a completed workflow that will build and deploy to WP-Engine. As an added bonus, this workflow can be extended for pushing feature branches to staging as well.

on:
  push:
    branches:
      - feat/**
      - feature/**
      - hotfix/**
Share to

Related Posts

Website Hosting: It's Not as Complicated as You Think

By: Natalie Miller on 8/22/2017

We're really satisfied by WP Engine's hosting, and if you don't know what that means, here's a basic overview.

Read More »
Creating an AWS DynamoDB table from the command-line

By: Mark Biek on 7/31/2017

One of the great things about the AWS command-line tool is that you can do pretty much any AWS operation with it. For today’s example, we’re going to show you how to easily create a new DynamoDB table.

Read More »