-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate-downstream.sh
executable file
·90 lines (74 loc) · 2.8 KB
/
generate-downstream.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
set -o errexit -o nounset -o pipefail
# enable recursive globbing with **
shopt -s globstar
SCRIPTDIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
source "$SCRIPTDIR/lib.sh"
usage() {
cat << EOF
Usage: $0 -v version_to_release [-f] [-m midstream_branch] [-d downstream_branch] [-b base_release_branch]
Generate the downstream branch based on the specified upstream version.
The downstream branch is named redhat-wip-\$version_to_release.
-v: specify the upstream version to use as base for the downstream branch
-m: specify the branch from which to apply the midstream modifications
default: current branch
-b: specify the base release branch (from which to copy the .tekton/ folder)
default: redhat-latest
-f: force-generate the downstream branch even if it already exists locally
EOF
}
VERSION_TO_RELEASE=''
MIDSTREAM_BRANCH=$(git rev-parse --abbrev-ref HEAD)
DOWNSTREAM_BRANCH=''
BASE_RELEASE_BRANCH=redhat-latest
FORCE='false'
while getopts v:m:d:b:fh opt; do
case "$opt" in
v) VERSION_TO_RELEASE=$OPTARG ;;
m) MIDSTREAM_BRANCH=$OPTARG ;;
d) DOWNSTREAM_BRANCH=$OPTARG ;;
b) BASE_RELEASE_BRANCH=$OPTARG ;;
f) FORCE='true' ;;
h) usage; exit 0 ;;
*) exit 1 ;;
esac
done
if [[ -z "$VERSION_TO_RELEASE" ]]; then
usage
exit 1
fi
if [[ -z "$DOWNSTREAM_BRANCH" ]]; then
DOWNSTREAM_BRANCH=downstream/$VERSION_TO_RELEASE
fi
if [[ "$FORCE" = 'true' ]]; then
git checkout -B "$DOWNSTREAM_BRANCH" "$VERSION_TO_RELEASE"
else
if ! git checkout -b "$DOWNSTREAM_BRANCH" "$VERSION_TO_RELEASE"; then
info "----------------------------------------------------------" \
"If the $DOWNSTREAM_BRANCH branch already exists, you can:" \
"- use '$0 -f ...' to overwrite it (discarding your changes)" \
"- rename it ('git branch -m $DOWNSTREAM_BRANCH <backup_name>')"
exit 1
fi
fi
trap 'git checkout - >/dev/null' EXIT
git rm -r .github/
git commit -s -m "Remove unwanted CI setup"
git rm -r -- examples **/test-fixtures **/*_test.go
git commit -s -m "Remove fluff to avoid SAST false positives"
apply_midstream_changes "$MIDSTREAM_BRANCH"
git commit -s -m "Apply Red Hat specific modifications"
if ! git fetch origin "$BASE_RELEASE_BRANCH"; then
warn "Could not fetch $BASE_RELEASE_BRANCH from origin. Will continue anyway."
fi
if git checkout "origin/$BASE_RELEASE_BRANCH" -- .tekton; then
git add .tekton
git commit -s -m "Copy Tekton pipelines from '$BASE_RELEASE_BRANCH' branch"
else
warn "Could not copy Tekton pipelines from origin/$BASE_RELEASE_BRANCH."
fi
cat << EOF
--------------------------------------------------------------------------------
Generated downstream branch: $DOWNSTREAM_BRANCH
--------------------------------------------------------------------------------
EOF