#!/usr/bin/env bash set -euo pipefail CURRENT_BRANCH="${SPLIT_BRANCH:-${GITHUB_REF_NAME:-$(git rev-parse --abbrev-ref HEAD)}}" BASEPATH="$(cd "$(dirname "$0")"; cd ../plugin/; pwd)" REPOS=("$@") case "$CURRENT_BRANCH" in v6-dev|v8-dev) ;; *) echo "Only v6-dev and v8-dev are allowed to split, current: ${CURRENT_BRANCH}" >&2 exit 1 ;; esac remote() { local name="$1" local url="$2" if git remote get-url "$name" >/dev/null 2>&1; then git remote set-url "$name" "$url" else git remote add "$name" "$url" fi } split_branch() { local repo="$1" local prefix="plugin/${repo}" local sha1 sha1="$(.github/splitsh-lite-linux --prefix="$prefix")" echo "Split ${prefix} => ${sha1}, push branch ${CURRENT_BRANCH}" git push "$repo" "${sha1}:refs/heads/${CURRENT_BRANCH}" -f } if [[ ${#REPOS[@]} -eq 0 ]]; then while IFS= read -r repo; do REPOS+=("$repo") done < <(find "$BASEPATH" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort) fi if [[ -n "${GITHUB_ACTIONS:-}" ]]; then git fetch origin "$CURRENT_BRANCH" || true else git pull --ff-only origin "$CURRENT_BRANCH" fi for repo in "${REPOS[@]}"; do remote "$repo" "git@github.com:zoujingli/${repo}.git" split_branch "$repo" done