From 761831ee6e000bdc5c3c6f799344a3b76351446b Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Thu, 12 Jan 2023 08:10:13 -0800 Subject: [PATCH] chore: minor updates to migration script (#3839) --- bin/delete-everything-split-repo.sh | 3 +- bin/migrate-split-repo.sh | 18 +++++----- bin/split-repo-post-process.sh | 54 ++++++++++++++--------------- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/bin/delete-everything-split-repo.sh b/bin/delete-everything-split-repo.sh index b2e0202ee92..116034b7c36 100755 --- a/bin/delete-everything-split-repo.sh +++ b/bin/delete-everything-split-repo.sh @@ -89,8 +89,7 @@ SAMPLES_CFG_TXT="#!/bin/bash set -eo pipefail export NPM_CONFIG_PREFIX=\${HOME}/.npm-global # Setup service account credentials. -export GOOGLE_APPLICATION_CREDENTIALS=\${KOKORO_GFILE_DIR}/service-account.json -export GCLOUD_PROJECT=long-door-651 +export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/secret_manager/long-door-651-kokoro-system-test-service-accountexport GCLOUD_PROJECT=long-door-651 cd \$(dirname \$0)/.. # Run a pre-test hook, if a pre-samples-test.sh is in the project if [ -f .kokoro/pre-samples-test.sh ]; then diff --git a/bin/migrate-split-repo.sh b/bin/migrate-split-repo.sh index df85fc33d3f..ea3e3364db3 100755 --- a/bin/migrate-split-repo.sh +++ b/bin/migrate-split-repo.sh @@ -12,26 +12,26 @@ # 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}" - + # run the migrate script, remove .kokoro and .github folders # keep the .github/.OwlBot.yaml config ${SCRIPT_DIR}/migrate-git-history.sh \ @@ -40,8 +40,8 @@ ${SCRIPT_DIR}/migrate-git-history.sh \ "" \ "${PACKAGE_PATH}" \ ".kokoro,.github,.trampolinerc,SECURITY.md,renovate.json,samples" \ - ".github/.OwlBot.yaml,samples/quickstart.js,samples/test/quickstart.js,samples/.eslintrc.yml,samples/test/sample.test.js,samples/test/quickstart.test.js,system-test/test/quickstart.test.js,system-test/test/quickstart.js,samples/README.md,samples/package.json,samples/generated" - + ".github/.OwlBot.yaml,samples/quickstart.js,samples/test/quickstart.js,system-test/test/quickstart.js,samples/.eslintrc.yml,samples/test/sample.test.js,samples/test/quickstart.test.js,system-test/test/quickstart.test.js,system-test/test/quickstart.js,samples/README.md,samples/package.json,samples/generated" + # run the script to update the split repo and either delete all the samples or just update the README ${SCRIPT_DIR}/delete-everything-split-repo.sh "${SPLIT_REPO}" "${ARTIFACT_NAME}" -${SCRIPT_DIR}/update-readme-only-split-repo.sh "${SPLIT_REPO}"" "${ARTIFACT_NAME}" +${SCRIPT_DIR}/update-readme-only-split-repo.sh "${SPLIT_REPO}" "${ARTIFACT_NAME}" \ No newline at end of file diff --git a/bin/split-repo-post-process.sh b/bin/split-repo-post-process.sh index 95cfd5dd575..07173e7bf14 100755 --- a/bin/split-repo-post-process.sh +++ b/bin/split-repo-post-process.sh @@ -12,34 +12,34 @@ # 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 - + PACKAGE_NAME=$(basename ${PACKAGE_PATH}) - + echo "Detecting the latest version in ${PACKAGE_PATH}" LATEST_VERSION=$(cat "${PACKAGE_PATH}/package.json" | jq -r ".version") echo "Latest version: ${LATEST_VERSION}" - + echo "Adding release-please config" # using a temp file because jq doesn't like writing to the input file as it reads cat release-please-config.json | jq --sort-keys ". * {\"packages\": {\"${PACKAGE_PATH}\": {}}}" > release-please-config2.json mv release-please-config2.json release-please-config.json - + echo "Adding release-please manifest version" # using a temp file because jq doesn't like writing to the input file as it reads cat .release-please-manifest.json | jq --sort-keys ". * {\"${PACKAGE_PATH}\": \"${LATEST_VERSION}\"}" > .release-please-manifest2.json mv .release-please-manifest2.json .release-please-manifest.json - + echo "Moving ${PACKAGE_PATH}/.github/.OwlBot.yaml" mv "${PACKAGE_PATH}/.github/.OwlBot.yaml" "${PACKAGE_PATH}/.OwlBot.yaml" - + echo "Fixing format of ${PACKAGE_PATH}/.OwlBot.yaml" # remove `docker:` line sed -i "/docker:/d" "${PACKAGE_PATH}/.OwlBot.yaml" # remove `image:` line sed -i "/image:/d" "${PACKAGE_PATH}/.OwlBot.yaml" - + if grep -q "/owl-bot-staging/\$1/\$2" "${PACKAGE_PATH}/.OwlBot.yaml" then echo "OwlBot config is copying each folder" @@ -48,7 +48,15 @@ then else sed -i "s/dest: \/owl-bot-staging/dest: \/owl-bot-staging\/${PACKAGE_NAME}/" "${PACKAGE_PATH}/.OwlBot.yaml" fi - + +echo "fixing owlbot.py file" + +if test -f "${PACKAGE_PATH}/owlbot.py"; then + sed -i "s/import synthtool.languages.node as node/import synthtool.languages.node_mono_repo as node/" "${PACKAGE_PATH}/owlbot.py" + echo sed -i "s/node.owlbot_main(/node.owlbot_main(relative_dir=${PACKAGE_PATH},/" "${PACKAGE_PATH}/owlbot.py" + sed -i "s|node.owlbot_main(|node.owlbot_main(relative_dir=\"${PACKAGE_PATH}\",|" "${PACKAGE_PATH}/owlbot.py" +fi + # update .repo and .issue_tracker in .repo-metadata.json echo "Update .repo-metadata.json" echo "updating .repo to googleapis/google-cloud-node" @@ -60,38 +68,29 @@ then jq ".issue_tracker = \"https://github.com/googleapis/google-cloud-node/issues\"" "${PACKAGE_PATH}/.repo-metadata.json" > "${PACKAGE_PATH}/.repo-metadata2.json" mv "${PACKAGE_PATH}/.repo-metadata2.json" "${PACKAGE_PATH}/.repo-metadata.json" fi - + # update system tests scripts echo "adding compile step to system-test" # using a temp file because jq doesn't like writing to the input file as it reads jq -r ".scripts[\"system-test\"] = \"npm run compile && c8 mocha build/system-test\"" ${PACKAGE_PATH}/package.json > ${PACKAGE_PATH}/package2.json mv ${PACKAGE_PATH}/package2.json ${PACKAGE_PATH}/package.json - + echo "adding compile step to samples-test" # using a temp file because jq doesn't like writing to the input file as it reads jq -r ".scripts[\"samples-test\"] = \"npm run compile && cd samples/ && npm link ../ && npm i && npm test\"" ${PACKAGE_PATH}/package.json > ${PACKAGE_PATH}/package2.json mv ${PACKAGE_PATH}/package2.json ${PACKAGE_PATH}/package.json - + echo "updating repository object type" # using a temp file because jq doesn't like writing to the input file as it reads -jq -r ".repository[\"type\"] = \"git\"" ${PACKAGE_PATH}/package.json > ${PACKAGE_PATH}/package2.json -mv ${PACKAGE_PATH}/package2.json ${PACKAGE_PATH}/package.json - -echo "updating repository object url" -# using a temp file because jq doesn't like writing to the input file as it reads -jq -r ".repository[\"url\"] = \"https://github.com/googleapis/google-cloud-node.git\"" ${PACKAGE_PATH}/package.json > ${PACKAGE_PATH}/package2.json +jq -r ".repository = {\"type\": \"git\", \"directory\": \"packages/${PACKAGE_NAME}\", \"url\": \"https://github.com/googleapis/google-cloud-node.git\"}" ${PACKAGE_PATH}/package.json > ${PACKAGE_PATH}/package2.json mv ${PACKAGE_PATH}/package2.json ${PACKAGE_PATH}/package.json - -echo "updating repository object directory" -# using a temp file because jq doesn't like writing to the input file as it reads -jq -r ".repository[\"directory\"] = \"packages/${PACKAGE_NAME}\"" ${PACKAGE_PATH}/package.json > ${PACKAGE_PATH}/package2.json -mv ${PACKAGE_PATH}/package2.json ${PACKAGE_PATH}/package.json - -echo "updating repository object directory" + +echo "updating homepage" # using a temp file because jq doesn't like writing to the input file as it reads jq -r ".homepage = \"https://github.com/googleapis/google-cloud-node/tree/main/packages/${PACKAGE_NAME}\"" ${PACKAGE_PATH}/package.json > ${PACKAGE_PATH}/package2.json mv ${PACKAGE_PATH}/package2.json ${PACKAGE_PATH}/package.json - + +if !(test -f "${PACKAGE_PATH}/owlbot.py"); then IMAGE="gcr.io/cloud-devrel-public-resources/owlbot-nodejs-mono-repo:latest" echo "Running post-processor: ${IMAGE}" docker pull "${IMAGE}" @@ -101,7 +100,8 @@ docker run --rm \ -w /workspace/google-cloud-node \ -e "DEFAULT_BRANCH=main" \ "${IMAGE}" - +fi + # add changes to local git directory git add . git commit -am "build: add release-please config, fix owlbot-config"