Skip to content

Instantly share code, notes, and snippets.

@mizner
Last active October 5, 2022 17:05
Show Gist options
  • Save mizner/01951cca14dd43e30749b70771ecc8db to your computer and use it in GitHub Desktop.
Save mizner/01951cca14dd43e30749b70771ecc8db to your computer and use it in GitHub Desktop.
Example of Github Action WP Engine Deployment
name: Deploy!
on:
push:
branches:
- production
- release/*
- feature/*
- bug/*
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Echo branch name
run: |
echo $GITHUB_REF
- name: Sync project files
uses: actions/checkout@v2 # https://github.com/marketplace/actions/checkout
- name: Setup SSH agent
uses: webfactory/ssh-agent@v0.4.1 # https://github.com/marketplace/actions/webfactory-ssh-agent
with:
ssh-private-key: ${{ secrets.WPE_PRIVATE_KEY }}
- name: Add host key
run: |
ssh-keyscan -t rsa git.wpengine.com >> ~/.ssh/known_hosts
- name: Setup WP CLI
run: |
cd .. && mkdir wp && cd wp
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
- name: Setup PHP w/ Composer # https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
tools: composer:v2
extensions: zip
- name: Setup Node.js environment # https://github.com/marketplace/actions/setup-node-js-environment
uses: actions/setup-node@v2.4.0
# - name: Setup Yarn # https://github.com/marketplace/actions/setup-php-action
# uses: bahmutov/npm-install@v1
- name: Install Composer Packages
run: |
composer install --no-dev --optimize-autoloader
- name: Install Node Modules
run: |
npm install
npm run build
- name: Filesystem CLeanup
run: |
rm -rf $(cat .clean)
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
find . -name '.vscode' -type d -prune -exec rm -rf '{}' +
- name: Run git commands
run: |
find . -name ".gitignore" -exec rm -f {} \;
git config --global user.email "development@pyxl.com"
git config --global user.name "Pyxl Engineering"
git add .
git commit -m "commit before deploy"
git fetch --unshallow
- name: Push to Prod
if: endsWith(github.ref, 'production')
run: git push -f ${{ secrets.WPE_PROD }}
- name: Push to Staging
if: startsWith(github.ref, 'refs/heads/release')
run: git push -f ${{ secrets.WPE_STAGE }}
- name: Push Bug Branch to Development
if: startsWith(github.ref, 'refs/heads/bug')
run: git push -f ${{ secrets.WPE_DEV }}
- name: Push Feature Branch to Development
if: startsWith(github.ref, 'refs/heads/feature')
run: git push -f ${{ secrets.WPE_DEV }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment