Test against the newest WordPress and WooCommerce, and ship updates

Three things this repository could not do: prove the plugin still works on a
WordPress or WooCommerce released after it, get a fix onto a shop without
someone uploading a zip, and do either of those for the next plugin without
starting over.

ci/ is the test harness. ci/site-test.sh builds a throwaway WordPress +
WooCommerce in containers at any versions you name — including `nightly` and
`beta` — installs exactly the files the release zip will contain, and runs
tests/smoke.php inside it with wp eval-file. Real cart, real coupons, real
WC_Shipping_Rate objects: a mocked cart keeps passing after WooCommerce has
changed underneath it, which is the one failure worth catching here. WP_DEBUG
is on and any notice logged from this plugin's directory fails the build,
because that is the shape an upgrade actually breaks in — nothing fails, a
notice appears, and two releases later it is a fatal.

compat.yml runs that weekly against today's releases, the next WordPress and
the next WooCommerce, the oldest PHP the header promises and the newest PHP.
When it is green it opens a PR bumping "Tested up to" and "WC tested up to" —
only when green, because WooCommerce shows that second value to the shop owner
as an untested-plugin banner, and that banner is what they read before deciding
whether to press update.

includes/class-updater.php is the distribution half. It hooks
update_plugins_{hostname} for the host in the new "Update URI" header and reads
the Gitea release API, so WordPress handles the notice, the download, the
"Enable auto-updates" link and wp plugin update with no further code. Update
URI earns its place twice: since 5.8 a plugin that declares one is never asked
about on wordpress.org, so a .org plugin sharing this slug cannot be pushed
onto a shop running this one. The check sends nothing about the site and
overrides WordPress's default user agent, which carries the site's own URL.

release.yml tags, tests, builds, publishes — then reads the feed back with no
credentials. A private repository and a release with no zip attached both leave
a page that looks perfect to anyone logged in and an update no shop is ever
offered.

Measured before committing, all green: WP 7.1 + WC 11.1 on PHP 8.3 and 7.4,
WP 7.2-alpha on 8.3, and the beta cell falling back to stable on 8.4. No
deprecations from this plugin on any of them.

Three guards are there because the bug they catch is invisible without them:
the annotated tag is re-fetched before its message is read (checkout turns it
into a lightweight tag pointing at the merge commit), the two workflow roots
are kept in sync (.gitea/workflows hides .github/workflows entirely), and every
file the code loads must be in the release zip — which caught class-updater.php
being referenced and uncommitted while every local test passed.

docs/REUSE.md is the port to the next plugin: copy ci/, rewrite five lines.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kristianwind
2026-09-16 10:34:38 +02:00
co-authored by Claude Opus 5
parent e4a40e53a0
commit eca2851d35
29 changed files with 2550 additions and 5 deletions
+142
View File
@@ -0,0 +1,142 @@
#!/usr/bin/env bash
# Publish a release with the plugin zip attached, on whichever forge is running
# this, and then verify the result the way a shop will actually see it.
#
# Needs: TAG, GITHUB_REPOSITORY, GITHUB_API_URL, GITHUB_SERVER_URL, GH_TOKEN.
#
# The verification at the end is the part worth keeping. The update feed is
# read anonymously by every shop, and the two ways it breaks — a private
# repository and a release with no zip attached — both leave a release page
# that looks perfectly fine to whoever is logged in. Nobody would notice for
# months; what they would notice is that updates stopped arriving.
set -euo pipefail
cd "$(dirname "$0")/.."
. ci/lib.sh
ci_load_conf
: "${TAG:?TAG is not set}"
: "${GH_TOKEN:?GH_TOKEN is not set}"
: "${GITHUB_REPOSITORY:?}"
: "${GITHUB_API_URL:?}"
zip="build/$PLUGIN_SLUG.zip"
[ -f "$zip" ] || { echo "$zip does not exist — run ci/build-zip.sh first." >&2; exit 1; }
owner="${GITHUB_REPOSITORY%%/*}"
repo="${GITHUB_REPOSITORY#*/}"
# The tag message is the announcement, so it has to survive the checkout.
#
# actions/checkout fetches every tag correctly and then overwrites this one ref
# with the commit SHA — `fetch-depth: 0` does not save you. The annotated tag
# becomes a lightweight one pointing at the commit, and reading its message
# returns the COMMIT message instead: on a merge commit, "Merge pull request
# #12 from ...". Nothing fails. The release is simply published with the wrong
# text, and only the page shows it.
git fetch --force origin "refs/tags/$TAG:refs/tags/$TAG"
[ "$(git cat-file -t "$TAG")" = tag ] || {
echo "$TAG is not an annotated tag. Its message is what gets published, so create it with 'git tag -a'." >&2
exit 1
}
notes=$(git tag -l --format='%(contents)' "$TAG")
first_line=$(printf '%s\n' "$notes" | head -1)
case "$first_line" in
'Merge pull request'*|'Merge branch'*|'')
echo "The release notes read '$first_line'." >&2
echo "That is a commit message, not the tag message — the annotated tag did not survive the checkout." >&2
exit 1
;;
esac
ci_step "release notes"
printf '%s\n' "$notes" | sed 's/^/ /'
# The updater reads this line out of the release body, so wp-admin can show
# what this version was tested against rather than what the last one claimed.
readme=
for f in readme.txt README.txt; do [ -f "$f" ] && readme=$f && break; done
tested_wp=$([ -n "$readme" ] && sed -n -E 's/^Tested up to:[[:space:]]*([^[:space:]]+).*/\1/p' "$readme" | head -1)
tested_wc=$(ci_plugin_header 'WC tested up to')
body=$(printf '%s\n\n---\n\nTested up to: %s\nWC tested up to: %s\n' \
"$notes" "${tested_wp:-unknown}" "${tested_wc:-unknown}")
api() { # method path [data]
curl -fsS -X "$1" \
-H "Authorization: token $GH_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
${3:+-d "$3"} \
"$2"
}
if [ "${GITHUB_SERVER_URL:-}" = 'https://github.com' ]; then
ci_step "publishing to GitHub"
gh release create "$TAG" "$zip" --title "$TAG" --notes "$body" 2>/dev/null \
|| gh release upload "$TAG" "$zip" --clobber
release_api="$GITHUB_API_URL/repos/$owner/$repo/releases/tags/$TAG"
else
ci_step "publishing to $GITHUB_SERVER_URL"
payload=$(printf '%s' "$body" | python3 -c '
import json, sys, os
print(json.dumps({
"tag_name": os.environ["TAG"],
"name": os.environ["TAG"],
"body": sys.stdin.read(),
"draft": False,
"prerelease": False,
}))')
# A re-run of a release must not fail on "already exists".
existing=$(curl -fsS -H "Authorization: token $GH_TOKEN" \
"$GITHUB_API_URL/repos/$owner/$repo/releases/tags/$TAG" 2>/dev/null || true)
id=$(printf '%s' "$existing" | sed -n -E 's/.*"id":[[:space:]]*([0-9]+).*/\1/p' | head -1)
if [ -z "$id" ]; then
created=$(api POST "$GITHUB_API_URL/repos/$owner/$repo/releases" "$payload")
id=$(printf '%s' "$created" | sed -n -E 's/.*"id":[[:space:]]*([0-9]+).*/\1/p' | head -1)
fi
[ -n "$id" ] || { echo "Could not create or find the release for $TAG." >&2; exit 1; }
echo " release id $id"
curl -fsS -X POST \
-H "Authorization: token $GH_TOKEN" \
-F "attachment=@$zip" \
"$GITHUB_API_URL/repos/$owner/$repo/releases/$id/assets?name=$PLUGIN_SLUG.zip" >/dev/null
echo " attached $PLUGIN_SLUG.zip"
release_api="$GITHUB_API_URL/repos/$owner/$repo/releases/latest"
fi
ci_step "the feed, read the way a shop reads it"
# Deliberately no token on any request below. A "check" that sends credentials
# the shops do not have is the false positive that hides exactly this bug.
feed=$(curl -fsS --max-time 30 "$release_api" 2>/dev/null || true)
if [ -z "$feed" ]; then
echo
ci_fail "$release_api cannot be read without credentials, so no shop will ever be offered this update."
echo "Either the repository is still private, or the release was not created."
echo "For Gitea: Settings → make the repository public. The update feed is a public read by design;"
echo "that is the whole mechanism, and there is nothing secret in a GPL plugin zip anyway."
exit 1
fi
package=$(printf '%s' "$feed" | tr ',' '\n' | sed -n -E 's/.*"browser_download_url":[[:space:]]*"([^"]*\.zip)".*/\1/p' | head -1)
if [ -z "$package" ]; then
echo
ci_fail "The release is readable, but it has no zip attached. WordPress would be offered an update it cannot download."
exit 1
fi
code=$(curl -s -o /dev/null -w '%{http_code}' -L --max-time 60 "$package")
echo " $package -> HTTP $code"
[ "$code" = 200 ] || { ci_fail "The package URL is not anonymously downloadable."; exit 1; }
echo
echo "Published $TAG. A shop running this plugin will be offered it within twelve hours,"
echo "or immediately on Dashboard → Updates → Check again."