diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7e931c668..cde69288e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -64,6 +64,7 @@ jobs: README_VERSION=$(grep -m 1 "Stable tag: " readme.txt | awk -F' ' '{print $3}') PKG_VERSION=$(node -p "require('./package.json').version") CLASS_VERSION=$(grep -oP "const VERSION = '\K[^']+" inc/class-wp-ultimo.php) + CONSTANT_VERSION=$(grep -oP "define\('WP_ULTIMO_VERSION', '\K[^']+" ultimate-multisite.php) # Composer drops VCS tags whose composer.json "version" disagrees with the tag (GH#2158). if jq -e 'has("version")' composer.json > /dev/null; then @@ -76,17 +77,18 @@ jobs: echo "readme.txt Stable tag: $README_VERSION" echo "package.json: $PKG_VERSION" echo "WP_Ultimo::VERSION: $CLASS_VERSION" + echo "WP_ULTIMO_VERSION: $CONSTANT_VERSION" - # For pre-releases, only check plugin header, class constant, and package.json + # For pre-releases, only check plugin header, class constants, and package.json # (readme.txt Stable tag stays at the last stable version) if [ "${{ env.IS_PRERELEASE }}" = "true" ]; then - if [ "$WP_VERSION" != "${{ env.VERSION }}" ] || [ "$PKG_VERSION" != "${{ env.VERSION }}" ] || [ "$CLASS_VERSION" != "${{ env.VERSION }}" ]; then + if [ "$WP_VERSION" != "${{ env.VERSION }}" ] || [ "$PKG_VERSION" != "${{ env.VERSION }}" ] || [ "$CLASS_VERSION" != "${{ env.VERSION }}" ] || [ "$CONSTANT_VERSION" != "${{ env.VERSION }}" ]; then echo "Error: Version mismatch detected!" exit 1 fi echo "Pre-release version numbers match: ${{ env.VERSION }}" else - if [ "$WP_VERSION" != "${{ env.VERSION }}" ] || [ "$README_VERSION" != "${{ env.VERSION }}" ] || [ "$PKG_VERSION" != "${{ env.VERSION }}" ] || [ "$CLASS_VERSION" != "${{ env.VERSION }}" ]; then + if [ "$WP_VERSION" != "${{ env.VERSION }}" ] || [ "$README_VERSION" != "${{ env.VERSION }}" ] || [ "$PKG_VERSION" != "${{ env.VERSION }}" ] || [ "$CLASS_VERSION" != "${{ env.VERSION }}" ] || [ "$CONSTANT_VERSION" != "${{ env.VERSION }}" ]; then echo "Error: Version mismatch detected!" exit 1 fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 88e82893c..f02ffce85 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -326,7 +326,14 @@ ultimate-multisite/ Releases are automated via GitHub Actions: -1. Update version numbers in plugin files +1. Update version numbers in every location: the plugin header `Version:` and `@version` in + `ultimate-multisite.php`, `define('WP_ULTIMO_VERSION', ...)` in `ultimate-multisite.php`, + `WP_Ultimo::VERSION` in `inc/class-wp-ultimo.php`, `package.json`, `composer.json`, `VERSION` + and the `readme.txt` `Stable tag` (stable releases only). Also run + `bin/replace-next-version.sh --check-guessed --allow 2.x.x` to list guessed numeric + `@since` / `@deprecated` tags (versions that are not a release tag) added since the last + release, and fix them before tagging. The release workflow verifies all of these versions + except `composer.json` and `VERSION`. 2. Stable releases only: replace `n.e.x.t` version placeholders with `pnpm run since 2.x.x` (see below) 3. Update the changelog in `readme.txt` 4. Create and push version tag: `git tag v2.x.x && git push origin v2.x.x` diff --git a/bin/deploy.sh b/bin/deploy.sh index d9d383bc3..ad2662f11 100755 --- a/bin/deploy.sh +++ b/bin/deploy.sh @@ -122,6 +122,9 @@ update_versions() { sed -i.bak -E "s/^( \* Version:[[:space:]]*).*/\\1$VERSION/" ultimate-multisite.php sed -i.bak -E "s/^( \* @version).*/\\1 $VERSION/" ultimate-multisite.php + # WP_ULTIMO_VERSION constant (read by the site exporter) + sed -i.bak -E "s/(define\\('WP_ULTIMO_VERSION', ')[^']+('\\);)/\\1$VERSION\\2/" ultimate-multisite.php + # WP_Ultimo const VERSION sed -i.bak -E "s/(const VERSION = ')[^']+(';)/\\1$VERSION\\2/" inc/class-wp-ultimo.php @@ -369,8 +372,16 @@ deploy_to_wporg_svn() { echo "SVN deployment complete." } +warn_guessed_since_tags() { + echo "==> Checking for guessed @since/@deprecated version tags" + if ! bash "$PLUGIN_DIR/bin/replace-next-version.sh" --check-guessed --allow "${VERSION%%-*}"; then + echo "Warning: guessed version tags found (listed above). Replace them with n.e.x.t or the correct released version before shipping." + fi +} + main() { ensure_clean_git + warn_guessed_since_tags update_versions sync_changelog_and_date commit_and_push diff --git a/bin/replace-next-version.sh b/bin/replace-next-version.sh index bba7862aa..1639a5b1e 100755 --- a/bin/replace-next-version.sh +++ b/bin/replace-next-version.sh @@ -18,6 +18,10 @@ # Usage: # bin/replace-next-version.sh 2.20.0 Replace placeholders with 2.20.0 (stable versions only) # bin/replace-next-version.sh --check List remaining placeholders; exit 1 if any +# bin/replace-next-version.sh --check-guessed [] [--allow X.Y.Z] +# List numeric @since/@deprecated tags added since (default: latest +# v* tag) whose version is not an existing release tag or an --allow version; +# exit 1 if any. Catches guessed versions on unreleased code. set -euo pipefail @@ -44,6 +48,9 @@ PLACEHOLDER_REGEX="@(since|deprecated)[[:space:]]+n\.e\.x\.t|'[^']*n\.e\.x\.t'|^ usage() { echo "Usage: $(basename "$0") Replace n.e.x.t placeholders with " echo " $(basename "$0") --check List remaining n.e.x.t placeholders" + echo " $(basename "$0") --check-guessed [] [--allow X.Y.Z]..." + echo " List numeric @since/@deprecated tags added since " + echo " (default: latest v* tag) that are not release tags" return 0 } @@ -80,6 +87,81 @@ check_placeholders() { return 0 } +# Prints the latest stable release tag (vX.Y.Z), or nothing when none exists. +latest_release_tag() { + git -C "$ROOT_DIR" tag -l 'v*' --sort=-v:refname | grep -E -m1 '^v[0-9]+\.[0-9]+\.[0-9]+$' || true + return 0 +} + +# Lists @since / @deprecated tags with a numeric version on lines added since +# whose version is neither an existing release tag nor allowed via +# --allow. Guessed versions ship wrong; unreleased code must use n.e.x.t. +# Output lines: file:line: text. Exit 1 when any are found. +check_guessed() { + local base="$1" + shift + local allowed=("$@") + local found=0 + local diff_output + local file lineno version text + + if [[ -z "$base" ]]; then + base=$(latest_release_tag) + fi + + if [[ -z "$base" ]] || ! git -C "$ROOT_DIR" rev-parse --verify --quiet "$base^{commit}" >/dev/null; then + echo "Error: base ref '${base:-}' not found; pass one: --check-guessed " >&2 + return 2 + fi + + diff_output=$(git -C "$ROOT_DIR" diff --unified=0 --no-color --no-ext-diff "$base" -- "${PATHSPECS[@]}") || return 2 + + while IFS=$'\t' read -r file lineno version text; do + [[ -z "$file" ]] && continue + + if [[ -n "$(git -C "$ROOT_DIR" tag -l "v$version")" ]]; then + continue + fi + + if [[ ${#allowed[@]} -gt 0 ]] && printf '%s\n' "${allowed[@]}" | grep -qxF "$version"; then + continue + fi + + if [[ $found -eq 0 ]]; then + echo "Guessed @since/@deprecated versions (not a release tag) added since $base:" + fi + echo "$file:$lineno: $text" + found=$((found + 1)) + done < <(awk ' + /^\+\+\+ / { file = ($2 == "/dev/null") ? "" : substr($2, 3); next } + /^@@ / { + split($3, parts, ",") + line = substr(parts[1], 2) + 0 + next + } + /^\+/ && file != "" { + text = substr($0, 2) + rest = text + while (match(rest, /@(since|deprecated)[ \t]+v?[0-9]+(\.[0-9]+)+/)) { + tag = substr(rest, RSTART, RLENGTH) + sub(/^@(since|deprecated)[ \t]+v?/, "", tag) + gsub(/\t/, " ", text) + printf "%s\t%d\t%s\t%s\n", file, line, tag, text + rest = substr(rest, RSTART + RLENGTH) + } + line++ + } + ' <<<"$diff_output") + + if [[ $found -gt 0 ]]; then + echo "Use n.e.x.t for unreleased code (see CONTRIBUTING.md), or correct the version." + return 1 + fi + + echo "No guessed @since/@deprecated versions found since $base." + return 0 +} + replace_in_file() { local file="$1" local version="$2" @@ -127,6 +209,27 @@ main() { check_placeholders return $? ;; + --check-guessed) + shift + local base="" + local allow=() + if [[ $# -gt 0 && "$1" != --* ]]; then + base="$1" + shift + fi + while [[ $# -gt 0 ]]; do + if [[ "$1" == "--allow" && $# -ge 2 ]]; then + allow+=("$2") + shift 2 + else + echo "Error: unexpected argument '$1'" >&2 + usage >&2 + return 1 + fi + done + check_guessed "$base" ${allow[@]+"${allow[@]}"} + return $? + ;; '' | -h | --help) usage [[ -n "$arg" ]] && return 0