To automatically deploy your WordPressify project, you can use GitHub Actions.
.github/workflows/deploy.yml
.name: Deploy WordPressify
on:
push:
branches:
- main
env:
THEME_NAME: ${{ vars.THEME_NAME }} # Define theme name as environment variable
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install dependencies
run: |
npm install
npm run build
- name: Build theme
run: |
npm run export
- name: Set permissions
run: |
sudo chown -R $USER:$USER ./dist
chmod -R 755 ./dist
mkdir -p dist/themes/${{ env.THEME_NAME }}
touch dist/themes/${{ env.THEME_NAME }}/.ftp-deploy-sync-state.json
chmod 666 dist/themes/${{ env.THEME_NAME }}/.ftp-deploy-sync-state.json
- name: Deploy to WordPress
uses: SamKirkland/FTP-Deploy-Action@v4.3.4
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./dist/themes/${{ env.THEME_NAME }}/
server-dir: /public_html/wp-content/themes/${{ env.THEME_NAME }}/
exclude: |
**/.git*
**/.git*/**
**/node_modules/**
**/src/**
gulpfile.js
package.json
package-lock.json
FTP_SERVER
, FTP_USERNAME
, and FTP_PASSWORD
to your GitHub repository's secrets.name: Deploy WordPressify
on:
push:
branches:
- develop
env:
THEME_NAME: ${{ vars.THEME_NAME }}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install dependencies
run: |
npm install
npm run build
- name: Build theme
run: |
npm run export
- name: Set permissions
run: |
sudo chown -R $USER:$USER ./dist
chmod -R 755 ./dist
mkdir -p dist/themes/${{ env.THEME_NAME }}
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
- name: Deploy to WordPress via SSH
run: |
rsync -avz --delete \
-e "ssh -p 22" \
--exclude '.git*' \
--exclude '.git*/**' \
--exclude 'node_modules/**' \
--exclude 'src/**' \
--exclude 'gulpfile.js' \
--exclude 'package.json' \
--exclude 'package-lock.json' \
./dist/themes/${{ env.THEME_NAME }}/ \
${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:/var/www/riangle/wordpress/wp-content/themes/${{ env.THEME_NAME }}/
SSH_HOST
, SSH_USERNAME
, SSH_KNOWN_HOSTS
, and SSH_PRIVATE_KEY
to your GitHub repository's secrets.THEME_NAME
to your GitHub repository's variables. This is the name of your WordPress theme directory..env
file is commited to your repository and contains the value for THEME_NAME
. Do not include any sensitive information.server-dir
path in the FTP-Deploy-Action step. This is the path to your WordPress theme directory on your server.src/plugins
directory, even if it's an empty file. If the directory is empty, the deployment will fail.main
branch.Here's how to set up both the theme name variable and all required secrets for the workflow:
Go to your GitHub repository settings:
Set up the theme name variable:
THEME_NAME
Set up the FTP secrets:
FTP_SERVER
Value: your-domain.com or ftp.your-domain.com
FTP_USERNAME
Value: your-ftp-username
FTP_PASSWORD
Value: your-ftp-password