80 lines
3.4 KiB
Bash
80 lines
3.4 KiB
Bash
#!/usr/bin/env bash
|
|||
|
|
# Update "Tested up to" and "WC tested up to" to the versions that were just
|
||
|
|
# tested, and open a pull request if anything changed.
|
||
|
|
#
|
||
|
|
# Run only after the compatibility matrix has gone green against the current
|
||
|
|
# releases. The headers are a claim made to whoever installs the plugin — and
|
||
|
|
# in WooCommerce's case a banner the shop owner reads before deciding whether
|
||
|
|
# to update at all — so bumping them on a red build would be publishing a claim
|
||
|
|
# we have just watched fail.
|
||
|
|
#
|
||
|
|
# Writes nothing when the headers are already current, so a quiet week costs a
|
||
|
|
# green run and no noise.
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
cd "$(dirname "$0")/.."
|
||
|
|
. ci/lib.sh
|
||
|
|
ci_load_conf
|
||
|
|
|
||
|
|
current_wp=$(curl -fsS --max-time 20 'https://api.wordpress.org/core/stable-check/1.0/' \
|
||
|
|
| tr ',' '\n' | sed -n -E 's/.*"([0-9][^"]*)"[[:space:]]*:[[:space:]]*"latest".*/\1/p' | head -1)
|
||
|
|
current_wc=$(curl -fsS --max-time 20 'https://api.wordpress.org/plugins/info/1.0/woocommerce.json' \
|
||
|
|
| sed -n -E 's/.*"version":"([^"]+)".*/\1/p' | head -1)
|
||
|
|
|
||
|
|
[ -n "$current_wp" ] || { echo "Could not read the current WordPress version." >&2; exit 1; }
|
||
|
|
|
||
|
|
readme=
|
||
|
|
for f in readme.txt README.txt; do [ -f "$f" ] && readme=$f && break; done
|
||
|
|
|
||
|
|
changed=()
|
||
|
|
|
||
|
|
if [ -n "$readme" ]; then
|
||
|
|
tested_wp=$(sed -n -E 's/^Tested up to:[[:space:]]*([^[:space:]]+).*/\1/p' "$readme" | head -1)
|
||
|
|
if [ "$tested_wp" != "$current_wp" ]; then
|
||
|
|
sed -i -E "s/^Tested up to:.*/Tested up to: $current_wp/" "$readme"
|
||
|
|
changed+=("WordPress ${tested_wp:-?} → $current_wp")
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ "$NEEDS_WOOCOMMERCE" = yes ] && [ -n "$current_wc" ]; then
|
||
|
|
tested_wc=$(ci_plugin_header 'WC tested up to')
|
||
|
|
if [ "$tested_wc" != "$current_wc" ]; then
|
||
|
|
sed -i -E "s/^([[:space:]]*\*[[:space:]]*WC tested up to:).*/\1 $current_wc/" "$PLUGIN_MAIN"
|
||
|
|
[ -n "$readme" ] && sed -i -E "s/^WC tested up to:.*/WC tested up to: $current_wc/" "$readme"
|
||
|
|
changed+=("WooCommerce ${tested_wc:-?} → $current_wc")
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ ${#changed[@]} -eq 0 ]; then
|
||
|
|
echo "The compatibility headers are already current — nothing to do."
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Re-read from disk rather than trusting the sed: a pattern that matched
|
||
|
|
# nothing would otherwise produce an empty, cheerful pull request.
|
||
|
|
for f in "$PLUGIN_MAIN" ${readme:+"$readme"}; do
|
||
|
|
git diff --quiet -- "$f" && continue
|
||
|
|
echo "--- $f"
|
||
|
|
git diff -- "$f" | sed -n '/^[+-][^+-]/p'
|
||
|
|
done
|
||
|
|
git diff --quiet && { echo "Nothing actually changed on disk — check the sed patterns." >&2; exit 1; }
|
||
|
|
|
||
|
|
branch="compat/tested-up-to-$current_wp-wc-$current_wc"
|
||
|
|
git config user.name "compatibility check"
|
||
|
|
git config user.email "noreply@localhost"
|
||
|
|
git checkout -b "$branch"
|
||
|
|
git commit -am "Tested against WordPress $current_wp and WooCommerce $current_wc
|
||
|
|
|
||
|
|
$(printf '%s\n' "${changed[@]}")
|
||
|
|
|
||
|
|
The compatibility matrix went green against these versions before this
|
||
|
|
was written, so the headers now say what was actually tested. WooCommerce
|
||
|
|
shows the 'WC tested up to' value to the shop owner as an untested-plugin
|
||
|
|
banner, which is what they read before deciding whether to press update."
|
||
|
|
|
||
|
|
git push -u origin "$branch"
|
||
|
|
|
||
|
|
gh pr create \
|
||
|
|
--title "Tested against WordPress $current_wp and WooCommerce $current_wc" \
|
||
|
|
--body "$(printf 'The weekly compatibility run passed against the current releases, so the headers are updated to match:\n\n%s\n\nOpened automatically by `ci/bump-tested-up-to.sh`. The versions here were tested before this PR existed; if the matrix had failed, the job that opens this would not have run.\n' "$(printf -- '- %s\n' "${changed[@]}")")"
|