# Auto Deploy

> Automatically deploy your WordPressify project using GitHub Actions with FTP or SSH.

Source: https://wordpressify.co/auto-deploy

> For the complete documentation index, see [llms.txt](https://wordpressify.co/llms.txt).

# Auto Deploy

Deploy your WordPressify theme automatically with GitHub Actions whenever you push to `main`.

## Setup

<Steps>
  <Step title="Create a GitHub repository">
    Push your WordPressify project to a new GitHub repository.
  </Step>
  <Step title="Add secrets and variables">
    In your repository, go to **Settings > Secrets and variables > Actions**:

    - Under **Variables**, create `THEME_NAME` with your theme directory name (e.g., `my-theme`).
    - Under **Secrets**, add the credentials for your chosen deployment method (see below).
  </Step>
  <Step title="Create the workflow file">
    Create `.github/workflows/deploy.yml` in your repository and paste one of the configurations below.
  </Step>
</Steps>

## Deployment Methods

<Tabs>
  <TabContent title="FTP">
    Add these secrets to your repository: `FTP_SERVER`, `FTP_USERNAME`, `FTP_PASSWORD`.

    ```yaml
    name: Deploy WordPressify
    on:
      push:
        branches:
          - main
    env:
      THEME_NAME: ${{ vars.THEME_NAME }}

    jobs:
      deploy:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - name: Setup Node.js
            uses: actions/setup-node@v4
            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
    ```
  </TabContent>
  <TabContent title="SSH">
    Add these secrets to your repository: `SSH_HOST`, `SSH_USERNAME`, `SSH_KNOWN_HOSTS`, `SSH_PRIVATE_KEY`.

    ```yaml
    name: Deploy WordPressify
    on:
      push:
        branches:
          - main
    env:
      THEME_NAME: ${{ vars.THEME_NAME }}

    jobs:
      deploy:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4

          - name: Setup Node.js
            uses: actions/setup-node@v4
            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/html/wp-content/themes/${{ env.THEME_NAME }}/
    ```
  </TabContent>
</Tabs>

<Callout type="warning">
  Important notes:

  - Set `THEME_NAME` as a **repository variable** (not a secret). This is the name of your WordPress theme directory.
  - Do **not** commit your `.env` file to the repository if it contains sensitive values. Use GitHub secrets and variables instead.
  - Verify the `server-dir` (FTP) or rsync destination path matches your server's WordPress installation directory.
  - Keep at least one file in `src/plugins/` (even an empty `.gitkeep`). An empty directory will cause the build to fail.
</Callout>

## Triggering the Deployment

Once the workflow file is committed and pushed to `main`, every subsequent push to `main` will automatically build and deploy your theme.

<Callout type="info">
Secrets are encrypted and cannot be viewed once saved. You can update a secret at any time by creating a new one with the same name. Never commit credentials to your repository.
</Callout>
