DEV Community

Cover image for One git tag, every release step: the CI/CD behind an open-source WordPress plugin
Nicu Micle
Nicu Micle

Posted on

One git tag, every release step: the CI/CD behind an open-source WordPress plugin

I maintain Simple JWT Login, a free WordPress plugin that adds JWT authentication to the WordPress REST API. It is a security plugin: it hands out tokens, logs users in, and decides who can call which endpoint. A bug here is not a broken button. It is someone else logged in as your admin.

For a long time a release meant a checklist in my head. Bump the version in four places. Copy the changelog into the WordPress.org readme. Build the zip. Commit to SVN. Write the GitHub release. Update the Postman collection. Update the docs site. Forget one step, and users see a mismatch.

Now a release is one command and one tag. This post shows the whole setup, how each piece works, and the few tricks that made it reliable. Everything is in the repo, so you can copy any workflow into your own plugin.

The big picture

There are two repositories:

  • nicumicle/simple-jwt-login - the plugin code, the OpenAPI spec (openapi/openapi.yaml) and Changelog.md.
  • simple-jwt-login/website - the docs site, built with Docusaurus.

Big picture: two repos, one tag fans out to WordPress.org, GitHub Releases, Postman and the docs site

The rule that holds it together: every fact lives in exactly one file. The API contract lives in openapi.yaml. Release notes live in Changelog.md. The version number is typed once, on the command line. Everything else is generated from those files, by a script or by a workflow.

Single source of truth: Changelog.md, openapi.yaml and the version number feed every other file

If you only steal one idea from this post, steal that one. Most release bugs are two copies of the same fact that drifted apart.

Part 1: what runs on every pull request

When a contributor opens a pull request, CodeQL scans the code, CodeRabbit is ready to review on request, and up to six workflows start. Each workflow has a paths: filter, so it only runs when something it checks has changed. A README typo does not need Chrome, MySQL and twelve PHP versions:

  • lint.yml runs when a PHP file or a linter config changes.
  • multiple-php.yml runs when PHP under simple-jwt-login/ changes.
  • plugin-check.yml runs when anything under simple-jwt-login/ changes.
  • tests.yml runs when the plugin, the tests, the Docker setup or Composer changes.
  • The two OpenAPI workflows run only when the spec changes.

Every filter also lists the workflow's own file, so a change to the pipeline always tests itself. The only secret any of them uses is an optional Codecov token. Without it, the upload falls back to tokenless mode, so PRs from forks still work.

Pull request pipeline: lint, PHP matrix, plugin check and tests behind path filters, CodeQL, CodeRabbit on request, and OpenAPI checks only when the spec changes

Static checks

lint.yml runs PHPCS (PSR-12), PHPMD and PHPStan level 5. Plain, fast, and the first thing to fail.

12 PHP versions, from 5.5 to 8.5

The plugin still supports PHP 5.5. Many WordPress hosts never upgrade, and I do not want to drop those users. But I write code on PHP 8, so it is easy to type ?? or a return type without noticing.

multiple-php.yml catches that with a matrix and php -l:

strategy:
  fail-fast: false
  matrix:
    php: [ '5.5', '5.6', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
steps:
  - uses: shivammathur/setup-php@v2
    with:
      php-version: ${{ matrix.php }}
  - working-directory: simple-jwt-login/
    run: find . -type f -name '*.php' -print0 | xargs -0 -n1 -P4 php -l
Enter fullscreen mode Exit fullscreen mode

It only checks syntax, not behaviour, but syntax is exactly what breaks on old PHP. A parse error on PHP 5.6 takes down the whole site, not one feature. This job costs about a minute and has saved me more than once.

The official WordPress Plugin Check

plugin-check.yml runs wordpress/plugin-check-action, the same checks the WordPress.org review team uses. Better to hear about a problem from CI than from the plugin directory.

Two security reviewers that never get tired: CodeRabbit and CodeQL

Linters catch style. Tests catch what I thought of. For an auth plugin I also want someone reading every diff and asking "can this be abused?". Two tools do that.

CodeRabbit reviews pull requests with AI. It has no workflow file. Everything lives in .coderabbit.yaml in the repo root, so contributors can read exactly how their PR will be reviewed. Three parts of that file do most of the work:

  • A persona and a threat model. The reviewer is told it is a senior PHP/WordPress security engineer reviewing an auth plugin with public, unauthenticated REST routes, where any bypass is an account takeover, often of an administrator. It is told to lead with exploitable issues and a concrete attack path, and to skip praise, style nits and poems.
  • Path-specific instructions. PHP files get a priority list: JWT verification (alg confusion, none, missing exp / iss / aud checks, hash_equals for signatures), refresh token reuse, permission_callback on every REST route. openapi.yaml must match the routes, so a PR that changes an endpoint without updating the spec gets flagged. Workflow files are checked for pull_request_target with PR checkout, unpinned actions and missing permissions blocks.
  • Extra scanners in the same review. PHPStan, PHPCS and PHPMD run with the repo's own config, plus gitleaks (secrets), Semgrep, OSV-Scanner (vulnerable dependencies), actionlint and zizmor (GitHub Actions security), ShellCheck and yamllint.

Reviews are on demand: a maintainer comments @coderabbitai review on the PR. CONTRIBUTING.md is loaded as the code guidelines, so the review follows the same rules a human reviewer would.

CodeQL is GitHub's own code scanner, turned on with GitHub's default setup (repository settings, no YAML to maintain). It scans pull requests and master and reports findings in the Security tab and on the PR. One thing to know: CodeQL does not analyse PHP. Here it covers the admin JavaScript in assets/js/ and the GitHub Actions workflows. That is why the PHP side gets Semgrep and the security-focused CodeRabbit review instead. Two tools with different blind spots beat one tool you trust blindly.

A deploy dry run on every merge

deploy.yml has two jobs. On every push to master it runs the deployer with dry_run: true, so it builds the SVN layout without committing anything. On a tag push it runs for real. The deploy path is tested hundreds of times before it matters. Release day is not the first time it runs.

The test pipeline: unit, feature, then cross-site

tests.yml is a small file that only wires three reusable workflows together:

jobs:
  unit:
    uses: ./.github/workflows/_unit_tests.yml
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  feature:
    uses: ./.github/workflows/_feature_tests.yml
  cross-site:
    needs: [ unit, feature ]
    uses: ./.github/workflows/_cross_site_tests.yml
Enter fullscreen mode Exit fullscreen mode

Unit and feature tests run in parallel. The cross-site tests are the slowest, so they only start when both passed. No point spinning up Chrome if a unit test is red.

The child workflows use on: workflow_call only. They never trigger by themselves, so there is one place that decides what runs and in which order. The _ prefix keeps them at the top of the folder and marks them as building blocks, not entry points.

Unit tests (134 test files) mock WordPress. A bootstrap.php file stubs the WordPress functions, and all WordPress access goes through one repository class, so tests mock that interface instead of a live database. The same run collects coverage with pcov (much faster than Xdebug, and line coverage is all I report) and uploads it to Codecov. Coverage comes from every test run, not from a separate release job, so the README badge is always current.

Feature tests (50 test files) are the opposite. The runner installs Apache, MySQL, WP-CLI and a real WordPress, activates the plugin, and sends real HTTP requests. They run on PHP 8.4 and 8.5. Unit tests tell you the logic is right. Feature tests tell you WordPress agrees.

Part 1b: the plugin attacks itself from another site

This is the part I am most proud of.

An auth plugin that stores a JWT in a cookie must defend against CSRF: a page on evil.example that makes your browser call your WordPress site, with your cookie attached. It must also send the right CORS headers, so only the origins you allow can read the responses.

You cannot test that with PHPUnit. You need a real browser, a second site, and a cookie. So _cross_site_tests.yml builds exactly that:

Cross-site test setup: headless Chrome holding the JWT cookie opens pages on a second site that call the WordPress site

  • WordPress with the plugin runs on localhost:88.
  • A second container, other-site, serves proof-of-concept pages on 127.0.0.1:8090. That is a different site from localhost, as far as the browser is concerned. localhost:8090 is also used, as a same-site but cross-origin control.
  • Playwright drives a real headless Chrome that holds the plugin's JWT cookie.
  • Each test opens an attacker page, the page fires fetch, a form post or an <img> at the plugin, and the test checks whether the request was blocked or allowed.
  • curl from the other-site container covers server-to-server calls, which must keep working.

The tests are table rows, so adding a case is one line, not a new test file.

One detail that took a while: Playwright's own request events do not always show the cookie on aborted no-cors requests, and a CORS response that nobody reads never "finishes". The fixtures read what Chrome really sent through the DevTools network events instead. If you build something similar, start there and save yourself a day.

Part 1c: the API spec is tested against the live API

openapi/openapi.yaml describes every REST endpoint. A spec that nobody checks is a spec that lies. So when a PR touches openapi/**, two extra workflows run:

  • openapi-validate.yml lints the spec with Redocly.
  • openapi_tests.yml reuses the feature test workflow with one input flipped:
jobs:
  openapi:
    uses: ./.github/workflows/_feature_tests.yml
    with:
      openapi: true
Enter fullscreen mode Exit fullscreen mode

Same WordPress setup, but instead of PHPUnit it runs Schemathesis. Schemathesis reads the spec, generates requests (including weird ones), calls the live site, and fails if a response does not match the documented schema. If the docs say an endpoint returns { "success": true, "data": {...} } and it really returns something else, CI fails.

Reusing _feature_tests.yml with a boolean input means the WordPress install steps exist once. Two suites, one setup to maintain.

Part 2: one command to prepare a release

Before tagging, I run one command locally:

composer prepare-release 4.3.0
Enter fullscreen mode Exit fullscreen mode

prepareRelease.sh does five things:

  1. Moves the ## Unreleased entries in Changelog.md to ## 4.3.0 (today's date).
  2. Sets 4.3.0 in the plugin header, the SIMPLE_JWT_LOGIN_VERSION constant, the readme Stable tag, and info.version in openapi.yaml.
  3. Copies the new release into the WordPress.org readme (syncChangelog.sh).
  4. Regenerates the .pot translation file.
  5. Rebuilds download/simple-jwt-login.zip.

It never commits, tags or pushes. I review the diff first, then I do that myself.

syncChangelog.sh is worth a closer look. The WordPress.org readme uses its own format (== Changelog ==, = 4.3.0 =). So I write notes once, in normal Markdown, and the script converts them. Bullets under ### Security get a Security: prefix, and a line starting with **Upgrade notice:** goes to the readme's == Upgrade Notice == section. The full check suite runs syncChangelog.sh --check, which fails if the readme is out of date. You cannot forget to sync it.

Part 3: one tag, many destinations

When I push the tag, three workflows start in parallel:

Release fan-out: one tag triggers the WordPress.org deploy, the GitHub release and the Postman publish

WordPress.org

deploy.yml uses a small action I wrote, simple-jwt-login/deployer. It commits simple-jwt-login/ to SVN trunk, creates tags/4.3.0, and syncs the banner and screenshots from the wordpress.org/ folder. SVN credentials are repository secrets, only used on tag pushes.

GitHub Release

github-release.yml refuses to run if the tag and the plugin version do not match:

PLUGIN_VERSION=$(grep -m1 -E '^\s*Version:' simple-jwt-login/simple-jwt-login.php | awk '{print $2}')
if [ "$PLUGIN_VERSION" != "$GITHUB_REF_NAME" ]; then
  echo "::error::simple-jwt-login.php Version is '$PLUGIN_VERSION', tag is '$GITHUB_REF_NAME'"
  exit 1
fi
Enter fullscreen mode Exit fullscreen mode

Then it cuts the release notes out of Changelog.md with a few lines of awk: start at ## 4.3.0 (, stop at the next ##. It builds the zip from the tagged code, checks the version inside the zip, and creates the release. On a re-run it edits the existing release instead of failing, so a flaky run is fixed with one click.

Postman

The plugin has a public Postman collection generated from the OpenAPI spec. postman.yml converts the spec with openapi-to-postmanv2 and replaces the content of the existing collection, keeping the same UID, so the public link never changes.

There is a catch. GitHub ignores paths filters on tag pushes. So the workflow compares the spec with the previous tag itself, and skips publishing if nothing changed:

if previous=$(git describe --tags --abbrev=0 "$GITHUB_SHA^"); then
  if git diff --quiet "$previous" "$GITHUB_SHA" -- openapi/openapi.yaml; then
    openapi=false
    echo "::notice::openapi.yaml is unchanged since $previous, nothing to publish"
  fi
fi
Enter fullscreen mode Exit fullscreen mode

Before publishing it calls openapi-validate.yml (the same reusable workflow PRs use) and checks that the spec's info.version matches the tag.

After the release: does the published plugin install?

Everything above tests the repo. Users never see the repo. They see whatever WordPress.org serves. So wordpress-org-install.yml runs every morning on a cron: it installs a fresh WordPress, runs wp plugin install simple-jwt-login --activate, checks that the plugin is active, and writes the installed version to the job summary.

It is one short workflow, and it tests the one artifact that matters: the zip a real site downloads. If an SVN commit went wrong, a file is missing from the build, or a new WordPress release breaks activation, I find out from a red cron run, not from a support ticket.

Part 4: how the docs are built

The docs site is a separate repo, simple-jwt-login/website, built with Docusaurus. The API reference is not written by hand. It is generated from the same openapi.yaml that Schemathesis tests against the live API. So the API docs are, quite literally, tested.

Docs pipeline: the spec is synced to the website repo by PR, linted for structure and prose, previewed, then built and deployed on tag

Step 1: the spec moves by pull request, not by copy-paste

On every merge into master that changes the spec, sync-website.yml in the plugin repo checks out the website repo, copies the spec to static/openapi/v4.yaml, and opens (or updates) a PR with peter-evans/create-pull-request on a fixed openapi-sync branch. The PR body says: do not edit the spec here, change it in the plugin repository.

Two small details:

  • It always checks out master, even on a manual re-run, so a re-run can never sync an older spec.
  • The third-party action is pinned to a commit SHA, not a tag, because this job has a token that can write to another repo.

A PR instead of a direct push means the docs site's own CI gets a say before anything goes live.

Step 2: the website CI checks structure and words

Three workflows run on that PR:

  • CI-validate runs cspell and a full yarn build. The build fails on broken links.
  • CI-openapi lints the spec again with Redocly.
  • CI-vale runs Vale with the Google and write-good styles on the docs, the website pages, and the description / summary fields of the OpenAPI spec. A custom Vale view picks only the human-readable fields of the YAML. Vale cannot read text inside JSX, so the script lints the website pages from the rendered HTML in build/.

That last point changes how I write the spec in the plugin repo. A sloppy description in openapi.yaml now fails a check two repos away. I learned to write "for example" instead of "e.g." pretty quickly.

Step 3: the API pages are generated at build time

yarn build has a prebuild hook that runs gen-api. That uses docusaurus-plugin-openapi-docs to turn v4.yaml (and the old v3.yaml, for users still on 3.x) into MDX pages, one per endpoint, with request and response schemas and example calls. The generated pages are not committed. The spec is the source, the pages are build output.

The same build also produces:

  • a sitemap with real lastmod dates (the deploy checks out full git history for that),
  • an llms.txt file, so AI assistants can read the docs in one request,
  • a local search index, with no external search service.

Step 4: preview deploys, without leaking secrets

Reviewing docs as a diff is hard. You want to click around. So the website has per-PR previews on Cloudflare Workers, and this is the workflow where I was most careful.

A preview has to build code from the PR, which may come from a fork. That code must never see the Cloudflare token. So CI-preview has two jobs:

  1. build checks out the PR head with persist-credentials: false, has no secrets and only read permissions, and uploads build/ as an artifact.
  2. deploy checks out only the trusted default branch, downloads the static files, and deploys them with the token. It never runs anything from the PR.

It is workflow_dispatch only, so only people with write access can start it. It validates that the PR number is a number, checks the PR is still open, adds an X-Robots-Tag: noindex header so previews stay out of Google, and comments the preview URL on the PR.

CI-preview-cleanup deletes the preview when the PR is closed, and an hourly cron deletes any preview older than 48 hours. It uses pull_request_target so it has the token for fork PRs too, and that is safe only because it never checks out or runs anything from the PR. The comment at the top of the file says exactly that, so nobody "improves" it later.

Step 5: deploy on tag

Pushing a tag on the website repo runs CI-deploy: build, then deploy. A repository variable, DEPLOY_TARGET, picks the host. cloudflare deploys to Cloudflare Workers with Wrangler. Anything else deploys to GitHub Pages. Moving hosts was a variable change, not a rewrite.

What a contributor actually needs to do

All of the above sounds like a lot. From a contributor's side, it is small:

git clone https://github.com/nicumicle/simple-jwt-login.git
cd simple-jwt-login
docker compose -f docker/docker-compose.yaml up
docker exec -it wordpress bash -c "cd /var/www/dev && composer run check-plugin"
Enter fullscreen mode Exit fullscreen mode

check-plugin runs the same checks as CI: readme sync, PHPCS, PHPMD, PHPStan, unit and feature tests. If it is green locally, the PR is almost always green.

Then:

  • Change an endpoint? Update openapi/openapi.yaml in the same PR. CI checks it against the live API, and the docs site updates itself after merge.
  • Have release notes? Add a bullet under ## Unreleased in Changelog.md. That is the only place you write it.

You never touch SVN, Postman, the readme changelog, or the docs repo.

Lessons, if you want to do this for your plugin

  1. One fact, one file. Generate the copies. Add a --check mode to every sync script and run it in CI.
  2. Make the tag the only release button. Everything a release needs should run from on: push: tags.
  3. Check the tag against the code. A two-line version check stops the most embarrassing release bug there is.
  4. Use reusable workflows with inputs. One WordPress install, two test suites. One validate job, used by PRs and by the Postman publish.
  5. Run the deploy as a dry run on every merge. Release day should not be its first run.
  6. Test security from the outside. A real browser on a second origin finds things PHPUnit never will.
  7. Give the AI reviewer your threat model. A generic review prompt gets generic comments. Tell it what an attack on your plugin looks like, per path, in a file that lives in the repo.
  8. Test the docs. If your API reference comes from a spec, test the spec against the live API.
  9. Split preview builds from preview deploys. Untrusted code never shares a job with a secret.
  10. Filter by path, and include the workflow itself. Docs-only PRs skip the heavy jobs, and a change to the pipeline still tests itself.
  11. Test what users download. A daily install from WordPress.org catches what no test in the repo can.

Try it, read it, star it

Everything in this post is in the open:

If a workflow here saved you an afternoon, a star on the repo is the best way to say thanks. It helps other WordPress developers find the plugin, and it tells me this kind of write-up is worth doing again.

And if you find a hole in any of it, open an issue. That is what the cross-site tests are for.

Top comments (0)