|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +# This script is supposed to be used to prepare a release branch based on master. |
| 4 | +# The script performs the following steps: |
| 5 | +# - Create a release branch in SBO repository |
| 6 | +# - Add a label to the SBO repository to be used to mark PRs to be cherry-picked in the release branch |
| 7 | +# - Prepare a PR branch for openshift/release repository adding OpenShift CI jobs for running acceptance and performance tests on PRs to the release branch |
| 8 | +# - Bump docs version in the release branch |
| 9 | +# - (TODO: Add a GitHub Action job for cherry-picking in the release branch) |
| 10 | + |
| 11 | +check_env() { |
| 12 | + if [ -n "$1" ]; then echo "✓"; else echo "✗"; fi |
| 13 | +} |
| 14 | + |
| 15 | +if [ -z "$GITHUB_TOKEN" ] || [ -z "$OPENSHIFT_RELEASE_FORK_REPO" ]; then |
| 16 | + echo "" |
| 17 | + echo "ERROR: All of the following environment variables are required to be set to a non-empty value" |
| 18 | + echo "" |
| 19 | + echo " $(check_env $GITHUB_TOKEN) GITHUB_TOKEN ... A 'repo' scoped Github token for creating release label" |
| 20 | + echo " $(check_env $OPENSHIFT_RELEASE_FORK_REPO) OPENSHIFT_RELEASE_FORK_REPO ... A fork of https://github.com/openshift/release.git" |
| 21 | + echo "" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +WS=${OUTPUT_DIR:-$(pwd)}/.branch-release |
| 26 | + |
| 27 | +[email protected]: $OPENSHIFT_RELEASE_FORK_REPO.git |
| 28 | +OPENSHIFT_RELEASE_UPSTREAM_REPO=${OPENSHIFT_RELEASE_UPSTREAM_REPO:-openshift/release} |
| 29 | +OPENSHIFT_RELEASE_UPSTREAM_REPO_URL=https://github.com/$OPENSHIFT_RELEASE_UPSTREAM_REPO.git |
| 30 | +OPENSHIFT_RELEASE_DIR=$WS/release.git |
| 31 | + |
| 32 | +SBO_REPO=${SBO_REPO:-redhat-developer/service-binding-operator} |
| 33 | + |
| 34 | +SBO_REPO_API=https://api.github.com/repos/$SBO_REPO |
| 35 | +SBO_DIR=$WS/service-binding-operator.git |
| 36 | + |
| 37 | +DRY_RUN=${DRY_RUN:-true} |
| 38 | +dry_run_msg() { |
| 39 | + echo "" |
| 40 | + echo "***** DRY-RUN: $1" |
| 41 | + echo "" |
| 42 | +} |
| 43 | + |
| 44 | +RELEASE=${RELEASE:-${VERSION%.*}} # assuming VERSION=x.y.z |
| 45 | +RELEASE_BRANCH=release-v${RELEASE}.x |
| 46 | + |
| 47 | +rm -rf $WS |
| 48 | +mkdir -p $WS |
| 49 | +cd $WS |
| 50 | + |
| 51 | +# SBO release branch |
| 52 | +git clone $SBO_REPO_URL $SBO_DIR |
| 53 | +pushd $SBO_DIR |
| 54 | +git fetch |
| 55 | + |
| 56 | +## check if release branch exists and fail if it does |
| 57 | +git ls-remote --exit-code --heads $SBO_REPO_URL $RELEASE_BRANCH && echo "ERROR: Branch $RELEASE_BRANCH already exist on remote origin ($(git remote get-url origin))" && exit 1 |
| 58 | + |
| 59 | +git checkout -b $RELEASE_BRANCH origin/master |
| 60 | + |
| 61 | +yq eval -i '.version = "'${RELEASE}'.x"' docs/devguide/antora.yml |
| 62 | +yq eval -i '.version = "'${RELEASE}'.x"' docs/userguide/antora.yml |
| 63 | + |
| 64 | +git add docs |
| 65 | +git commit -m "Bump version in docs to ${RELEASE}.x" |
| 66 | + |
| 67 | +if [ $DRY_RUN == "false" ]; then |
| 68 | + git push origin $RELEASE_BRANCH |
| 69 | +else |
| 70 | + dry_run_msg "Would have pushed $RELEASE_BRANCH branch to $(git remote get-url origin) repository: git push origin $RELEASE_BRANCH" |
| 71 | +fi |
| 72 | + |
| 73 | +## release label |
| 74 | +release_label='{"name":"release/v'${RELEASE}'.x","description":"Used to mark PRs to be cherry-picked in '$RELEASE_BRANCH' branch","color":"C1E359"}' |
| 75 | +if [ $DRY_RUN == "false" ]; then |
| 76 | + curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" $SBO_REPO_API/labels -d "$release_label" |
| 77 | +else |
| 78 | + dry_run_msg "Would have created a label in $SBO_REPO_URL repository: $release_label" |
| 79 | +fi |
| 80 | + |
| 81 | +## TODO: Add GH actions job for cherry-picking in the release branch |
| 82 | + |
| 83 | +popd |
| 84 | + |
| 85 | +# OpenShift CI jobs for release branch |
| 86 | +git clone $OPENSHIFT_RELEASE_FORK_REPO_URL $OPENSHIFT_RELEASE_DIR |
| 87 | + |
| 88 | +pushd $OPENSHIFT_RELEASE_DIR |
| 89 | +git remote add upstream $OPENSHIFT_RELEASE_UPSTREAM_REPO_URL |
| 90 | +git fetch upstream |
| 91 | +pr_branch=rhd-sbo-$RELEASE_BRANCH-branch |
| 92 | +git checkout -b $pr_branch upstream/master |
| 93 | + |
| 94 | +## Copy release-v1.1.x jobs and replace the version with the new release |
| 95 | +pushd $OPENSHIFT_RELEASE_DIR/ci-operator/config/redhat-developer/service-binding-operator |
| 96 | +for i in redhat-developer-service-binding-operator-release-v1.3.x*; do |
| 97 | + sed_expr="s,v1\.3\.x,v${RELEASE}.x,g" |
| 98 | + sed -e "$sed_expr" $i >$(echo -n "$i" | sed -e "$sed_expr") |
| 99 | +done |
| 100 | +popd |
| 101 | + |
| 102 | +## Prepare YAMLs for the PR |
| 103 | +make update |
| 104 | +yq eval -i '(.presubmits.redhat-developer/service-binding-operator[] | select(.context == "ci/prow/performance").always_run) = false' $OPENSHIFT_RELEASE_DIR/ci-operator/jobs/redhat-developer/service-binding-operator/redhat-developer-service-binding-operator-$RELEASE_BRANCH-presubmits.yaml |
| 105 | +make update |
| 106 | +git add ci-operator |
| 107 | +git commit -m "[rhd-sbo] Add jobs for ${RELEASE_BRANCH} branch" |
| 108 | +if [ $DRY_RUN == "false" ]; then |
| 109 | + git push -u origin $pr_branch |
| 110 | +else |
| 111 | + dry_run_msg "Would have pushed $pr_branch branch to $(git remote get-url origin) repository: git push -u origin $pr_branch" |
| 112 | +fi |
| 113 | +popd |
0 commit comments