-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpre-push
More file actions
executable file
·111 lines (101 loc) · 4.85 KB
/
pre-push
File metadata and controls
executable file
·111 lines (101 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
#ddev-generated
# ── Skip all checks for projects not yet live ────────────────────────────────
ENV_FILE="$(git rev-parse --show-toplevel)/.ddev/.env.anner"
LIVE=$(grep -E '^LIVE=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2 | tr -d '"')
if [[ -z "$LIVE" ]]; then
echo "⚠️ LIVE is not set in .ddev/.env.anner, assuming live project."
fi
# ── Skip all checks when pushing a tag ───────────────────────────────────────
# Check stdin refs from git
PUSH_REFS=$(cat)
if echo "$PUSH_REFS" | grep -q 'refs/tags/'; then
exit 0
fi
# Fallback: check parent git process was invoked with --tags (Linux)
if tr '\0' '\n' < /proc/$PPID/cmdline 2>/dev/null | grep -qxF -- '--tags'; then
exit 0
fi
# ── Composer validate ────────────────────────────────────────────────────────
ddev composer validate --no-check-all --no-check-publish 2>&1
if [[ $? -ne 0 ]]; then
echo ""
echo "🚫 Push aborted: fix composer.json/lock issues above before pushing."
exit 1
fi
# ── Sanity check ─────────────────────────────────────────────────────────────
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
ddev sanity-check -s
if [[ $? -ne 0 ]]; then
echo ""
if [[ "$CURRENT_BRANCH" == "dev" ]]; then
echo "⚠️ Sanity-check failed on 'dev' branch - pushing anyway."
else
read -p "⚠️ Sanity-check failed. Continue pushing anyway? (y/N): " sanity_confirm </dev/tty
sanity_confirm=${sanity_confirm:-N}
if [[ ! "$sanity_confirm" =~ ^[Yy] ]]; then
echo "🚫 Push aborted: fix the issues above and try again."
exit 1
fi
fi
fi
# ── Backstop tests check ────────────────────────────────────────────────────
if [[ "$LIVE" != "0" ]] && [ -f "tests/backstop/backstop.json" ] && [[ "$CURRENT_BRANCH" != "dev" ]]; then
BASE_DIR="tests/backstop/backstop_data/bitmaps_test"
TODAY=$(date +%Y%m%d)
MATCH=$(find "$BASE_DIR" -maxdepth 1 -type d -name "${TODAY}-*" 2>/dev/null)
if [ -z "$MATCH" ]; then
echo ""
echo "=================================================================================================="
echo "⚠️ No Backstop test folder found for today ($TODAY) in $BASE_DIR"
echo "Did you run Backstop and other tests?"
echo "=================================================================================================="
echo ""
read -p "Continue pushing without Backstop tests? (y/N): " backstop_confirm </dev/tty
backstop_confirm=${backstop_confirm:-N}
if [[ ! "$backstop_confirm" =~ ^[Yy] ]]; then
echo "🚫 Push aborted. Run Backstop and other tests or use --no-verify to skip this check."
exit 1
fi
fi
fi
# ── Main/master branch protection ───────────────────────────────────────────
if [[ "$CURRENT_BRANCH" == "main" || "$CURRENT_BRANCH" == "master" ]]; then
echo ""
echo "=================================================================================================="
echo "⚠️ You are about to push directly to '$CURRENT_BRANCH'."
echo "=================================================================================================="
echo ""
read -p "Are you sure you want to push to '$CURRENT_BRANCH'? (type 'yes' to confirm): " main_confirm </dev/tty
if [[ "$main_confirm" != "yes" ]]; then
echo "🚫 Push aborted."
exit 1
fi
# Offer backup if upstream is platform/upsun
UPSTREAM_PROVIDER=""
ENV_FILE="$(git rev-parse --show-toplevel)/.ddev/.env.anner"
if [ -f "$ENV_FILE" ]; then
UPSTREAM_PROVIDER=$(grep -E '^DDEV_UPSTREAM_PROVIDER=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2 | tr -d '"')
fi
if [[ "$UPSTREAM_PROVIDER" == "platform" || "$UPSTREAM_PROVIDER" == "upsun" ]]; then
echo ""
read -p "Create a backup of the '$CURRENT_BRANCH' environment on ${UPSTREAM_PROVIDER}? (Y/n): " backup_confirm </dev/tty
backup_confirm=${backup_confirm:-Y}
if [[ "$backup_confirm" =~ ^[Yy] ]]; then
echo "⏳ Creating backup..."
ddev exec upsun backup -e "$CURRENT_BRANCH"
if [[ $? -ne 0 ]]; then
echo ""
read -p "⚠️ Backup failed. Continue pushing anyway? (y/N): " backup_fail_confirm </dev/tty
backup_fail_confirm=${backup_fail_confirm:-N}
if [[ ! "$backup_fail_confirm" =~ ^[Yy] ]]; then
echo "🚫 Push aborted."
exit 1
fi
else
echo "✅ Backup created."
fi
fi
fi
fi
exit 0