Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Created September 7, 2020 08:50
Show Gist options
  • Save vincentorback/6428bc7eb023f4a38006a91234a20b3a to your computer and use it in GitHub Desktop.
Save vincentorback/6428bc7eb023f4a38006a91234a20b3a to your computer and use it in GitHub Desktop.
Github Action - Deploying Bedrock WordPress website
name: Build and deploy
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Create .env file
- name: Create .env file
uses: SpicyPizza/create-envfile@v1
with:
envkey_DB_NAME: ${{ secrets.DB_NAME }}
envkey_DB_USER: ${{ secrets.DB_USER }}
envkey_DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
envkey_DB_PREFIX: ${{ secrets.DB_PREFIX }}
envkey_WP_ENV: 'staging'
envkey_WP_HOME: ${{ secrets.WP_HOME }}
envkey_WP_SITEURL: "${WP_HOME}/wp"
# Install and build with Composer
- name: Validate composer.json and composer.lock
run: composer validate --no-check-all
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Composer dependencies
if: ${{ contains(github.event.head_commit.message, 'purge') || steps.composer-cache.outputs.cache-hit != 'true' }}
run: composer install --prefer-dist --no-progress --no-suggest
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-${{ env.cache-name }}-
${{ runner.os }}-npm-
${{ runner.os }}-
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build:deploy
# Deploy with SSH
- name: Copying files to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }}
source: ".,!.babelrc,!.env.example,!.git*,!./*.json,!*.lock,!*.md,!*.config.js,!./assets,!node_modules"
target: ${{ secrets.REMOTE_FOLDER }}
rm: ${{ contains(github.event.head_commit.message, 'purge') }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment