Skip to content

Commit

Permalink
build: create two PRs when updating split repo, so that we do not unn…
Browse files Browse the repository at this point in the history
…ecessarily delete samples if we do not need to (#3385)
  • Loading branch information
sofisl authored Oct 4, 2022
1 parent 4b45779 commit 142941f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bin/update-split-repo.sh → bin/delete-samples-split-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ git clone "git@github.com:googleapis/${SPLIT_REPO}.git" "/tmp/${SPLIT_REPO}"

cd "/tmp/${SPLIT_REPO}"

git checkout -b 'removeOwlBotAndUpdateREADME'
git checkout -b 'deleteMostOfLibrary'

shopt -s extglob

Expand Down Expand Up @@ -72,7 +72,7 @@ echo -e "'**_THIS REPOSITORY IS DEPRECATED. ALL OF ITS CONTENT AND HISTORY HAS B
git add .
git commit -m 'build: update README for deprecation notice and delete all files except samples'

git push -f --set-upstream origin removeOwlBotAndUpdateREADME
git push -f --set-upstream origin deleteMostOfLibrary

# create pull request
if gh --help > /dev/null
Expand Down
5 changes: 3 additions & 2 deletions bin/migrate-split-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ ${SCRIPT_DIR}/migrate-git-history.sh \
".kokoro,.github,.trampolinerc,SECURITY.md,renovate.json,samples" \
".github/.OwlBot.yaml,samples/quickstart.js,samples/test/quickstart.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
${SCRIPT_DIR}/update-split-repo.sh ${SPLIT_REPO} ${ARTIFACT_NAME}
# run the script to update the split repo and either delete all the samples or just update the README
${SCRIPT_DIR}/delete-samples-split-repo.sh ${SPLIT_REPO} ${ARTIFACT_NAME}
${SCRIPT_DIR}/update-readme-only-split-repo.sh ${SPLIT_REPO} ${ARTIFACT_NAME}
82 changes: 82 additions & 0 deletions bin/update-readme-only-split-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/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 <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

rm -rf "/tmp/${SPLIT_REPO}"
git clone "git@github.com:googleapis/${SPLIT_REPO}.git" "/tmp/${SPLIT_REPO}"

cd "/tmp/${SPLIT_REPO}"

git checkout -b 'removeOwlBotAndUpdateREADME'

shopt -s extglob

OWLBOT_PY="/tmp/${SPLIT_REPO}/owlbot.py"
# Delete owlbot.yaml
rm -rf "$OWLBOT_PY"

IGNORE_README_TXT="# 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.
import synthtool.languages.node as node
node.owlbot_main(templates_excludes=[
README.md'
])"

echo "$IGNORE_README_TXT" >> "$OWLBOT_PY"

# Update the README
README_MD="/tmp/${SPLIT_REPO}/README.md"

echo -e "'**_THIS REPOSITORY IS DEPRECATED. ALL OF ITS CONTENT AND HISTORY HAS BEEN MOVED TO [GOOGLE-CLOUD-NODE](https://github.com/googleapis/google-cloud-node/tree/main/packages/${ARTIFACT_NAME})_**'\n$(cat $README_MD)" > "$README_MD"

git add .
git commit -m 'build: update README for deprecation notice and delete all files except samples'

git push -f --set-upstream origin removeOwlBotAndUpdateREADME

# create pull request
if gh --help > /dev/null
then
gh pr create --title "build: update README for deprecation notice"
else
hub pull-request -m "build: update README for deprecation notice"
fi

rm -rf "/tmp/${SPLIT_REPO}"

0 comments on commit 142941f

Please sign in to comment.