104 lines
2.5 KiB
Bash
Executable File
104 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
STYLEGUIDE_REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
SOURCE_CSS="$STYLEGUIDE_REPO_ROOT/styleguide.css"
|
|
VERSION_FILE="$STYLEGUIDE_REPO_ROOT/VERSION"
|
|
|
|
PORTAL_REPO_PATH=""
|
|
PORTAL_CSS_REL="public/assets/styleguide.upstream.css"
|
|
PORTAL_META_REL="public/assets/styleguide.upstream.meta.json"
|
|
COMMIT_IN_PORTAL="false"
|
|
|
|
usage() {
|
|
cat <<USAGE
|
|
Usage:
|
|
$(basename "$0") --portal-repo <path> [--commit-portal]
|
|
|
|
Options:
|
|
--portal-repo <path> Absolute path to portal repository root.
|
|
--commit-portal Create commit in portal repo after sync.
|
|
-h, --help Show this help.
|
|
USAGE
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--portal-repo)
|
|
PORTAL_REPO_PATH="${2:-}"
|
|
shift 2
|
|
;;
|
|
--commit-portal)
|
|
COMMIT_IN_PORTAL="true"
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown argument: $1" >&2
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$PORTAL_REPO_PATH" ]]; then
|
|
echo "Missing required argument: --portal-repo" >&2
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$SOURCE_CSS" ]]; then
|
|
echo "Source CSS not found: $SOURCE_CSS" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$VERSION_FILE" ]]; then
|
|
echo "Version file not found: $VERSION_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -d "$PORTAL_REPO_PATH/.git" ]]; then
|
|
echo "Portal repo is not a git repository: $PORTAL_REPO_PATH" >&2
|
|
exit 1
|
|
fi
|
|
|
|
PORTAL_CSS_PATH="$PORTAL_REPO_PATH/$PORTAL_CSS_REL"
|
|
PORTAL_META_PATH="$PORTAL_REPO_PATH/$PORTAL_META_REL"
|
|
|
|
mkdir -p "$(dirname "$PORTAL_CSS_PATH")"
|
|
|
|
cp "$SOURCE_CSS" "$PORTAL_CSS_PATH"
|
|
|
|
STYLEGUIDE_VERSION="$(tr -d '[:space:]' < "$VERSION_FILE")"
|
|
STYLEGUIDE_COMMIT="$(git -C "$STYLEGUIDE_REPO_ROOT" rev-parse --short HEAD)"
|
|
SYNCED_AT="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
|
|
|
|
cat > "$PORTAL_META_PATH" <<META
|
|
{
|
|
"styleguideVersion": "$STYLEGUIDE_VERSION",
|
|
"styleguideCommit": "$STYLEGUIDE_COMMIT",
|
|
"syncedAtUtc": "$SYNCED_AT",
|
|
"sourceRepo": "$STYLEGUIDE_REPO_ROOT"
|
|
}
|
|
META
|
|
|
|
if [[ "$COMMIT_IN_PORTAL" == "true" ]]; then
|
|
git -C "$PORTAL_REPO_PATH" add "$PORTAL_CSS_REL" "$PORTAL_META_REL"
|
|
if ! git -C "$PORTAL_REPO_PATH" diff --cached --quiet; then
|
|
git -C "$PORTAL_REPO_PATH" commit -m "Sync styleguide $STYLEGUIDE_VERSION"
|
|
git -C "$PORTAL_REPO_PATH" push
|
|
echo "Portal repo synced and pushed."
|
|
else
|
|
echo "No changes to commit in portal repo."
|
|
fi
|
|
else
|
|
echo "Portal files updated locally (no commit requested)."
|
|
fi
|
|
|
|
echo "Synced $SOURCE_CSS -> $PORTAL_CSS_PATH"
|
|
echo "Metadata written: $PORTAL_META_PATH"
|