Skip to content

Commit 2190178

Browse files
authored
chore: update migration script (#7070)
* working PR #7051 * chore: add Kokoro to migration script, and other ch changes * chore: make changes to gh script * undo gsed portion * chore: fix which trampoline script gets modified * Fix typo in license comment
1 parent 65046f5 commit 2190178

3 files changed

Lines changed: 64 additions & 119 deletions

File tree

bin/delete-everything-split-repo.sh

Lines changed: 5 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,7 @@ git clone "git@github.com:googleapis/${SPLIT_REPO}.git" "/tmp/${SPLIT_REPO}"
3131

3232
cd "/tmp/${SPLIT_REPO}"
3333

34-
git checkout -b 'deleteMostOfLibrary'
35-
36-
37-
# Delete everything first that's not the samples, README.md, .kokoro folder, and git folder
38-
ls | grep -v 'samples\|README.md\|.git' | xargs rm -rf
39-
rm -rf "/tmp/${SPLIT_REPO}/.[!.git]*"
40-
rm -rf "/tmp/${SPLIT_REPO}/.github"
41-
rm -rf "/tmp/${SPLIT_REPO}/.kokoro"
42-
43-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/presubmit/node12/common.cfg"
44-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/presubmit/node12/samples-test.cfg"
45-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/presubmit/node12/system-test.cfg"
46-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/presubmit/node12/test.cfg"
47-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/common.cfg"
48-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/populate-secrets.sh"
49-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/trampoline.sh"
50-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/trampoline_v2.sh"
51-
git checkout "/tmp/${SPLIT_REPO}/.kokoro/.gitattributes"
34+
git checkout -b 'archiveLibrary'
5235

5336
IGNORE_README_TXT="# Copyright 2022 Google LLC
5437
#
@@ -72,83 +55,6 @@ OWLBOT_PY="/tmp/${SPLIT_REPO}/owlbot.py"
7255

7356
echo "$IGNORE_README_TXT" >> "$OWLBOT_PY"
7457

75-
SAMPLES_CFG_TXT="#!/bin/bash
76-
# Copyright 2022 Google LLC
77-
#
78-
# Licensed under the Apache License, Version 2.0 (the "License");
79-
# you may not use this file except in compliance with the License.
80-
# You may obtain a copy of the License at
81-
#
82-
# https://www.apache.org/licenses/LICENSE-2.0
83-
#
84-
# Unless required by applicable law or agreed to in writing, software
85-
# distributed under the License is distributed on an \"AS IS\" BASIS,
86-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
87-
# See the License for the specific language governing permissions and
88-
# limitations under the License.
89-
set -eo pipefail
90-
export NPM_CONFIG_PREFIX=\${HOME}/.npm-global
91-
# Setup service account credentials.
92-
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/secret_manager/long-door-651-kokoro-system-test-service-accountexport GCLOUD_PROJECT=long-door-651
93-
cd \$(dirname \$0)/..
94-
# Run a pre-test hook, if a pre-samples-test.sh is in the project
95-
if [ -f .kokoro/pre-samples-test.sh ]; then
96-
set +x
97-
. .kokoro/pre-samples-test.sh
98-
set -x
99-
fi
100-
if [ -f samples/package.json ]; then
101-
# Install and link samples
102-
cd samples/
103-
npm install
104-
# If tests are running against main branch, configure flakybot
105-
# to open issues on failures:
106-
if [[ \$KOKORO_BUILD_ARTIFACTS_SUBDIR = *\"continuous\"* ]] || [[ \$KOKORO_BUILD_ARTIFACTS_SUBDIR = *\"nightly\"* ]]; then
107-
export MOCHA_REPORTER_OUTPUT=test_output_sponge_log.xml
108-
export MOCHA_REPORTER=xunit
109-
cleanup() {
110-
chmod +x \$KOKORO_GFILE_DIR/linux_amd64/flakybot
111-
\$KOKORO_GFILE_DIR/linux_amd64/flakybot
112-
}
113-
trap cleanup EXIT HUP
114-
fi
115-
npm run test
116-
fi
117-
# codecov combines coverage across integration and unit tests. Include
118-
# the logic below for any environment you wish to collect coverage for:
119-
COVERAGE_NODE=12
120-
if npx check-node-version@3.3.0 --silent --node \$COVERAGE_NODE; then
121-
NYC_BIN=./node_modules/nyc/bin/nyc.js
122-
if [ -f \"\$NYC_BIN\" ]; then
123-
\$NYC_BIN report || true
124-
fi
125-
bash \$KOKORO_GFILE_DIR/codecov.sh
126-
else
127-
echo \"coverage is only reported for Node \$COVERAGE_NODE\"
128-
fi"
129-
130-
SYSTEM_TEST_CFG_TXT="#!/bin/bash
131-
# Copyright 2022 Google LLC
132-
#
133-
# Licensed under the Apache License, Version 2.0 (the \"License\");
134-
# you may not use this file except in compliance with the License.
135-
# You may obtain a copy of the License at
136-
#
137-
# https://www.apache.org/licenses/LICENSE-2.0
138-
#
139-
# Unless required by applicable law or agreed to in writing, software
140-
# distributed under the License is distributed on an \"AS IS\" BASIS,
141-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142-
# See the License for the specific language governing permissions and
143-
# limitations under the License.
144-
set -eo pipefail
145-
echo \"no-op\"
146-
"
147-
148-
echo "$SAMPLES_CFG_TXT" >> "/tmp/${SPLIT_REPO}/.kokoro/samples-test.sh"
149-
echo "$SYSTEM_TEST_CFG_TXT" >> "/tmp/${SPLIT_REPO}/.kokoro/system-test.sh"
150-
chmod u+x "/tmp/${SPLIT_REPO}/.kokoro/samples-test.sh"
151-
chmod u+x "/tmp/${SPLIT_REPO}/.kokoro/system-test.sh"
15258

15359
# Update the README
15460
README_MD="/tmp/${SPLIT_REPO}/README.md"
@@ -157,16 +63,16 @@ README_CONTENT=$(cat $README_MD)
15763
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/${ARTIFACT_NAME})_**\n\n$README_CONTENT" > "$README_MD"
15864

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

162-
git push -f --set-upstream origin deleteMostOfLibrary
68+
git push -f --set-upstream origin archiveLibrary
16369

16470
# create pull request
16571
if gh --help > /dev/null
16672
then
167-
gh pr create --title "build: update README for deprecation notice and delete all files except samples"
73+
gh pr create --title "build: update README for deprecation notice"
16874
else
169-
hub pull-request -m "build: update README for deprecation notice and delete all files except samples"
75+
hub pull-request -m "build: update README for deprecation notice"
17076
fi
17177

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

bin/migrate-split-repo.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ then
2222
fi
2323

2424
# repo name (e.g. nodejs-asset)
25-
SPLIT_REPO=$1
25+
export SPLIT_REPO=$1
2626
# destination directory (e.g. packages/google-cloud-asset)
2727
export PACKAGE_PATH="$2"
2828

@@ -37,7 +37,7 @@ ${SCRIPT_DIR}/migrate-git-history.sh \
3737
"googleapis/google-cloud-node" \
3838
"" \
3939
"${PACKAGE_PATH}" \
40-
".kokoro,.github,.trampolinerc,SECURITY.md,renovate.json" \
40+
".github/workflows/ci.yaml,.github/workflows/issues-no-repro.yaml,.github/workflows/response.yaml,SECURITY.md,renovate.json" \
4141
".github/.OwlBot.yaml,system-test/test/quickstart.js,system-test/test/quickstart.test.js"
4242

4343
# run the script to update the split repo and either delete all the samples or just update the README

bin/split-repo-post-process.sh

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@
1414
# limitations under the License.
1515

1616
set -e
17+
18+
# find owner from lower-level CODEOWNERS and add to top-level CODEOWNERS
19+
LOWER_CODEOWNERS="${PACKAGE_PATH}/.github/CODEOWNERS"
20+
if [[ -f "${LOWER_CODEOWNERS}" ]]; then
21+
echo "Found ${LOWER_CODEOWNERS}, extracting owner..."
22+
OWNER=$(grep -v '^#' "${LOWER_CODEOWNERS}" | grep '\*' | head -n 1 | awk '{print $NF}')
23+
if [[ ! -z "${OWNER}" ]]; then
24+
# check if entry already exists
25+
if ! grep -q "^/${PACKAGE_PATH} " ./.github/CODEOWNERS; then
26+
echo "Adding /${PACKAGE_PATH} ${OWNER} to ./.github/CODEOWNERS"
27+
echo "/${PACKAGE_PATH} ${OWNER}" >> ./.github/CODEOWNERS
28+
else
29+
echo "Entry for /${PACKAGE_PATH} already exists in ./.github/CODEOWNERS"
30+
fi
31+
fi
32+
echo "Removing ${LOWER_CODEOWNERS}"
33+
rm "${LOWER_CODEOWNERS}"
34+
fi
35+
36+
# move any .github/workflows files to the top-level .github/workflows
37+
if [[ -d "${PACKAGE_PATH}/.github/workflows" ]]; then
38+
if [ -n "$(ls -A "${PACKAGE_PATH}/.github/workflows")" ]; then
39+
echo "Moving .github/workflows from ${PACKAGE_PATH} to root..."
40+
cp -r "${PACKAGE_PATH}/.github/workflows/"* ./.github/workflows/
41+
fi
42+
fi
43+
1744

1845
PACKAGE_NAME=$(basename ${PACKAGE_PATH})
1946

@@ -36,25 +63,25 @@ mv "${PACKAGE_PATH}/.github/.OwlBot.yaml" "${PACKAGE_PATH}/.OwlBot.yaml"
3663

3764
echo "Fixing format of ${PACKAGE_PATH}/.OwlBot.yaml"
3865
# remove `docker:` line
39-
sed -i "/docker:/d" "${PACKAGE_PATH}/.OwlBot.yaml"
66+
gsed -i "/docker:/d" "${PACKAGE_PATH}/.OwlBot.yaml"
4067
# remove `image:` line
41-
sed -i "/image:/d" "${PACKAGE_PATH}/.OwlBot.yaml"
68+
gsed -i "/image:/d" "${PACKAGE_PATH}/.OwlBot.yaml"
4269

4370
if grep -q "/owl-bot-staging/\$1/\$2" "${PACKAGE_PATH}/.OwlBot.yaml"
4471
then
4572
echo "OwlBot config is copying each folder"
46-
sed -i 's/\.\*-nodejs\/(.*)/.*-nodejs/' "${PACKAGE_PATH}/.OwlBot.yaml"
47-
sed -i "s/dest: \/owl-bot-staging\/\$1\/\$2/dest: \/owl-bot-staging\/${PACKAGE_NAME}\/\$1/" "${PACKAGE_PATH}/.OwlBot.yaml"
73+
gsed -i 's/\.\*-nodejs\/(.*)/.*-nodejs/' "${PACKAGE_PATH}/.OwlBot.yaml"
74+
gsed -i "s/dest: \/owl-bot-staging\/\$1\/\$2/dest: \/owl-bot-staging\/${PACKAGE_NAME}\/\$1/" "${PACKAGE_PATH}/.OwlBot.yaml"
4875
else
49-
sed -i "s/dest: \/owl-bot-staging/dest: \/owl-bot-staging\/${PACKAGE_NAME}/" "${PACKAGE_PATH}/.OwlBot.yaml"
76+
gsed -i "s/dest: \/owl-bot-staging/dest: \/owl-bot-staging\/${PACKAGE_NAME}/" "${PACKAGE_PATH}/.OwlBot.yaml"
5077
fi
5178

5279
echo "fixing owlbot.py file"
5380

5481
if test -f "${PACKAGE_PATH}/owlbot.py"; then
55-
sed -i "s/import synthtool.languages.node as node/import synthtool.languages.node_mono_repo as node/" "${PACKAGE_PATH}/owlbot.py"
56-
echo sed -i "s/node.owlbot_main(/node.owlbot_main(relative_dir=${PACKAGE_PATH},/" "${PACKAGE_PATH}/owlbot.py"
57-
sed -i "s|node.owlbot_main(|node.owlbot_main(relative_dir=\"${PACKAGE_PATH}\",|" "${PACKAGE_PATH}/owlbot.py"
82+
gsed -i "s/import synthtool.languages.node as node/import synthtool.languages.node_mono_repo as node/" "${PACKAGE_PATH}/owlbot.py"
83+
echo gsed -i "s/node.owlbot_main(/node.owlbot_main(relative_dir=${PACKAGE_PATH},/" "${PACKAGE_PATH}/owlbot.py"
84+
gsed -i "s|node.owlbot_main(|node.owlbot_main(relative_dir=\"${PACKAGE_PATH}\",|" "${PACKAGE_PATH}/owlbot.py"
5885
fi
5986

6087
# update .repo and .issue_tracker in .repo-metadata.json
@@ -79,17 +106,29 @@ echo "updating homepage"
79106
jq -r ".homepage = \"https://github.com/googleapis/google-cloud-node/tree/main/${PACKAGE_PATH}\"" ${PACKAGE_PATH}/package.json > ${PACKAGE_PATH}/package2.json
80107
mv ${PACKAGE_PATH}/package2.json ${PACKAGE_PATH}/package.json
81108

82-
if !(test -f "${PACKAGE_PATH}/owlbot.py"); then
83-
IMAGE="gcr.io/cloud-devrel-public-resources/owlbot-nodejs-mono-repo:latest"
84-
echo "Running post-processor: ${IMAGE}"
85-
docker pull "${IMAGE}"
86-
docker run --rm \
87-
--user $(id -u):$(id -g) \
88-
-v $(pwd):/workspace/google-cloud-node \
89-
-w /workspace/google-cloud-node \
90-
-e "DEFAULT_BRANCH=main" \
91-
"${IMAGE}"
109+
110+
# remove .github folder from package
111+
if [[ -d "${PACKAGE_PATH}/.github" ]]; then
112+
echo "Removing ${PACKAGE_PATH}/.github"
113+
rm -rf "${PACKAGE_PATH}/.github"
114+
fi
115+
116+
117+
# update repo name in .kokoro files from SPLIT_REPO to PACKAGE_PATH
118+
KOKORO_DIR="${PACKAGE_PATH}/.kokoro"
119+
PACKAGE_PATH_REPLACEMENT="${SPLIT_REPO}/${PACKAGE_PATH}"
120+
if [[ -d "${KOKORO_DIR}" ]]; then
121+
echo "Updating repo name in .kokoro files..."
122+
if [[ -n "${SPLIT_REPO}" ]]; then
123+
find "${KOKORO_DIR}" -type f -print0 | while IFS= read -r -d '' file; do
124+
echo "Processing ${file}"
125+
gsed -i -E "s|${SPLIT_REPO}|${PACKAGE_PATH_REPLACEMENT}|g" "${file}"
126+
done
127+
fi
92128
fi
129+
130+
echo "Fixing .trampolinerc for populate-secrets.sh"
131+
gsed -i 's|source ${PROJECT_ROOT}/.kokoro/populate-secrets.sh|source ${PROJECT_ROOT}/'"${PACKAGE_PATH}"'/.kokoro/populate-secrets.sh|' "${PACKAGE_PATH}"/.trampolinerc
93132

94133
# add changes to local git directory
95134
git add .

0 commit comments

Comments
 (0)