Skip to content

Commit a81bd23

Browse files
committed
Add release helper with commit option
1 parent 009c1e8 commit a81bd23

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

scripts/release.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
usage() {
5+
cat <<'EOF'
6+
Usage:
7+
scripts/release.sh --master [--date YYYY-MM-DD] [--no-fetch] [--commit SHA]
8+
scripts/release.sh --dev [--date YYYY-MM-DD] [--no-fetch] [--commit SHA]
9+
10+
Options:
11+
--master Build from ProcessWire master branch
12+
--dev Build from ProcessWire dev branch
13+
--date Override release date used by the workflow
14+
--no-fetch Do not refresh ProcessWire source (skip --fetch)
15+
--commit Checkout specific ProcessWire commit before building docs
16+
EOF
17+
}
18+
19+
branch=""
20+
date_override=""
21+
fetch_flag="--fetch"
22+
commit_sha=""
23+
commit_flag=0
24+
25+
while [[ $# -gt 0 ]]; do
26+
case "$1" in
27+
--master)
28+
branch="master"
29+
;;
30+
--dev)
31+
branch="dev"
32+
;;
33+
--date)
34+
shift
35+
date_override="${1:-}"
36+
;;
37+
--no-fetch)
38+
fetch_flag=""
39+
;;
40+
--commit)
41+
shift
42+
commit_sha="${1:-}"
43+
commit_flag=1
44+
;;
45+
-h|--help)
46+
usage
47+
exit 0
48+
;;
49+
*)
50+
echo "Unknown option: $1" >&2
51+
usage
52+
exit 1
53+
;;
54+
esac
55+
shift
56+
done
57+
58+
if [[ -z "$branch" ]]; then
59+
echo "Error: choose --master or --dev" >&2
60+
usage
61+
exit 1
62+
fi
63+
64+
if [[ "$commit_flag" -eq 1 && -z "$commit_sha" ]]; then
65+
echo "Error: --commit requires a SHA" >&2
66+
usage
67+
exit 1
68+
fi
69+
70+
if ! command -v gh >/dev/null 2>&1; then
71+
echo "Error: gh not found. Install GitHub CLI first." >&2
72+
exit 1
73+
fi
74+
75+
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
76+
cd "$repo_root"
77+
78+
if ! git diff --quiet || ! git diff --cached --quiet; then
79+
echo "Error: working tree not clean. Commit or stash changes first." >&2
80+
exit 1
81+
fi
82+
83+
if [[ -n "$commit_sha" ]]; then
84+
sync_args=(--branch "$branch")
85+
if [[ -z "$fetch_flag" ]]; then
86+
sync_args+=(--no-update)
87+
fi
88+
python3 src/sync_processwire.py "${sync_args[@]}"
89+
90+
if ! git -C sources/processwire diff --quiet || ! git -C sources/processwire diff --cached --quiet; then
91+
echo "Error: sources/processwire has uncommitted changes." >&2
92+
exit 1
93+
fi
94+
95+
git -C sources/processwire checkout "$commit_sha"
96+
resolved_commit=$(git -C sources/processwire rev-parse HEAD)
97+
printf "branch=%s\ncommit=%s\n" "$branch" "$resolved_commit" > sources/processwire.lock
98+
99+
python3 src/update_docs.py --branch "$branch"
100+
else
101+
python3 src/update_docs.py --branch "$branch" $fetch_flag
102+
fi
103+
104+
version=$(python3 - <<'PY'
105+
import json
106+
from pathlib import Path
107+
meta = Path('docs/_processwire_version.json')
108+
if not meta.exists():
109+
raise SystemExit('docs/_processwire_version.json not found')
110+
print(json.loads(meta.read_text(encoding='utf-8')).get('version') or 'unknown')
111+
PY
112+
)
113+
114+
git add -A
115+
if git diff --cached --quiet; then
116+
echo "No changes to commit."
117+
else
118+
git commit -m "Update docs for ProcessWire $branch $version"
119+
git push
120+
fi
121+
122+
if [[ -n "$date_override" ]]; then
123+
gh workflow run Release -R phlppschrr/processwire-knowledge-base -f date="$date_override"
124+
else
125+
gh workflow run Release -R phlppschrr/processwire-knowledge-base
126+
fi
127+
128+
echo "Release workflow triggered for $branch ($version)."

0 commit comments

Comments
 (0)