← blog

deploy_wordpress

Deploying code with GitHub Actions and version control

At EpicDevs, any junior can deploy a site. You explain two or three things and it just works: which branch to use, what to build, where each thing goes, whether to dev, staging or production. You push, and a few minutes later the theme shows up on the server.

What most people don’t know is how it works. Those of us who know what’s inside are few. For everyone else, it’s like magic. And for better or worse, the magic works.

Plenty of tools that make our lives easier work the same way. Laravel’s docs say it plainly when they explain facades (opens in a new tab): “It’s perfectly fine if you don’t totally understand how facades work”. You write Cache::get() and it works. Knowing little, you control a lot. The trouble starts the day you need to change something underneath.

For us, that day came one early morning in November, when I wrote this to Claude: “We can’t know who uses our v1 tag to test it, but you’ve got access to a bunch of our repos where we use it. Could we pull some real use cases and make sure nothing breaks?”

nt-matter is our GitHub organization. The v1 tag is the version of wp-deployment-action (opens in a new tab) that almost all of EpicDevs uses: the GitHub Action behind that magic. I was about to change it, and I had no idea what could break.

How did we do this before?

In the post about 20 years of WordPress I covered, at a high level, how code got to production. This is the hands-on version.

At first we had few clients on Git. We used GitLab, and I had a .sh on my machine that ran rsync to the servers I had access to. That’s if I was lucky. If not, it was all SFTP, old school.

Meanwhile, what we shipped kept getting more complex. A theme stopped being a folder of just PHP and CSS you edited and uploaded (that was also the end of the functions_back_18-12-26.php era). Our first base theme, built on Underscores (opens in a new tab), compiled Sass (opens in a new tab) with gulp (opens in a new tab), ran the JavaScript through Babel and pulled third-party libraries from npm. Then came TypeScript (opens in a new tab) and, with the base block theme, @wordpress/scripts (opens in a new tab), which according to its docs is “inspired by react-scripts”: a recommended configuration that comes built in, so you don’t have to set it up yourself. In other words, a little more magic.

Every tool solved a real problem, and every one added a step between what you wrote and what reached the server. Deploying wasn’t copying files anymore: you had to install, build and only then upload. Now there were source files and the compiled theme, CSS and JS versions cached in wp_enqueue_scripts(), bundled third-party libraries, SVG icons or fonts, and so on. At first, my machine was enough. But when the team and the projects started to grow, we needed to share code and stop the deploy from depending on anyone’s computer. We needed a system. That’s when we moved to GitHub and I got into CI/CD.

The theme’s first workflow was basically my .sh moved into a YAML file: install, build, and an rsync with a hand-written list of excludes.

- name: 🔁 Syncing files
  run: |
    rsync -chav --delete \
      -e 'ssh -i ./.deployment_key -o StrictHostKeyChecking=no' \
      --exclude '.*' --exclude 'node_modules' --exclude 'src' \
      ./ ${{ env.user }}:${{ env.dest }}

Why I needed a custom-made action

We started out with WP Engine’s Git integration, but I wasn’t sold on it. It was convoluted, though I honestly don’t even remember why anymore. And we mostly just wanted to deploy a theme.

Looking for alternatives, I found WP Engine’s action (opens in a new tab) on GitHub and we started using it. But the rsync flags were fixed, and our workflow had its quirks. It was better to keep my own integration and fit it to how we worked.

In 2021 I finally built wpe-deployment-action (opens in a new tab), based on WP Engine’s. I made it in a day, with the basics, very on brand for me, only with what we needed: a branch per environment, cache clearing, a permalink flush and a .deployignore to decide what not to upload (nobody wants the package.json, the phpcs.xml, the .editorconfig or the uncompiled files).

The important part was on the other end. We already had several templates for each case, and each one came with its sample workflow. Anyone starting one of our themes already had the deploy set up:

- name: 🔁 Deploying to WP Engine
  uses: IlanVivanco/wpe-deployment-action@main
  env:
    WPE_SSH_KEY: ${{ secrets.WPE_SSH_KEY }}
    PRD_BRANCH: main
    PRD_ENV: prodinstall
    STG_BRANCH: staging
    STG_ENV: stageinstall

That’s how the magic from the start began: you pick the branch, you push, and the code lands in the right environment.

Anything that wasn’t WP Engine went through another action (opens in a new tab), over FTP. Plain, no SSL. Yes, I know. But the vast majority of our clients were on WP Engine, so it covered almost everything.

A name I outgrew

In 2024 the fight between Matt Mullenweg and WP Engine broke out, first with “WP Engine is not WordPress (opens in a new tab)” and a few days later with WP Engine being blocked from WordPress.org resources (opens in a new tab). Lots of clients started asking us what to do, and we’d started working with Pressable (opens in a new tab) just a few months earlier: comparable in features and quality, but more affordable. WP Engine had also been pretty aggressive with upgrades.

An action called “wpe” didn’t cut it for me anymore. So, soon after, wp-deployment-action (opens in a new tab) was born, with Pressable and WP Engine, and I archived the old one with a sign pointing to the new one. This time, each workflow could change the rsync flags.

That left 10% out: clients with SSH on other hosts, like Kinsta, Hostinger or Pantheon. I didn’t want one workflow per server, so I made a first attempt on a separate branch, where it was all a matter of passing the right parameters. It was more verbose, but it worked. That branch never got merged, and v1 went untouched for a good while. But we did use it from that branch on the odd project.

It worked because nobody touched it

All those years, the action didn’t have a single test. And it didn’t fail, because we always used it the same way: same hosts, same flags, same script after uploading. Nobody touched anything, and nothing changed on the server. Simple and effective.

As a tool, though, it was pretty rudimentary. It served one way of working, and that way didn’t change for years. It served us doing what it did, limited and well.

Meanwhile, the tag kept getting copied. Every new theme came with its workflow, every workflow pointed to @v1, and when we counted, there were almost a hundred workflows across 27 repos. Some still point to the archived action from 2021.

Recently, the case that didn’t fit landed on my desk: a nonprofit’s site, on its own server, that needed automatic deploys. It was the 10% that had been left on a branch. Adding it meant opening the box, and opening it without tests was like jumping into the pool without knowing if there was any water. But with a plan, a method and AI, we can make all of it a bit easier.

Opening the box

That’s where the line from the beginning comes back. A public tag is a promise: whoever writes @v1 in a workflow expects it to do tomorrow what it does today. The action is on the GitHub Marketplace (opens in a new tab), so there’s no way to know who uses it out there. But I could find out how we used it.

With the GitHub CLI (opens in a new tab) you can search code across a whole organization. Claude found every workflow that used the action and read them all, one by one. It was the job nobody was going to do by hand: opening a hundred similar files, looking for the difference that matters.

What came out was an X-ray of how we’ve worked all these years. Everyone used the action the same way, with three variations of flags, and almost all of them ran a script after uploading. And something showed up that nobody had written down: those scripts assumed they started in a specific folder on the server. If the new version ran them from somewhere else, they’d fail without anyone understanding why. That’s the kind of detail that lives inside the magic, and that nobody explains in those two or three things on day one.

A typical step looked like this:

- uses: IlanVivanco/wp-deployment-action@v1
  with:
    SSH_PRIVATE_KEY: ${{ secrets.WPE_SSH_KEY }}
    SERVER_TYPE: wpengine
    SERVER_ID: my-env
    REMOTE_PATH: wp-content/themes/my-theme
    FLAGS: -azvrhi --inplace --delete-excluded --exclude-from=.deployignore
    SCRIPT: bin/post-deploy.sh
    PHP_LINT: TRUE
    CACHE_CLEAR: TRUE

With that X-ray we built the test that was missing: deploy the same cases with the original v1 and with the new one, against a throwaway server, and compare how everything ends up. Files, permissions, what got deleted, what each script did. To know whether the test was any good, we sabotaged it on purpose. We changed the folder the script runs from, and more than half the cases failed. The test saw what it needed to see.

You can’t know who uses your tag, but you can know how you use it. And if you’re also its biggest user, that’s a pretty good sample.

Who tests the tests?

The action’s first tests had their own bugs, and both were the worst kind: the ones that make you feel safe.

One compared the new version against the v1 tag. But as soon as we published the first new version, v1 started pointing to it. The test was comparing the code with itself, and it could never fail. The other ran on a test server where a command failed silently, so it compared two empty lists. Always a match.

To catch this kind of thing, I worked the way I did with my site, with two models on opposite sides: one builds and the other reviews. Codex’s review found, for example, a lost permission that would have broken some post-deploy scripts. Without that review, that version would have shipped broken.

A test that can’t fail is worse than no test at all, because it lets you sleep at night.

What was under the magic

Reading the real workflows didn’t just help us not break anything. It also showed what was already broken, and had been for years.

Six repos were uploading their .git folder to the server. Nobody had noticed, because from the outside the deploy worked the same. What kept hidden files from being uploaded were the default flags, and when a project passed its own, that protection disappeared without warning. The difference is in one part of a single line:

# v1's default flags
FLAGS: -azvrhi --inplace --exclude='.*'
# What a lot of our workflows passed
FLAGS: -azvrhi --inplace --delete-excluded --exclude-from=.deployignore

If the .deployignore didn’t have .*, the .git folder went along with the deploy. There was more: a deploy that failed after the files were already uploaded, a connection that wouldn’t start if a certain folder already existed, and an SSH setup that accepted any server, even if it had changed.

That’s where the core idea of v2 (opens in a new tab) came from: the safe behavior has to be the default. There are files that never get uploaded, like .git or .env, and server files that never get deleted, like wp-config.php or uploads/, whatever the workflow says. Whoever deploys doesn’t need to know about it to be protected. The magic’s still there, but now it has guardrails.

We split it into small releases so we wouldn’t mix things up. First, the compatible changes. Then, a fixed image for each version, because while digging around I found that WP Engine’s action had recently broken the deploy for everyone (opens in a new tab) when rsync got updated without anyone asking for it. And last, the changes in behavior, with their own version number. We also took the chance to rewrite the README as a step-by-step guide, with a rule I gave Claude: “Let’s make everything junior-proof”. The same juniors from the start, now with something they can read, or hand off to AI.

More than the job asked for

Odds are 99.9% of its usage is EpicDevs. But the code is public, and if someone out there was using it, I didn’t want to make trouble for them. That’s why v1 stays where it is, doing the same thing as on day one, and the new stuff lives in v2.

And since mine came from WP Engine’s, I went through theirs too. Two of the problems we fixed were still there, so I opened two issues on their repo: one (opens in a new tab) because it didn’t protect wp-config.php or uploads/ with certain flags, and another (opens in a new tab) for the folder that made the connection fail. Years later, I gave something back to the action I’d based mine on.

My philosophy has always been to build things better than the problem asked for: reusable, modular, maintainable. A .sh just for me would have been enough. An action just for WP Engine, too. But that’s how I learned to work better, and that’s why, the day everything had to change, there was something solid to change.

Magic is fine. It’s what lets someone who just joined deploy without fear and worry about other things. But someone has to know what’s underneath, and has to be able to open it up without breaking anything. This time, to open it, reading how we used it was enough.

I still don’t know who uses my v1. But now I know how we use it, and that it still works the way it should.