-
Notifications
You must be signed in to change notification settings - Fork 227
/
update-4x-branch.sh
executable file
·73 lines (63 loc) · 2.23 KB
/
update-4x-branch.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
#!/bin/bash
#
# Create a PR to update the 4.x branch to match the state of "main" for the
# just-tagged release. The 4.x branch needs to be updated for the current docs
# build.
#
if [ "$TRACE" != "" ]; then
export PS4='${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
fi
set -o errexit
set -o pipefail
function fatal {
echo "$(basename $0): error: $*"
exit 1
}
TOP=$(cd $(dirname $0)/../ >/dev/null; pwd)
WRKDIR=${TOP}/build/update-4x-branch
echo "# Creating working git clone in: ${WRKDIR}/apm-agent-nodejs"
rm -rf $WRKDIR
mkdir -p $WRKDIR
cd $WRKDIR
git clone [email protected]:elastic/apm-agent-nodejs.git
cd apm-agent-nodejs
TARGTAG=$(git tag --points-at HEAD)
if [[ ! ("$TARGTAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]$) ]]; then
fatal "the tag on HEAD, '${TARGTAG}', does not look like a release tag"
fi
# echo "TARGTAG=$TARGTAG"
readonly NUM_COMMITS_SANITY_GUARD=200
LASTTAG=$(
git log --pretty=format:%h -$NUM_COMMITS_SANITY_GUARD | tail -n +2 | while read sha; do
possible=$(git tag --points-at $sha)
if [[ "$possible" =~ ^v[0-9]+\.[0-9]+\.[0-9]$ ]]; then
echo $possible
break
fi
done
)
if [[ -z "$LASTTAG" ]]; then
fatal "could not find previous release tag in last $NUM_COMMITS_SANITY_GUARD commits"
fi
# echo "LASTTAG=$LASTTAG"
# Merging generally fails, IME. Let's attempt to cherry-pick each commit.
# - That 'awk' command is to reverse the lines of commit shas.
# `tac` works on Linux, `tail -r` works on BSD/macOS.
# https://stackoverflow.com/a/744093/14444044
echo
echo "# Creating PR to update 4.x branch with commits from $LASTTAG to $TARGTAG."
FEATBRANCH=update-4x-branch-$(date +%Y%m%d)
git checkout 4.x
git checkout -b "$FEATBRANCH"
git log --pretty=format:"%h" $LASTTAG...$TARGTAG \
| awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' \
| while read sha; do
echo "$ git cherry-pick $sha"
git cherry-pick $sha
done
RELEASE_PR=$(git log --pretty=format:"%s" -1 $TARGTAG | sed -E 's/^.* \(\#([0-9]+)\)$/\1/')
echo
echo "# You can create a PR now with:"
echo " cd $WRKDIR/apm-agent-nodejs"
echo " gh pr create -w -B 4.x -t 'docs: update 4.x branch for $TARGTAG release' --body 'Refs: #$RELEASE_PR (release PR)'"