56 lines
1.7 KiB
Bash
56 lines
1.7 KiB
Bash
# Shared helpers for the ci/ scripts. Sourced, never executed.
|
|||
|
|
#
|
||
|
|
# Nothing in here is specific to one plugin — ci/plugin.conf holds that.
|
||
|
|
|
||
|
|
# shellcheck shell=bash
|
||
|
|
|
||
|
|
ci_repo_root() {
|
||
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd
|
||
|
|
}
|
||
|
|
|
||
|
|
# Load ci/plugin.conf and fail loudly on anything it forgot to set. A missing
|
||
|
|
# value would otherwise turn into an empty path and a test that passes by
|
||
|
|
# testing nothing.
|
||
|
|
ci_load_conf() {
|
||
|
|
local root
|
||
|
|
root="$(ci_repo_root)"
|
||
|
|
|
||
|
|
# shellcheck source=/dev/null
|
||
|
|
. "$root/ci/plugin.conf"
|
||
|
|
|
||
|
|
local missing=
|
||
|
|
for var in PLUGIN_SLUG PLUGIN_MAIN TEXT_DOMAIN NEEDS_WOOCOMMERCE; do
|
||
|
|
[ -n "${!var:-}" ] || missing="$missing $var"
|
||
|
|
done
|
||
|
|
if [ -n "$missing" ]; then
|
||
|
|
echo "ci/plugin.conf is missing:$missing" >&2
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ ! -f "$root/$PLUGIN_MAIN" ]; then
|
||
|
|
echo "ci/plugin.conf points PLUGIN_MAIN at '$PLUGIN_MAIN', which does not exist." >&2
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
# The version WordPress will compare against the update feed. Read from the
|
||
|
|
# plugin header, which is the only copy WordPress ever looks at.
|
||
|
|
ci_plugin_version() {
|
||
|
|
sed -n -E 's/^[[:space:]]*\*?[[:space:]]*Version:[[:space:]]*([^[:space:]]+).*/\1/p' \
|
||
|
|
"$(ci_repo_root)/$PLUGIN_MAIN" | head -1
|
||
|
|
}
|
||
|
|
|
||
|
|
# Read any other plugin header field, e.g. ci_plugin_header 'Requires at least'.
|
||
|
|
ci_plugin_header() {
|
||
|
|
sed -n -E "s/^[[:space:]]*\*?[[:space:]]*$1:[[:space:]]*(.*)/\1/p" \
|
||
|
|
"$(ci_repo_root)/$PLUGIN_MAIN" | head -1 | sed -E 's/[[:space:]]+$//'
|
||
|
|
}
|
||
|
|
|
||
|
|
ci_step() { printf '\n\033[1m→ %s\033[0m\n' "$*"; }
|
||
|
|
ci_fail() { printf '\033[31mFAIL\033[0m %s\n' "$*" >&2; }
|
||
|
|
|
||
|
|
# GitHub and Gitea both render these as annotations on the file and line.
|
||
|
|
ci_annotate() { # level file line message
|
||
|
|
printf '::%s file=%s,line=%s::%s\n' "$1" "$2" "$3" "$4"
|
||
|
|
}
|