Skip to content

Commit 2997ef1

Browse files
committed
chore: add pre-push tag version validation
Add check-tag-version.sh script and GrumPHP pre-push hook to prevent pushing tags that don't match ext_emconf.php version. Catches mismatches locally before the server-side TER publish workflow fails. Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
1 parent b45283a commit 2997ef1

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Build/Scripts/check-tag-version.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
# Validates that ext_emconf.php version matches any semver tag pointing at HEAD.
3+
# Used as a CaptainHook pre-push hook to prevent pushing mismatched versions.
4+
set -euo pipefail
5+
6+
# Find semver tags (with or without v prefix) pointing at HEAD, normalize to bare version
7+
TAGS=$(git tag --points-at HEAD | sed -nE 's/^v?([0-9]+\.[0-9]+\.[0-9]+)$/\1/p' || true)
8+
9+
if [[ -z "${TAGS}" ]]; then
10+
# No semver tag at HEAD — nothing to validate
11+
exit 0
12+
fi
13+
14+
# Extract version from ext_emconf.php (portable sed instead of grep -P)
15+
EMCONF_VERSION=$(sed -nE "s/.*'version'[[:space:]]*=>[[:space:]]*'([^']+)'.*/\1/p" ext_emconf.php)
16+
17+
if [[ -z "${EMCONF_VERSION}" ]]; then
18+
echo "ERROR: Could not extract version from ext_emconf.php" >&2
19+
exit 1
20+
fi
21+
22+
# Check if ext_emconf.php version matches any of the tags at HEAD
23+
if ! echo "${TAGS}" | grep -qFx -e "${EMCONF_VERSION}"; then
24+
echo "ERROR: ext_emconf.php version (${EMCONF_VERSION}) does not match any semver tag at HEAD." >&2
25+
echo "Tags found at HEAD:" >&2
26+
echo "${TAGS}" >&2
27+
echo "Update ext_emconf.php version to match the tag and amend your commit before pushing." >&2
28+
exit 1
29+
fi
30+
31+
echo "Version check passed: ext_emconf.php (${EMCONF_VERSION}) matches tag(s)"

grumphp.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ grumphp:
6464
lockfile: composer.lock
6565
run_always: true
6666

67+
# Tag version validation (pre-push only)
68+
shell:
69+
scripts:
70+
- Build/Scripts/check-tag-version.sh
71+
triggered_by: [php]
72+
6773
# Testsuites for manual runs
6874
testsuites:
6975
git_pre_commit:
@@ -78,3 +84,7 @@ grumphp:
7884
git_commit_msg:
7985
tasks:
8086
- git_commit_message
87+
88+
git_pre_push:
89+
tasks:
90+
- shell

0 commit comments

Comments
 (0)