|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Create a PR to update the 4.x branch to match the state of "main" for the |
| 4 | +# just-tagged release. The 4.x branch needs to be updated for the current docs |
| 5 | +# build. |
| 6 | +# |
| 7 | + |
| 8 | +if [ "$TRACE" != "" ]; then |
| 9 | + export PS4='${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' |
| 10 | + set -o xtrace |
| 11 | +fi |
| 12 | +set -o errexit |
| 13 | +set -o pipefail |
| 14 | + |
| 15 | +function fatal { |
| 16 | + echo "$(basename $0): error: $*" |
| 17 | + exit 1 |
| 18 | +} |
| 19 | + |
| 20 | +TOP=$(cd $(dirname $0)/../ >/dev/null; pwd) |
| 21 | +WRKDIR=${TOP}/build/update-4x-branch |
| 22 | + |
| 23 | +echo "# Creating working git clone in: ${WRKDIR}/apm-agent-nodejs" |
| 24 | +rm -rf $WRKDIR |
| 25 | +mkdir -p $WRKDIR |
| 26 | +cd $WRKDIR |
| 27 | +git clone [email protected]:elastic/apm-agent-nodejs.git |
| 28 | +cd apm-agent-nodejs |
| 29 | + |
| 30 | +TARGTAG=$(git tag --points-at HEAD) |
| 31 | +if [[ ! ("$TARGTAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]$) ]]; then |
| 32 | + fatal "the tag on HEAD, '${TARGTAG}', does not look like a release tag" |
| 33 | +fi |
| 34 | +# echo "TARGTAG=$TARGTAG" |
| 35 | + |
| 36 | +readonly NUM_COMMITS_SANITY_GUARD=200 |
| 37 | +LASTTAG=$( |
| 38 | + git log --pretty=format:%h -$NUM_COMMITS_SANITY_GUARD | tail -n +2 | while read sha; do |
| 39 | + possible=$(git tag --points-at $sha) |
| 40 | + if [[ "$possible" =~ ^v[0-9]+\.[0-9]+\.[0-9]$ ]]; then |
| 41 | + echo $possible |
| 42 | + break |
| 43 | + fi |
| 44 | + done |
| 45 | +) |
| 46 | +if [[ -z "$LASTTAG" ]]; then |
| 47 | + fatal "could not find previous release tag in last $NUM_COMMITS_SANITY_GUARD commits" |
| 48 | +fi |
| 49 | +# echo "LASTTAG=$LASTTAG" |
| 50 | + |
| 51 | + |
| 52 | +# Merging generally fails, IME. Let's attempt to cherry-pick each commit. |
| 53 | +# - That 'awk' command is to reverse the lines of commit shas. |
| 54 | +# `tac` works on Linux, `tail -r` works on BSD/macOS. |
| 55 | +# https://stackoverflow.com/a/744093/14444044 |
| 56 | +echo |
| 57 | +echo "# Creating PR to update 4.x branch with commits from $LASTTAG to $TARGTAG." |
| 58 | +FEATBRANCH=update-4x-branch-$(date +%Y%m%d) |
| 59 | +git checkout 4.x |
| 60 | +git checkout -b "$FEATBRANCH" |
| 61 | +git log --pretty=format:"%h" $LASTTAG...$TARGTAG \ |
| 62 | + | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' \ |
| 63 | + | while read sha; do |
| 64 | + echo "$ git cherry-pick $sha" |
| 65 | + git cherry-pick $sha |
| 66 | + done |
| 67 | + |
| 68 | +echo |
| 69 | +echo "# You can create a PR now with:" |
| 70 | +echo " cd $WRKDIR/apm-agent-nodejs" |
| 71 | +echo " gh pr create --fill -w -B 4.x -t 'docs: update 4.x branch for $TARGTAG release'" |
| 72 | + |
0 commit comments