Git Tags and Signed Releases for WordPress Plugins

Git tags and signed releases for a WordPress plugin

A plugin release is a version number in three places (the plugin header, readme.txt‘s “Stable tag”, a constant in the code), a ZIP and, ideally, a tag in git that marks exactly which commit was released. When these drift apart, a support request for “version 2.4.1” cannot be traced to the code. Annotated, signed tags and a small release check keep them together.

Problem: A plugin’s releases are built from whatever is checked out. The header says 2.4.1, readme.txt still says 2.4.0, there is no tag, and nobody can tell which commit customers are running.

Solution: Bump the version in all places in one commit, check them with a script, create an annotated tag v2.4.1 (signed with SSH or GPG), push the tag, and let CI build the ZIP only from tags. Verify signatures with git tag -v.

Annotated tags, not lightweight tags

git tag v2.4.1                                   # lightweight: only a name for a commit
git tag -a v2.4.1 -m "Release 2.4.1"             # annotated: own object with tagger, date, message
git show v2.4.1
git push origin v2.4.1                           # tags are not pushed with branches

An annotated tag records who tagged and when, carries a message, and can be signed. git describe and most release tools ignore lightweight tags by default. Push a tag explicitly; git push --follow-tags pushes annotated tags that point to pushed commits.

Sign with an SSH key

Git 2.34+ can sign with the SSH key many developers already have:

git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global tag.gpgSign true          # sign every annotated tag

git tag -a v2.4.1 -m "Release 2.4.1"          # signed now

To verify, git needs a list of trusted keys:

echo "dev@example.com $(cat ~/.ssh/id_ed25519.pub)" >> ~/.config/git/allowed_signers
git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers
git tag -v v2.4.1
# Good "git" signature for dev@example.com with ED25519 key SHA256:...

GitHub and GitLab show a “Verified” badge on tags signed with a key that is registered as a signing key in the user’s account. GPG signing works the same way with gpg.format openpgp (the default).

Check the version numbers before tagging

#!/usr/bin/env bash
# bin/check-version.sh 2.4.1
set -euo pipefail
v="$1"
grep -q "^ \* Version: *$v$" ha-plugin.php            || { echo "plugin header"; exit 1; }
grep -q "^Stable tag: *$v$" readme.txt               || { echo "readme.txt"; exit 1; }
grep -q "HA_PLUGIN_VERSION', '$v'" ha-plugin.php      || { echo "constant"; exit 1; }
grep -q "^= $v" readme.txt                           || { echo "changelog entry"; exit 1; }
echo "version $v consistent"

Run it before git tag, and again in CI on the tag, with the version taken from the tag name (${GITHUB_REF_NAME#v}). A release whose numbers do not match then fails before a ZIP exists.

Build releases from tags only

# .github/workflows/release.yml (excerpt)
on:
  push:
    tags: [ 'v*' ]
jobs:
  zip:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: bin/check-version.sh "${GITHUB_REF_NAME#v}"
      - run: composer install --no-dev --optimize-autoloader
      - run: git archive --format=zip --prefix=ha-plugin/ -o ha-plugin.zip HEAD

git archive packs exactly the tagged commit and respects export-ignore entries in .gitattributes (tests, configs, the .github folder). Files that are not in git, like the vendor folder installed in the step before, are not included by git archive; add them with a zip step of their own or commit a built vendor on a release branch, depending on the plugin. The general pipeline: GitHub Actions CI/CD for WordPress plugins.

Fixing a wrong tag

git tag -d v2.4.1                       # local
git push origin :refs/tags/v2.4.1        # remote

Only do this before anybody installed the release. Once a tag is public, others may have fetched it, and git does not update existing tags on fetch; release a 2.4.2 instead.

NOTE: Plugins on WordPress.org are released through SVN: the “Stable tag” in readme.txt on trunk points to an SVN tag folder. Git tags do not reach WordPress.org by themselves; a deploy action that copies the tagged release into SVN closes that gap. Backporting a fix into an older release line before tagging it: git cherry-pick.