Skip to content

WordPress deployment automation — GitHub Actions and Bitbucket Pipelines

Automating WordPress deployments with GitHub Actions or Bitbucket Pipelines. The pipeline shape that survives plugin updates, database migrations, and a rollback that needs to work on Friday at 5pm.

A WordPress agency moves off “rsync the theme folder from a laptop” and stands up a GitHub Actions workflow. The first version pushes code on every commit to main, including to production, without testing anything. Two weeks later a typo in functions.php takes the site down for 40 minutes. The pipeline shape that actually holds up has gates: tests, lint, build, deploy, smoke test, with a rollback path that someone can trigger from a phone.

What’s happening

A WordPress deployment pipeline has four real stages, not one:

  1. Build: install Composer dependencies, install npm dependencies, compile assets, produce an artifact (a tarball or container image).
  2. Test: run PHPUnit, PHPCS, JS tests. Block the deploy if anything fails.
  3. Deploy: push the artifact to the target server (rsync, SSH+tar, or container registry+orchestrator). Run database migrations. Flush the right caches.
  4. Verify: hit the home page, check key endpoints respond 200, check error log doesn’t have new entries.

Most teams have step 3 and skip 1, 2, 4. That’s how a typo takes the site down — there’s nothing between “commit” and “production runtime.”

GitHub Actions and Bitbucket Pipelines have the same shape — workflow file in .github/workflows/ or bitbucket-pipelines.yml, with stages. The platform-specific bits are secrets management and where the artifact storage lives.

How to verify

For an existing pipeline, look at what it actually does:

cat .github/workflows/deploy.yml  # or bitbucket-pipelines.yml

Walk through each step. If the deploy step is the only step that’s not a comment, the pipeline is “push and pray” — there’s no testing.

For deploy speed, check recent runs:

gh run list --workflow=deploy.yml --limit 10

A deploy that takes 20 minutes for a 50KB code change has a Composer install that isn’t cached or a database export that’s running unnecessarily.

For rollback path, ask: if production is broken right now, what’s the command? If the answer is “redeploy the previous Git tag,” that’s fine. If the answer is “restore from last night’s backup,” the rollback path doesn’t actually exist.

What to do

The GitHub Actions workflow that works for a typical WordPress site.

  1. .github/workflows/deploy.yml:
name: Deploy

on:
  push:
    branches: [main, staging]

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:8.0
        env:
          MYSQL_ROOT_PASSWORD: root
          MYSQL_DATABASE: wp_test
        ports: ['3306:3306']
    steps:
      - uses: actions/checkout@v4

      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.2'
          extensions: mysqli, gd, intl, zip
          tools: composer:v2, wp-cli

      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install Composer dependencies
        run: composer install --no-dev --optimize-autoloader

      - name: Install npm dependencies and build
        run: |
          npm ci
          npm run build

      - name: Run PHPCS
        run: ./vendor/bin/phpcs --standard=phpcs.xml.dist src/

      - name: Set up WordPress test suite
        run: bin/install-wp-tests.sh wp_test root root 127.0.0.1 latest true

      - name: Run PHPUnit
        run: ./vendor/bin/phpunit

      - name: Package artifact
        run: |
          tar --exclude='./node_modules' --exclude='./tests' --exclude='./.git' \
            -czf /tmp/deploy.tar.gz .

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: deploy-tarball
          path: /tmp/deploy.tar.gz
          retention-days: 7

  deploy-staging:
    needs: build-and-test
    if: github.ref == 'refs/heads/staging'
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: deploy-tarball

      - name: Deploy to staging
        env:
          SSH_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
        run: |
          mkdir -p ~/.ssh && echo "$SSH_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
          scp -o StrictHostKeyChecking=no deploy.tar.gz deploy@staging.example.com:/tmp/
          ssh deploy@staging.example.com bash -s <<'EOF'
          set -euo pipefail
          cd /var/www/staging.example.com
          tar xzf /tmp/deploy.tar.gz -C release-$(date +%s)
          ln -sfn release-$(ls -1d release-* | tail -1) current
          wp --path=current core db check
          wp --path=current cache flush
          wp --path=current eval-file current/bin/run-migrations.php
          EOF

      - name: Smoke test
        run: |
          for path in / /wp-login.php /wp-json/wp/v2; do
            status=$(curl -s -o /dev/null -w "%{http_code}" "https://staging.example.com$path")
            [ "$status" = "200" ] || (echo "$path returned $status" && exit 1)
          done

  deploy-production:
    needs: build-and-test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: production
    steps:
      # ... same as staging, targeted at production hosts
  1. The release-symlink pattern (the bash inside ssh deploy@...): every deploy lands in a timestamped directory, then the current symlink atomically points to it. Rollback is ln -sfn release-previous current — instant, no rebuild.

  2. Secrets: GitHub Actions has Environments with required-reviewer gates. Set production to require an approval before deploying. Staging can auto-deploy.

  3. For Bitbucket Pipelines, the equivalent file is bitbucket-pipelines.yml:

image: php:8.2
pipelines:
  branches:
    main:
      - step:
          name: Build, test, deploy
          script:
            - composer install --no-dev
            - vendor/bin/phpunit
            - rsync -avz --delete --exclude='.git' --exclude='node_modules' \
                ./ deploy@example.com:/var/www/example.com/release-$BITBUCKET_BUILD_NUMBER/
            - ssh deploy@example.com "ln -sfn release-$BITBUCKET_BUILD_NUMBER /var/www/example.com/current"
          services:
            - mysql
  1. Rollback workflow is a separate .github/workflows/rollback.yml triggered manually (workflow_dispatch):
on:
  workflow_dispatch:
    inputs:
      target:
        description: 'Environment'
        type: choice
        options: [staging, production]
jobs:
  rollback:
    runs-on: ubuntu-latest
    steps:
      - name: Rollback
        run: |
          ssh deploy@${{ inputs.target }}.example.com \
            "cd /var/www/${{ inputs.target }}.example.com && \
             previous=\$(ls -1d release-* | tail -2 | head -1) && \
             ln -sfn \$previous current && \
             wp --path=current cache flush"
  1. Database migrations: keep them in bin/run-migrations.php (or similar), run after the symlink swap. Migrations are idempotent — they check a wp_options row for migration state and only apply what’s new.

  2. For Composer/Bedrock setups, the artifact is the entire built tree including vendor/ and web/wp/. For non-Composer setups, the artifact is the theme and any agency-owned plugin code.

For the Git branch model behind this, see WordPress Git workflows and staging-to-production promotion.

Stack Harbor’s Enterprise WordPress practice ships these pipelines as part of every onboarding. If a team is deploying by rsync from a laptop and the deploy occasionally takes the site down, we can replace the pipeline.