#!/usr/bin/env bash set -euo pipefail if [[ $# -lt 1 ]]; then echo "Usage: $0 [release-branch] [repo ...]" >&2 exit 1 fi VERSION="$1" shift if [[ $# -gt 0 && "$1" =~ ^v[0-9]+-dev$ ]]; then RELEASE_BRANCH="$1" shift else RELEASE_BRANCH="${RELEASE_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}" fi case "$VERSION" in v6.*) EXPECTED_BRANCH="v6-dev" ;; v8.*) EXPECTED_BRANCH="v8-dev" ;; *) echo "Only v6.* and v8.* tags are allowed, current: ${VERSION}" >&2 exit 1 ;; esac if [[ "$RELEASE_BRANCH" != "$EXPECTED_BRANCH" ]]; then echo "Tag ${VERSION} must be released from ${EXPECTED_BRANCH}, current: ${RELEASE_BRANCH}" >&2 exit 1 fi BASEPATH="$(cd "$(dirname "$0")"; cd ../plugin/; pwd)" REPOS=("$@") 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 } push_split_release() { local repo="$1" local prefix="plugin/${repo}" local sha1 remote_tag sha1="$(.github/splitsh-lite-linux --prefix="$prefix")" echo "Release ${prefix} => ${sha1}, branch ${RELEASE_BRANCH}, tag ${VERSION}" git push "$repo" "${sha1}:refs/heads/${RELEASE_BRANCH}" -f remote_tag="$(git ls-remote --tags "$repo" "refs/tags/${VERSION}" | awk '{print $1}' || true)" if [[ -n "$remote_tag" ]]; then if [[ "$remote_tag" == "$sha1" ]]; then echo "Tag ${VERSION} already exists on ${repo} at ${sha1}, skip." return fi echo "Tag ${VERSION} already exists on ${repo} at ${remote_tag}, expected ${sha1}. Refuse to overwrite." >&2 exit 1 fi git push "$repo" "${sha1}:refs/tags/${VERSION}" } 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 for repo in "${REPOS[@]}"; do remote "$repo" "git@github.com:zoujingli/${repo}.git" push_split_release "$repo" done