|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2022 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -e |
| 17 | + |
| 18 | +if [ $# -lt 2 ] |
| 19 | +then |
| 20 | + echo "Usage: $0 <split-repo-name> <target-path>" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# repo name (e.g. nodejs-asset) |
| 25 | +SPLIT_REPO=$1 |
| 26 | +# destination directory (e.g. google-cloud-asset) |
| 27 | +ARTIFACT_NAME=$2 |
| 28 | + |
| 29 | +rm -rf "/tmp/${SPLIT_REPO}" |
| 30 | +git clone "git@github.com:googleapis/${SPLIT_REPO}.git" "/tmp/${SPLIT_REPO}" |
| 31 | + |
| 32 | +cd "/tmp/${SPLIT_REPO}" |
| 33 | + |
| 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" |
| 52 | + |
| 53 | +IGNORE_README_TXT="# Copyright 2022 Google LLC |
| 54 | +# |
| 55 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 56 | +# you may not use this file except in compliance with the License. |
| 57 | +# You may obtain a copy of the License at |
| 58 | +# |
| 59 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 60 | +# |
| 61 | +# Unless required by applicable law or agreed to in writing, software |
| 62 | +# distributed under the License is distributed on an \"AS IS\" BASIS, |
| 63 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 64 | +# See the License for the specific language governing permissions and |
| 65 | +# limitations under the License. |
| 66 | +import synthtool.languages.node as node |
| 67 | +node.owlbot_main(templates_excludes=[ |
| 68 | +'README.md' |
| 69 | +])" |
| 70 | + |
| 71 | +OWLBOT_PY="/tmp/${SPLIT_REPO}/owlbot.py" |
| 72 | + |
| 73 | +echo "$IGNORE_README_TXT" >> "$OWLBOT_PY" |
| 74 | + |
| 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" |
| 152 | + |
| 153 | +# Update the README |
| 154 | +README_MD="/tmp/${SPLIT_REPO}/README.md" |
| 155 | + |
| 156 | +README_CONTENT=$(cat $README_MD) |
| 157 | +echo -e "**_THIS REPOSITORY IS DEPRECATED. ALL OF ITS CONTENT AND HISTORY HAS BEEN MOVED TO [MONOREPO-TEST](https://github.com/googleapis/monorepo-test/tree/main/packages/${ARTIFACT_NAME})_**\n\n$README_CONTENT" > "$README_MD" |
| 158 | + |
| 159 | +git add . |
| 160 | +git commit -m 'build: update README for deprecation notice and delete all files except samples' |
| 161 | + |
| 162 | +git push -f --set-upstream origin deleteMostOfLibrary |
| 163 | + |
| 164 | +# create pull request |
| 165 | +if gh --help > /dev/null |
| 166 | +then |
| 167 | + gh pr create --title "build: update README for deprecation notice and delete all files except samples" |
| 168 | +else |
| 169 | + hub pull-request -m "build: update README for deprecation notice and delete all files except samples" |
| 170 | +fi |
| 171 | + |
| 172 | +rm -rf "/tmp/${SPLIT_REPO}" |
0 commit comments