github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/scripts/release-notes/common.sh (about)

     1  #!/bin/sh
     2  
     3  # Initialize a test.
     4  function test_init() {
     5      PYTHON=${PYTHON:-python}
     6  
     7      # We fix all the git per-commit parameters so that the repo structure
     8      # becomes deterministic.
     9  
    10      date="Sun Apr 22 19:26:11 2018 +0200"
    11      author="$t <$t@example.com>"
    12  
    13      export GIT_COMMITTER_DATE=$date
    14      export GIT_COMMITTER_NAME=$t
    15      export GIT_COMMITTER_EMAIL=$t@example.com
    16      flags=(--date="$date" --author="$author")
    17  
    18      rm -rf $t
    19      mkdir $t
    20  }
    21  
    22  # Initialize the repository. Tag the initial commit.
    23  function init_repo() {
    24      git init
    25      touch foo; git add foo; git commit "${flags[@]}" -m "initial"; git tag initial
    26  	git tag v000-base
    27  }
    28  
    29  # Perform some arbitrary change.
    30  # $1 = commit message.
    31  function make_change() {
    32      git commit --allow-empty "${flags[@]}" -m "$1"
    33  }
    34  
    35  # Mark a branch tip as PR tip.
    36  # $1 = PR number.
    37  function tag_pr() {
    38      mkdir -p .git/refs/pull/origin
    39      git log --pretty=tformat:%H > .git/refs/pull/origin/$1
    40  }
    41  
    42  # Merge a regular branch into the current branch.
    43  # $1 = branch name
    44  function merge_branch() {
    45      git merge --no-ff -m "Merge $1 into current" $1
    46      git commit --amend --no-edit "${flags[@]}"
    47  }
    48  
    49  # Merge a PR branch into the current branch.
    50  # $1 = branch name
    51  # $2 = PR number
    52  # $3 = PR title
    53  function merge_pr() {
    54      branchname=$1
    55      prnum=$2
    56      prtitle=$3
    57      git merge --no-ff -m "Merge #$prnum
    58  
    59  $prnum: $prtitle r=foo a=bar
    60  
    61  Release note (core change): this must not be included.
    62  
    63  Co-authored-by: invisible <invisible@example.com>
    64  " $branchname
    65      git commit --amend --no-edit "${flags[@]}"
    66  
    67      # Make a dummy second pr just to compare the PR message.
    68      git checkout -b dummypr
    69      make_change "merge pr canary
    70  
    71  Release note: none
    72  "
    73      prnum=$(expr $prnum \* 100)
    74      tag_pr $prnum
    75  
    76      git checkout master
    77      git merge --no-ff -m "Merge pull request #$prnum from foo/bar
    78  
    79  $prtitle alternate format
    80  " dummypr
    81      git commit --amend --no-edit "${flags[@]}"
    82      git branch -D dummypr
    83  }
    84  
    85  function test_end() {
    86      # Check the repo layout is correct.
    87      (cd $t && git log --graph --pretty=oneline) >$t.graph.txt
    88      if test -z "$rewrite"; then
    89          diff -u $t.graph.txt $t.graph.ref.txt
    90      else
    91          mv -f $t.graph.txt $t.graph.ref.txt
    92      fi
    93  
    94      # Check the generated release notes.
    95      (cd $t && $PYTHON $relnotescript --hide-header --hide-downloads-section --from initial --until master "$@") >$t.notes.txt
    96      if test -z "$rewrite"; then
    97          diff -u $t.notes.txt $t.notes.ref.txt
    98      else
    99          mv -f $t.notes.txt $t.notes.ref.txt
   100      fi
   101      rm -rf $t
   102  }