github.com/quay/claircore@v1.5.28/.github/scripts/changelog-render (about)

     1  #!/bin/sh
     2  set -e
     3  # This script has some colon-commands to help in debugging -- they're shown in
     4  # "-x" output, whereas comments are not.
     5  : "${GIT_NOTES_REF:=refs/notes/changelog}"
     6  GIT_NOTES_DISPLAY_REF=$GIT_NOTES_REF
     7  export GIT_NOTES_REF GIT_NOTES_DISPLAY_REF
     8  while getopts hf:m flag; do
     9  	case "$flag" in
    10  		f) prevtag="$OPTARG" ;;
    11  		m)
    12  			: no markup
    13  			nomarkup=1
    14  			;;
    15  		h|?) printf 'Usage: %s [-f prevtag] [next]\n' "$0" >&2
    16  			printf '  -f prev\tforce previous tag (instead of guessing)\n' >&2
    17  			exit 2 ;;
    18  	esac
    19  done
    20  shift $((OPTIND - 1))
    21  
    22  needcmds() {
    23  	if [ "$#" -eq 0 ]; then
    24  		echo programmer error: missing argument to "'needcmds'"
    25  		exit 1
    26  	fi
    27  	for cmd in "$@"; do
    28  		command -v "$cmd" >/dev/null || {
    29  			echo Need "$cmd" >&2
    30  			exit 1
    31  		}
    32  	done
    33  }
    34  needcmds git grep sed wc fold
    35  [ -z "$prevtag" ] && prevtag="$(git tag --sort=-taggerdate --merged | grep '^v' | sed 1q)"
    36  nexttag="${1:-$(echo "$prevtag" | cut -d. -f-2).$(($(echo "$prevtag" | cut -d. -f3)+1))}"
    37  if echo "${nexttag}" | grep -vq '^v[0-9]\+\.[0-9]\+\.[0-9]\+'; then
    38  	printf 'bad tag format: %s\n' "${nexttag}" >&2
    39  	exit 1
    40  fi
    41  : previous tag: "${prevtag}"
    42  : guessed next tag: "${nexttag}"
    43  
    44  work=$(mktemp -d)
    45  trap 'rm -rf "$work"' EXIT
    46  newnotes="${work}/nn"
    47  notebody="${work}/body"
    48  sedf="${work}/sed"
    49  
    50  # Write out the sed script and header based on whether explicit markup was asked
    51  # for or not.
    52  if [ -n "$nomarkup" ]; then
    53  	cat <<'.' >"${sedf}"
    54  1s/^/- /
    55  2,$s/^/  /
    56  $a\
    57  .
    58  	cat <<. >"${newnotes}"
    59  ## ${nexttag} - $(date +%F)
    60  
    61  .
    62  else
    63  	cat <<'.' >"${sedf}"
    64  s/PROJQUAY-[0-9]\+/[&](https:\/\/issues.redhat.com\/browse\/&)/
    65  1s/^/- /
    66  2c\
    67    <details>
    68  3,$s/^/  /
    69  $a\
    70    </details>\
    71  .
    72  	cat <<. >"${newnotes}"
    73  <a name="${nexttag}"></a>
    74  ## [${nexttag}] - $(date +%F)
    75  [${nexttag}]: https://github.com/quay/claircore/compare/${prevtag}...${nexttag}
    76  
    77  .
    78  fi
    79  
    80  git rev-list "${prevtag}..." |
    81  	while read -r commit; do
    82  		git notes show "$commit" 2>/dev/null >"${notebody}" || continue
    83  		if grep -q '^$' <"${notebody}"; then
    84  			: list item
    85  			fold <"${notebody}" |
    86  				sed -f "$sedf" >> "${newnotes}"
    87  		else
    88  			: graf
    89  			fold <"${notebody}" >> "${newnotes}"
    90  			printf '\n' >> "${newnotes}"
    91  		fi
    92  	done
    93  test "$(wc -l < "${newnotes}")" -eq 4 &&
    94  	printf 'Nothing interesting happened this release.\n\n' >> "${newnotes}"
    95  
    96  cat "${newnotes}"