Skip to content

Commit

Permalink
chore: minor updates to migration script (#3839)
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl authored Jan 12, 2023
1 parent e24f633 commit 761831e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
3 changes: 1 addition & 2 deletions bin/delete-everything-split-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions bin/migrate-split-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <split-repo-name> <target-path>"
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 \
Expand All @@ -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}"
54 changes: 27 additions & 27 deletions bin/split-repo-post-process.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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}"
Expand All @@ -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"

0 comments on commit 761831e

Please sign in to comment.