-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-brand.sh
More file actions
75 lines (66 loc) · 2.27 KB
/
Copy pathpublish-brand.sh
File metadata and controls
75 lines (66 loc) · 2.27 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
#!/bin/bash
# publish-brand.sh — Build a brand and push it to its GitHub repo.
#
# Usage: bash publish-brand.sh <brand>
# e.g. bash publish-brand.sh goblin
#
# Prerequisites: gh CLI authenticated, target repo must exist on GitHub.
set -euo pipefail
BRAND="${1:?Usage: publish-brand.sh <brand>}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BRAND_DIR="$SCRIPT_DIR/brands/$BRAND"
DIST="$SCRIPT_DIR/dist/$BRAND"
PUBLISH_DIR="$SCRIPT_DIR/dist/.publish-${BRAND}"
# Load brand config
if [ ! -f "$BRAND_DIR/brand.conf" ]; then
echo "ERROR: brands/$BRAND/brand.conf not found." >&2
exit 1
fi
# shellcheck source=/dev/null
source "$BRAND_DIR/brand.conf"
# Step 1: Build
echo "=== Building $BRAND_NAME ==="
bash "$SCRIPT_DIR/build-brand.sh" "$BRAND"
echo ""
# Step 2: Clone or update the target repo
echo "=== Publishing to $BRAND_GH_URL ==="
if [ -d "$PUBLISH_DIR/.git" ]; then
echo " Updating existing clone..."
cd "$PUBLISH_DIR"
git fetch origin 2>/dev/null || true
git reset --hard origin/main 2>/dev/null || git reset --hard HEAD
cd "$SCRIPT_DIR"
else
rm -rf "$PUBLISH_DIR"
if ! gh repo view "$BRAND_GH_ORG/$BRAND_GH_REPO" >/dev/null 2>&1; then
echo " Repo not found. Creating $BRAND_GH_ORG/$BRAND_GH_REPO..."
gh repo create "$BRAND_GH_ORG/$BRAND_GH_REPO" --public --description "$BRAND_TAGLINE"
fi
# Clone; if repo is empty, init locally instead
if ! git clone "$BRAND_GH_URL.git" "$PUBLISH_DIR" 2>/dev/null; then
echo " Empty repo, initializing locally..."
mkdir -p "$PUBLISH_DIR"
cd "$PUBLISH_DIR"
git init -b main
git remote add origin "$BRAND_GH_URL.git"
cd "$SCRIPT_DIR"
fi
fi
# Step 3: Sync dist into the publish directory (preserve .git)
# Remove everything except .git, then copy fresh from dist
find "$PUBLISH_DIR" -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
cp -r "$DIST"/. "$PUBLISH_DIR/"
# Step 4: Commit and push
cd "$PUBLISH_DIR"
TAS_HASH=$(cd "$SCRIPT_DIR" && git rev-parse --short HEAD 2>/dev/null || echo "unknown")
git add -A
if git diff --cached --quiet 2>/dev/null; then
echo " No changes to publish."
else
git commit -m "sync: upstream $TAS_HASH"
git push -u origin HEAD 2>/dev/null || git push --set-upstream origin main
echo ""
echo " Published to $BRAND_GH_URL"
fi
cd "$SCRIPT_DIR"
echo "Done."