github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/hack/scripts/sync-prow.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2024 The Kubernetes Authors. 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 # http://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 -euo pipefail 17 18 check_deps() { 19 if ! command -v git-filter-repo &>/dev/null; then 20 echo "please install the git-filter-repo tool per https://github.com/newren/git-filter-repo" 21 exit 1 22 fi 23 24 if [[ -z "${1}" ]]; then 25 echo "please specify your github username as a positional parameter." 26 echo "${1}" 27 exit 1 28 fi 29 } 30 31 # $1 must be your GitHub username. 32 check_deps "${1:-}" 33 34 gh_username="${1}" 35 old_prow="$PWD/old_prow" 36 new_prow="$PWD/prow" 37 38 rm -rf $old_prow $new_prow 39 # Clone the old prow repo. 40 git clone https://github.com/kubernetes/test-infra.git $old_prow || true 41 42 # Clone the new prow repo (this should be your fork). 43 git clone "https://github.com/${gh_username}/prow.git" $new_prow || true 44 45 # These are the --path arguments that define the set of paths we want to migrate: 46 path_args=" 47 --path prow \ 48 --path ghproxy \ 49 --path pkg/flagutil \ 50 --path pkg/genyaml \ 51 --path hack/prowimagebuilder \ 52 --path hack/ts-rollup 53 " 54 55 # Strip down the master branch of $old_prow to only have commits that touch the prow related directories. 56 cd "$old_prow" 57 git-filter-repo \ 58 ${path_args} 59 60 cd "$new_prow" 61 # Check out a new "sync" branch that we want to create a PR from. 62 git branch sync origin/main 63 git checkout sync 64 65 # Remove any existing history for the directories we care about to avoid duplicate commits. 66 git-filter-repo \ 67 --invert-paths \ 68 --force \ 69 ${path_args} 70 71 # Import commits from old_prow/master into "sync" inside $new_prow. 72 git remote add old_prow "$old_prow" 73 git fetch old_prow 74 git merge old_prow/master --no-edit --allow-unrelated-histories --strategy-option theirs 75 76 # Rename go module paths 77 find . -path ./hack/scripts/sync-prow.sh -prune -o -type f -exec sed -i 's,k8s.io/test-infra,sigs.k8s.io/prow,g' {} \; 78 git commit -a -m "Rename k8s.io/test-infra module to sigs.k8s.io/prow." 79 80 # Update go deps 81 make update-go-deps 82 # Commit if there were changes. 83 git commit -a -m "Update Go dependencies after prow source sync." || true 84 85 # Run codegen (CRD file is probably out of date). 86 make update-codegen 87 # Commit if there were changes. 88 git commit -a -m "Update generated code after prow source sync." || true 89 90 echo "Sync completed successfully! 'cd ${new_prow} && git push origin' when you're ready."