From 61a3bb607cee62b4abb800f0c6cecfb660c61bce Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Mon, 3 Apr 2023 15:24:04 -0700 Subject: [PATCH 01/11] feat: adds script. --- .../git-migrate-history.sh | 146 ++++++++++++++++++ scripts/split_repo_migration/run.sh | 54 +++++++ 2 files changed, 200 insertions(+) create mode 100755 scripts/split_repo_migration/git-migrate-history.sh create mode 100644 scripts/split_repo_migration/run.sh diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh new file mode 100755 index 000000000000..c3ab951452ea --- /dev/null +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -0,0 +1,146 @@ +#!/bin/bash +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -ex + +if [ $# -lt 4 ] +then + echo "Usage: $0 [folders,to,skip] [files,to,keep] [branch-name]" + exit 1 +fi + +# source GitHub repository. format: / +SOURCE_REPO=$1 + +# destination GitHub repository. format: / +TARGET_REPO=$2 + +# path in the source repo to copy code from. Defaults to the root directory +SOURCE_PATH=$3 + +# path in the target repo to put the copied code +TARGET_PATH=$4 + +# comma-separated list of files/folders to skip +IGNORE_FOLDERS=$5 +# keep these specific files that would otherwise be deleted by IGNORE_FOLDERS +KEEP_FILES=$6 + +# override the HEAD branch name for the migration PR +BRANCH=$7 + +if [[ ! -z "${UPDATE_SCRIPT}" ]] +then + UPDATE_SCRIPT=$(realpath "${UPDATE_SCRIPT}") +fi + +if [[ -z "${BRANCH}" ]] +then + # default the branch name to be generated from the source repo name + BRANCH=$(basename ${SOURCE_REPO})-migration +fi +echo "here" +export FILTER_BRANCH_SQUELCH_WARNING=1 + +# create a working directory +WORKDIR=$(mktemp -d -t code-migration-XXXXXXXXXX) +echo "Created working directory: ${WORKDIR}" + +pushd "${WORKDIR}" # cd into workdir + +echo "Cloning source repository: ${SOURCE_REPO}" +git clone "git@github.com:${SOURCE_REPO}.git" source-repo + +pushd source-repo +git remote remove origin + +# prune only files within the specified directory +if [[ ! -z "${SOURCE_PATH}" ]] +then + echo "Pruning commits only including path: ${SOURCE_PATH}" + git filter-branch \ # rewrites history... unsafe + --prune-empty \ + --subdirectory-filter "${SOURCE_PATH}" +fi + +if [[ ! -z "${IGNORE_FOLDERS}" ]] +then + echo "Ignoring folder: ${IGNORE_FOLDERS}" + mkdir -p ${WORKDIR}/filtered-source + FOLDERS=$(echo ${IGNORE_FOLDERS} | tr "," " ") + # remove files/folders we don't want + FILTER="(rm -rf ${FOLDERS} || true)" + if [[ ! -z "${KEEP_FILES}" ]] + then + KEEP_FILES_SPACES=($(echo ${KEEP_FILES} | tr "," " ")) + LAST_ELEMENT=$(( ${#KEEP_FILES_SPACES[@]} - 1 )) + KEEP_FILE_COMMANDS="" + for file in "${KEEP_FILES_SPACES[@]}" + do + if [[ $file == "${KEEP_FILES_SPACES[$LAST_ELEMENT]}" ]] + then + KEEP_FILE_COMMANDS+="git checkout -- ${file} 2>/dev/null || true" + else + KEEP_FILE_COMMANDS+="git checkout -- ${file} 2>/dev/null || true; " + fi + done + # restore files to keep, silence errors if the file doesn't exist + FILTER="${FILTER}; ${KEEP_FILE_COMMANDS}" + fi + git filter-branch \ + --force \ + --prune-empty \ + --tree-filter "${FILTER}" +fi + +# reorganize the filtered code into the desired target locations +if [[ ! -z "${TARGET_PATH}" ]] +then + echo "Moving files to destination path: ${TARGET_PATH}" + git filter-branch \ + --force \ + --prune-empty \ + --tree-filter \ + "shopt -s dotglob; mkdir -p ${WORKDIR}/migrated-source; mv * ${WORKDIR}/migrated-source; mkdir -p ${TARGET_PATH}; mv ${WORKDIR}/migrated-source/* ${TARGET_PATH}" +fi + +# back to workdir +popd + +# merge histories +echo "Cloning target repository: ${SOURCE_REPO}" +git clone "git@github.com:${TARGET_REPO}.git" target-repo +pushd target-repo + +git remote add --fetch migration ../source-repo +git checkout -b "${BRANCH}" +git merge --allow-unrelated-histories migration/main --no-edit + +if [[ ! -z "${UPDATE_SCRIPT}" ]] +then + bash "${UPDATE_SCRIPT}" +fi +echo "Success" +# git push -u origin "${BRANCH}" --force + +# # create pull request +# if gh --help > /dev/null +# then +# gh pr create --title "migrate code from ${SOURCE_REPO}" +# else +# hub pull-request -m "migrate code from ${SOURCE_REPO}" +# fi + +popd \ No newline at end of file diff --git a/scripts/split_repo_migration/run.sh b/scripts/split_repo_migration/run.sh new file mode 100644 index 000000000000..bd40af6cf710 --- /dev/null +++ b/scripts/split_repo_migration/run.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +if [ $# -lt 2 ] +then + echo "Usage: $0 " + exit 1 +fi + +# repo name (e.g. nodejs-asset) +SPLIT_REPO=$1 +# destination directory (e.g. google-cloud-asset) +ARTIFACT_NAME=$2 + +## Get the directory of the build script +SCRIPT_DIR=$(realpath $(dirname "${BASH_SOURCE[0]}")) + +#export UPDATE_SCRIPT="${SCRIPT_DIR}/split-repo-post-process.sh" +export PACKAGE_PATH="packages/${ARTIFACT_NAME}" + +# Args to migrate git +# 1. source GitHub repository. format: / +# 2. destination GitHub repository. format: / +# 3. path in the source repo to copy code from. Defaults to the root directory +# 4. path in the target repo to put the copied code +# 5. comma-separated list of files/folders to skip +# 6. keep these specific files that would otherwise be deleted by IGNORE_FOLDERS +# 7. override the HEAD branch name for the migration PR + +echo ${PACKAGE_PATH} + +# run the migrate script, remove .kokoro and .github folders +# keep the .github/.OwlBot.yaml config +${SCRIPT_DIR}/git-migrate-history.sh \ + "googleapis/${SPLIT_REPO}" \ + "googleapis/google-cloud-python" \ + "" \ + "${PACKAGE_PATH}" \ + ".kokoro,.github,.trampolinerc,SECURITY.md,renovate.json,samples" \ + ".github/.OwlBot.yaml" From 2c1e1e47a9e90341be7b159b1139f8834e8a15ae Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Thu, 6 Apr 2023 18:35:30 -0700 Subject: [PATCH 02/11] feat: fix some bugs. --- .../git-migrate-history.sh | 23 +++++++++++++++++-- scripts/split_repo_migration/run.sh | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index c3ab951452ea..3e51b6138103 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -133,7 +133,26 @@ then bash "${UPDATE_SCRIPT}" fi echo "Success" -# git push -u origin "${BRANCH}" --force + +popd # back to workdir + +# Do a diff between source code split repl and migrated code. +git clone "git@github.com:${SOURCE_REPO}.git" source-repo-validation # Not ideal to clone again. +rm -rf source-repo-validation/.git # That folder is not needed for validation. + +if diff -r target-repo/"${TARGET_PATH}" source-repo-validation; then + echo "No diff" +else + echo "Diff non-empty" + exit 1 +fi + +pushd target-repo # To target repo + +# Uncomment this to push to branch and create a pull request. +# BRANCH here is something like python-speech-migration. + +# git push -u origin "${BRANCH}" --force # # create pull request # if gh --help > /dev/null diff --git a/scripts/split_repo_migration/run.sh b/scripts/split_repo_migration/run.sh index bd40af6cf710..637c0e2a6282 100644 --- a/scripts/split_repo_migration/run.sh +++ b/scripts/split_repo_migration/run.sh @@ -50,5 +50,5 @@ ${SCRIPT_DIR}/git-migrate-history.sh \ "googleapis/google-cloud-python" \ "" \ "${PACKAGE_PATH}" \ - ".kokoro,.github,.trampolinerc,SECURITY.md,renovate.json,samples" \ + "" \ ".github/.OwlBot.yaml" From fcb0211689477313c351b53fc8c6abcdd4ff4e68 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Thu, 6 Apr 2023 18:52:36 -0700 Subject: [PATCH 03/11] feat: add update script. --- scripts/split_repo_migration/git-migrate-history.sh | 3 +++ scripts/split_repo_migration/run.sh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index 3e51b6138103..fca0ada47275 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -41,6 +41,9 @@ KEEP_FILES=$6 # override the HEAD branch name for the migration PR BRANCH=$7 +# Path for update script for migration postprocessing. +UPDATE_SCRIPT=$8 + if [[ ! -z "${UPDATE_SCRIPT}" ]] then UPDATE_SCRIPT=$(realpath "${UPDATE_SCRIPT}") diff --git a/scripts/split_repo_migration/run.sh b/scripts/split_repo_migration/run.sh index 637c0e2a6282..2d96799a5344 100644 --- a/scripts/split_repo_migration/run.sh +++ b/scripts/split_repo_migration/run.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ export PACKAGE_PATH="packages/${ARTIFACT_NAME}" # 5. comma-separated list of files/folders to skip # 6. keep these specific files that would otherwise be deleted by IGNORE_FOLDERS # 7. override the HEAD branch name for the migration PR +# 8. path for update script. echo ${PACKAGE_PATH} From 39432b13fe0fb9f68b572db5d590924fef3ae856 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Thu, 13 Apr 2023 14:53:01 -0700 Subject: [PATCH 04/11] chore: address pr feedback. --- .../git-migrate-history.sh | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index fca0ada47275..004a54a64b09 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -15,10 +15,12 @@ set -ex +[[ "${BASH_SOURCE[0]}" != "${0}" ]] && EXIT=return || EXIT=exit + if [ $# -lt 4 ] then echo "Usage: $0 [folders,to,skip] [files,to,keep] [branch-name]" - exit 1 + $EXIT 1 fi # source GitHub repository. format: / @@ -41,24 +43,16 @@ KEEP_FILES=$6 # override the HEAD branch name for the migration PR BRANCH=$7 -# Path for update script for migration postprocessing. -UPDATE_SCRIPT=$8 - -if [[ ! -z "${UPDATE_SCRIPT}" ]] -then - UPDATE_SCRIPT=$(realpath "${UPDATE_SCRIPT}") -fi if [[ -z "${BRANCH}" ]] then # default the branch name to be generated from the source repo name BRANCH=$(basename ${SOURCE_REPO})-migration fi -echo "here" export FILTER_BRANCH_SQUELCH_WARNING=1 # create a working directory -WORKDIR=$(mktemp -d -t code-migration-XXXXXXXXXX) +WORKDIR="$(mktemp -d -t code-migration-XXXXXXXXXX)" echo "Created working directory: ${WORKDIR}" pushd "${WORKDIR}" # cd into workdir @@ -81,7 +75,7 @@ fi if [[ ! -z "${IGNORE_FOLDERS}" ]] then echo "Ignoring folder: ${IGNORE_FOLDERS}" - mkdir -p ${WORKDIR}/filtered-source + mkdir -p "${WORKDIR}/filtered-source" FOLDERS=$(echo ${IGNORE_FOLDERS} | tr "," " ") # remove files/folders we don't want FILTER="(rm -rf ${FOLDERS} || true)" @@ -131,15 +125,11 @@ git remote add --fetch migration ../source-repo git checkout -b "${BRANCH}" git merge --allow-unrelated-histories migration/main --no-edit -if [[ ! -z "${UPDATE_SCRIPT}" ]] -then - bash "${UPDATE_SCRIPT}" -fi echo "Success" popd # back to workdir -# Do a diff between source code split repl and migrated code. +# Do a diff between source code split repo and migrated code. git clone "git@github.com:${SOURCE_REPO}.git" source-repo-validation # Not ideal to clone again. rm -rf source-repo-validation/.git # That folder is not needed for validation. @@ -147,7 +137,7 @@ if diff -r target-repo/"${TARGET_PATH}" source-repo-validation; then echo "No diff" else echo "Diff non-empty" - exit 1 + $EXIT 1 fi pushd target-repo # To target repo From 2096df74d759a5096218eb2ea0a1fb049634bfbb Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Thu, 13 Apr 2023 18:03:09 -0700 Subject: [PATCH 05/11] chore: address feedback. --- .../git-migrate-history.sh | 22 +++++++++---------- scripts/split_repo_migration/run.sh | 7 +++--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index 004a54a64b09..d19d77b4b5ac 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -136,23 +136,21 @@ rm -rf source-repo-validation/.git # That folder is not needed for validation. if diff -r target-repo/"${TARGET_PATH}" source-repo-validation; then echo "No diff" else - echo "Diff non-empty" + diff -r target-repo/"${TARGET_PATH}" source-repo-validation > "diff.txt" + echo "Diff non-empty. See ${WORKDIR}/diff.txt" $EXIT 1 fi pushd target-repo # To target repo -# Uncomment this to push to branch and create a pull request. -# BRANCH here is something like python-speech-migration. +git push -u origin "${BRANCH}" --force -# git push -u origin "${BRANCH}" --force - -# # create pull request -# if gh --help > /dev/null -# then -# gh pr create --title "migrate code from ${SOURCE_REPO}" -# else -# hub pull-request -m "migrate code from ${SOURCE_REPO}" -# fi +# create pull request +if gh --help > /dev/null +then + gh pr create --title "migrate code from ${SOURCE_REPO}" +else + hub pull-request -m "migrate code from ${SOURCE_REPO}" +fi popd \ No newline at end of file diff --git a/scripts/split_repo_migration/run.sh b/scripts/split_repo_migration/run.sh index 2d96799a5344..5e461c1f1afb 100644 --- a/scripts/split_repo_migration/run.sh +++ b/scripts/split_repo_migration/run.sh @@ -14,11 +14,13 @@ # limitations under the License. set -e - + +[[ "${BASH_SOURCE[0]}" != "${0}" ]] && EXIT=return || EXIT=exit + if [ $# -lt 2 ] then echo "Usage: $0 " - exit 1 + $EXIT 1 fi # repo name (e.g. nodejs-asset) @@ -29,7 +31,6 @@ ARTIFACT_NAME=$2 ## Get the directory of the build script SCRIPT_DIR=$(realpath $(dirname "${BASH_SOURCE[0]}")) -#export UPDATE_SCRIPT="${SCRIPT_DIR}/split-repo-post-process.sh" export PACKAGE_PATH="packages/${ARTIFACT_NAME}" # Args to migrate git From e336cd390e59aa787b6b6a5d59be39dbd36e25d3 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Tue, 18 Apr 2023 10:41:16 -0700 Subject: [PATCH 06/11] chore: address feedback and change args. --- .../git-migrate-history.sh | 46 +++++++++------ scripts/split_repo_migration/run.sh | 56 ------------------- 2 files changed, 28 insertions(+), 74 deletions(-) delete mode 100644 scripts/split_repo_migration/run.sh diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index d19d77b4b5ac..f89977e44040 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -13,13 +13,25 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Sample usage: +# +# git-migrate-history.sh \ +# "googleapis/python-speech" \ +# "~/temp/google-cloud-python" \ +# "" \ +# "" \ +# ".github/.OwlBot.yaml" +# +# This invocation runs migration script on python-speech, where the source path is root directory, +# nothing is ignored, and .OwlBot.yaml is being kept. + set -ex [[ "${BASH_SOURCE[0]}" != "${0}" ]] && EXIT=return || EXIT=exit -if [ $# -lt 4 ] +if [ $# -lt 3 ] then - echo "Usage: $0 [folders,to,skip] [files,to,keep] [branch-name]" + echo "Usage: $0 [folders,to,skip] [files,to,keep] [branch-name]" $EXIT 1 fi @@ -27,21 +39,19 @@ fi SOURCE_REPO=$1 # destination GitHub repository. format: / -TARGET_REPO=$2 +TARGET_REPO=$2 # Path to google-cloud-python # path in the source repo to copy code from. Defaults to the root directory SOURCE_PATH=$3 -# path in the target repo to put the copied code -TARGET_PATH=$4 - # comma-separated list of files/folders to skip -IGNORE_FOLDERS=$5 +IGNORE_FOLDERS=$4 + # keep these specific files that would otherwise be deleted by IGNORE_FOLDERS -KEEP_FILES=$6 +KEEP_FILES=$5 # override the HEAD branch name for the migration PR -BRANCH=$7 +BRANCH=$6 if [[ -z "${BRANCH}" ]] @@ -102,6 +112,8 @@ then --tree-filter "${FILTER}" fi +TARGET_PATH=$(jq -r '.distribution_name' .repo-metadata.json) # -r removes quotes around the name. + # reorganize the filtered code into the desired target locations if [[ ! -z "${TARGET_PATH}" ]] then @@ -117,12 +129,10 @@ fi popd # merge histories -echo "Cloning target repository: ${SOURCE_REPO}" -git clone "git@github.com:${TARGET_REPO}.git" target-repo -pushd target-repo +pushd $TARGET_REPO -git remote add --fetch migration ../source-repo -git checkout -b "${BRANCH}" +git remote add --fetch migration ${WORKDIR}/source-repo +git checkout -B "${BRANCH}" git merge --allow-unrelated-histories migration/main --no-edit echo "Success" @@ -133,15 +143,15 @@ popd # back to workdir git clone "git@github.com:${SOURCE_REPO}.git" source-repo-validation # Not ideal to clone again. rm -rf source-repo-validation/.git # That folder is not needed for validation. -if diff -r target-repo/"${TARGET_PATH}" source-repo-validation; then +DIFF_FILE="${WORKDIR}/diff.txt" +if diff -r "${TARGET_REPO}/${TARGET_PATH}" source-repo-validation > "${DIFF_FILE}" ; then echo "No diff" else - diff -r target-repo/"${TARGET_PATH}" source-repo-validation > "diff.txt" - echo "Diff non-empty. See ${WORKDIR}/diff.txt" + echo "Diff non-empty. See ${DIFF_FILE}" $EXIT 1 fi -pushd target-repo # To target repo +pushd "${TARGET_REPO}" # To target repo git push -u origin "${BRANCH}" --force diff --git a/scripts/split_repo_migration/run.sh b/scripts/split_repo_migration/run.sh deleted file mode 100644 index 5e461c1f1afb..000000000000 --- a/scripts/split_repo_migration/run.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -[[ "${BASH_SOURCE[0]}" != "${0}" ]] && EXIT=return || EXIT=exit - -if [ $# -lt 2 ] -then - echo "Usage: $0 " - $EXIT 1 -fi - -# repo name (e.g. nodejs-asset) -SPLIT_REPO=$1 -# destination directory (e.g. google-cloud-asset) -ARTIFACT_NAME=$2 - -## Get the directory of the build script -SCRIPT_DIR=$(realpath $(dirname "${BASH_SOURCE[0]}")) - -export PACKAGE_PATH="packages/${ARTIFACT_NAME}" - -# Args to migrate git -# 1. source GitHub repository. format: / -# 2. destination GitHub repository. format: / -# 3. path in the source repo to copy code from. Defaults to the root directory -# 4. path in the target repo to put the copied code -# 5. comma-separated list of files/folders to skip -# 6. keep these specific files that would otherwise be deleted by IGNORE_FOLDERS -# 7. override the HEAD branch name for the migration PR -# 8. path for update script. - -echo ${PACKAGE_PATH} - -# run the migrate script, remove .kokoro and .github folders -# keep the .github/.OwlBot.yaml config -${SCRIPT_DIR}/git-migrate-history.sh \ - "googleapis/${SPLIT_REPO}" \ - "googleapis/google-cloud-python" \ - "" \ - "${PACKAGE_PATH}" \ - "" \ - ".github/.OwlBot.yaml" From a3694e414ff1e31487b0e43414bc30553a612ccb Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Tue, 18 Apr 2023 17:32:32 -0700 Subject: [PATCH 07/11] chore: address pr feedback. --- .../git-migrate-history.sh | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index f89977e44040..9e3ed6186dd7 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -112,7 +112,7 @@ then --tree-filter "${FILTER}" fi -TARGET_PATH=$(jq -r '.distribution_name' .repo-metadata.json) # -r removes quotes around the name. +TARGET_PATH="packages/$(jq -r '.distribution_name' .repo-metadata.json)" # -r removes quotes around the name. # reorganize the filtered code into the desired target locations if [[ ! -z "${TARGET_PATH}" ]] @@ -131,9 +131,10 @@ popd # merge histories pushd $TARGET_REPO -git remote add --fetch migration ${WORKDIR}/source-repo +REMOTE="remote.${SOURCE_REPO}" +git remote add --fetch ${REMOTE} ${WORKDIR}/source-repo git checkout -B "${BRANCH}" -git merge --allow-unrelated-histories migration/main --no-edit +git merge --allow-unrelated-histories ${REMOTE}/main --no-edit echo "Success" @@ -153,14 +154,14 @@ fi pushd "${TARGET_REPO}" # To target repo -git push -u origin "${BRANCH}" --force +# git push -u origin "${BRANCH}" --force -# create pull request -if gh --help > /dev/null -then - gh pr create --title "migrate code from ${SOURCE_REPO}" -else - hub pull-request -m "migrate code from ${SOURCE_REPO}" -fi +# # create pull request +# if gh --help > /dev/null +# then +# gh pr create --title "migrate code from ${SOURCE_REPO}" +# else +# hub pull-request -m "migrate code from ${SOURCE_REPO}" +# fi popd \ No newline at end of file From 57e96dcc01ace9025e60e75f54d2090558e326c0 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Wed, 19 Apr 2023 10:49:45 -0700 Subject: [PATCH 08/11] chore: add gh. --- .../git-migrate-history.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index 9e3ed6186dd7..997041eeb8e9 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -154,14 +154,14 @@ fi pushd "${TARGET_REPO}" # To target repo -# git push -u origin "${BRANCH}" --force - -# # create pull request -# if gh --help > /dev/null -# then -# gh pr create --title "migrate code from ${SOURCE_REPO}" -# else -# hub pull-request -m "migrate code from ${SOURCE_REPO}" -# fi +git push -u origin "${BRANCH}" --force + +# create pull request +if gh --help > /dev/null +then + gh pr create --title "migrate code from ${SOURCE_REPO}" +else + hub pull-request -m "migrate code from ${SOURCE_REPO}" +fi popd \ No newline at end of file From c7c0d485aed84ccaf80c82a09ba2cb6889712729 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Wed, 19 Apr 2023 14:08:34 -0700 Subject: [PATCH 09/11] fix: fix details for post-processor. --- .../git-migrate-history.sh | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index 997041eeb8e9..d0a541f3190a 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -31,7 +31,7 @@ set -ex if [ $# -lt 3 ] then - echo "Usage: $0 [folders,to,skip] [files,to,keep] [branch-name]" + echo "Usage: $0 [folders,to,skip] [files,to,keep] [branch-name] [issue-number]" $EXIT 1 fi @@ -53,6 +53,8 @@ KEEP_FILES=$5 # override the HEAD branch name for the migration PR BRANCH=$6 +# GitHub issue number +ISSUE_NUMBER=$7 if [[ -z "${BRANCH}" ]] then @@ -112,18 +114,16 @@ then --tree-filter "${FILTER}" fi -TARGET_PATH="packages/$(jq -r '.distribution_name' .repo-metadata.json)" # -r removes quotes around the name. +DISTRIBUTION_NAME=$(jq -r '.distribution_name' .repo-metadata.json) # -r removes quotes around the name. +TARGET_PATH="packages/${DISTRIBUTION_NAME}" # reorganize the filtered code into the desired target locations -if [[ ! -z "${TARGET_PATH}" ]] -then - echo "Moving files to destination path: ${TARGET_PATH}" - git filter-branch \ - --force \ - --prune-empty \ - --tree-filter \ - "shopt -s dotglob; mkdir -p ${WORKDIR}/migrated-source; mv * ${WORKDIR}/migrated-source; mkdir -p ${TARGET_PATH}; mv ${WORKDIR}/migrated-source/* ${TARGET_PATH}" -fi +echo "Moving files to destination path: ${TARGET_PATH}" +git filter-branch \ + --force \ + --prune-empty \ + --tree-filter \ + "shopt -s dotglob; mkdir -p ${WORKDIR}/migrated-source; mv * ${WORKDIR}/migrated-source; mkdir -p ${TARGET_PATH}; mv ${WORKDIR}/migrated-source/* ${TARGET_PATH}" # back to workdir popd @@ -154,12 +154,18 @@ fi pushd "${TARGET_REPO}" # To target repo +# For postprocessing of the batch migration script. +mkdir -p owl-bot-staging/${DISTRIBUTION_NAME}/${DISTRIBUTION_NAME} +touch owl-bot-staging/${DISTRIBUTION_NAME}/${DISTRIBUTION_NAME}/${DISTRIBUTION_NAME}.txt +git add owl-bot-staging +git commit -m "Trigger owlbot post-processor" + git push -u origin "${BRANCH}" --force # create pull request if gh --help > /dev/null then - gh pr create --title "migrate code from ${SOURCE_REPO}" + gh pr create --title "migrate code from ${SOURCE_REPO}" --body "feat: Migrate ${SOURCE_REPO} into ${TARGET_PATH} (#${ISSUE_NUMBER})." else hub pull-request -m "migrate code from ${SOURCE_REPO}" fi From a303e0f8493731e9475f7f5dbf3e9515a2c7c413 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Wed, 19 Apr 2023 14:42:11 -0700 Subject: [PATCH 10/11] chore: conventional commit. --- scripts/split_repo_migration/git-migrate-history.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index d0a541f3190a..c17e620000ff 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -165,7 +165,7 @@ git push -u origin "${BRANCH}" --force # create pull request if gh --help > /dev/null then - gh pr create --title "migrate code from ${SOURCE_REPO}" --body "feat: Migrate ${SOURCE_REPO} into ${TARGET_PATH} (#${ISSUE_NUMBER})." + gh pr create --title "migrate code from ${SOURCE_REPO}" --title "feat: Migrate ${SOURCE_REPO} into ${TARGET_PATH} (#${ISSUE_NUMBER})" else hub pull-request -m "migrate code from ${SOURCE_REPO}" fi From 5c57e45ce1e67904106204549c21a86018f76446 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Wed, 19 Apr 2023 15:19:51 -0700 Subject: [PATCH 11/11] chore: fix. --- scripts/split_repo_migration/git-migrate-history.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/split_repo_migration/git-migrate-history.sh b/scripts/split_repo_migration/git-migrate-history.sh index c17e620000ff..b6eeb8752986 100755 --- a/scripts/split_repo_migration/git-migrate-history.sh +++ b/scripts/split_repo_migration/git-migrate-history.sh @@ -165,7 +165,7 @@ git push -u origin "${BRANCH}" --force # create pull request if gh --help > /dev/null then - gh pr create --title "migrate code from ${SOURCE_REPO}" --title "feat: Migrate ${SOURCE_REPO} into ${TARGET_PATH} (#${ISSUE_NUMBER})" + gh pr create --title "feat: Migrate code from ${SOURCE_REPO} into ${TARGET_PATH} (#${ISSUE_NUMBER})" --body "See #${ISSUE_NUMBER}." else hub pull-request -m "migrate code from ${SOURCE_REPO}" fi