Skip to content

Instantly share code, notes, and snippets.

@aslakhellesoy
Last active September 19, 2021 15:45
Show Gist options
  • Save aslakhellesoy/3cb73d9b69c28b497710b78baf0d3ec5 to your computer and use it in GitHub Desktop.
Save aslakhellesoy/3cb73d9b69c28b497710b78baf0d3ec5 to your computer and use it in GitHub Desktop.
This script fixes tags as part of https://github.com/cucumber/common/issues/1724
#!/usr/bin/env bash
#
# This script creates a new repository from a directory in the common monorepo.
# See https://github.com/cucumber/common/issues/1724
#
# Prerequisites:
# * brew install git-filter-repo
#
# Usage: make-polyglot-repo.sh name
# Example: make-polyglot-repo.sh cucumber-expressions
name=$1
mkdir "${name}"
cd "${name}"
git init
git remote add common git@github.com:cucumber/common.git
git fetch common
git checkout -b tmp-migrate common/main
git filter-repo --subdirectory-filter "${name}" --force
git branch -m main
# Creates new X and go/X tags
# Usage: git-move-tags old new
function git-move-tags() {
git tag "$2" "$1"
git tag "go/$2" "$1"
git tag -d "$1"
}
export -f git-move-tags
# Move xxx/v1.2.3 tags
git tag | \
grep "${name}/v" | \
sed "p;s/${name}\///" | \
xargs -n2 bash -c 'git-move-tags "$@"' _
# Move xxx-v1.2.3 tags (legacy tag scheme)
git tag | \
grep "${name}-" | \
sed "p;s/${name}-//" | \
xargs -n2 bash -c 'git-move-tags "$@"' _
# Delete all other tags
git tag | grep --invert-match -E '^go/v\d|^v\d' | \
xargs -n1 git tag -d
# Modify CHANGELOG.md links. Remove the '' if not on MacOS.
sed -i '' "s|${name}-||g" CHANGELOG.md
sed -i '' "s|${name}/||g" CHANGELOG.md
sed -i '' "s|https://github.com/cucumber/common/compare|https://github.com/cucumber/${name}/compare|" CHANGELOG.md
sed -i '' "s|https://github.com/cucumber/cucumber/compare|https://github.com/cucumber/${name}/compare|" CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment