|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2019 The OpenShift Knative Authors |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# The local git repo must have a remote "upstream" pointing |
| 18 | +# to knative-sandbox/kn-plugin-func, and a remote "openshift" |
| 19 | +# pointing to openshift-knative/kn-plugin-func. |
| 20 | + |
| 21 | +# Synchs the release-next branch to main and then triggers CI |
| 22 | +# Usage: update-to-head.sh |
| 23 | + |
| 24 | +set -e |
| 25 | +REPO_NAME=$(basename $(git rev-parse --show-toplevel)) |
| 26 | + |
| 27 | +# Custom files |
| 28 | +custom_files=$(cat <<EOT | tr '\n' ' ' |
| 29 | +openshift |
| 30 | +EOT |
| 31 | +) |
| 32 | +openshift_files_msg=":open_file_folder: update OpenShift specific files" |
| 33 | +robot_trigger_msg=":robot: triggering CI on branch 'release-next' after synching from upstream/main" |
| 34 | + |
| 35 | +# Reset release-next to upstream/main. |
| 36 | +git fetch upstream main |
| 37 | +git checkout upstream/main -B release-next |
| 38 | + |
| 39 | +# Update openshift's main and take all needed files from there. |
| 40 | +git fetch openshift main |
| 41 | +git checkout openshift/main $custom_files |
| 42 | + |
| 43 | +# Apply midstream patches |
| 44 | +if [[ -d openshift/patches ]]; then |
| 45 | + git apply openshift/patches/* |
| 46 | +fi |
| 47 | +# Apply midstream overrides |
| 48 | +if [[ -d openshift/overrides ]]; then |
| 49 | + cp -r openshift/overrides/. . |
| 50 | + rm -rf openshift/overrides |
| 51 | +fi |
| 52 | +# Apply midstream patches using scripts |
| 53 | +if [[ -d openshift/scripts ]]; then |
| 54 | + for script in openshift/scripts/*.sh; do |
| 55 | + "$script" |
| 56 | + done |
| 57 | +fi |
| 58 | +git add . |
| 59 | + |
| 60 | +make generate/zz_filesystem_generated.go |
| 61 | +git add $custom_files generate/zz_filesystem_generated.go templates/certs/ca-certificates.crt |
| 62 | +git commit -m "${openshift_files_msg}" |
| 63 | + |
| 64 | +git push -f openshift release-next |
| 65 | + |
| 66 | +# Trigger CI |
| 67 | +git checkout release-next -B release-next-ci |
| 68 | +date > ci |
| 69 | +git add ci |
| 70 | +git commit -m "${robot_trigger_msg}" |
| 71 | +git push -f openshift release-next-ci |
| 72 | + |
| 73 | +if hash hub 2>/dev/null; then |
| 74 | + # Test if there is already a sync PR in |
| 75 | + COUNT=$(hub api -H "Accept: application/vnd.github.v3+json" repos/openshift-knative/${REPO_NAME}/pulls --flat \ |
| 76 | + | grep -c "${robot_trigger_msg}") || true |
| 77 | + if [ "$COUNT" = "0" ]; then |
| 78 | + hub pull-request --no-edit -l "kind/sync-fork-to-upstream,approved,lgtm" -b openshift-knative/${REPO_NAME}:release-next -h openshift-knative/${REPO_NAME}:release-next-ci -m "${robot_trigger_msg}" |
| 79 | + fi |
| 80 | +else |
| 81 | + echo "hub (https://github.com/github/hub) is not installed, so you'll need to create a PR manually." |
| 82 | +fi |
0 commit comments