|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -o pipefail |
| 18 | +this=`basename $0` |
| 19 | + |
| 20 | +usage () { |
| 21 | +cat << EOF |
| 22 | +Generate a changelog for the specified tag |
| 23 | +Usage: $this --reference <tag> [--remote <remote_name>] |
| 24 | +
|
| 25 | +Options: |
| 26 | + --since specify the tag to start the changelog from (default: latest tag) |
| 27 | + --remote specify the remote to fetch tags from (default: upstream) |
| 28 | + --version specify the version to be released |
| 29 | + --help/-h show this help and exit |
| 30 | +
|
| 31 | +EOF |
| 32 | +} |
| 33 | + |
| 34 | +REMOTE="upstream" |
| 35 | +VERSION="" |
| 36 | +REFERENCE= |
| 37 | + |
| 38 | +# Parse command line options |
| 39 | +while [[ $# -gt 0 ]]; do |
| 40 | + key="$1" |
| 41 | + case $key in |
| 42 | + --since) |
| 43 | + REFERENCE="$2" |
| 44 | + shift # past argument |
| 45 | + shift # past value |
| 46 | + ;; |
| 47 | + --remote) |
| 48 | + REMOTE="$2" |
| 49 | + shift # past argument |
| 50 | + shift # past value |
| 51 | + ;; |
| 52 | + --version) |
| 53 | + VERSION="$2" |
| 54 | + shift # past argument |
| 55 | + shift # past value |
| 56 | + ;; |
| 57 | + --help/-h) usage |
| 58 | + exit 0 |
| 59 | + ;; |
| 60 | + *) usage |
| 61 | + exit 1 |
| 62 | + ;; |
| 63 | + esac |
| 64 | +done |
| 65 | + |
| 66 | +# Fetch the latest tags from the remote |
| 67 | +git fetch $REMOTE --tags |
| 68 | + |
| 69 | +# if REFERENCE is not set, get the latest tag |
| 70 | +if [ -z "$REFERENCE" ]; then |
| 71 | + REFERENCE=$(git describe --tags $(git rev-list --tags --max-count=1)) |
| 72 | +fi |
| 73 | + |
| 74 | +# Print the changelog |
| 75 | +echo "## Changelog" |
| 76 | +echo "" |
| 77 | +echo "### Version $VERSION" |
| 78 | + |
| 79 | +# Iterate over the commit messages and ignore the ones that start with "Merge" or "Bump" |
| 80 | +git log --pretty=format:"%s" $REFERENCE..@ | grep -Ev "(^Merge )|(^Bump)" | sed 's/^\(.*\)/- \1/g' |
0 commit comments