github.com/vmware/go-vcloud-director/v2@v2.24.0/scripts/make-changelog.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # This script collects the single change files and generates CHANGELOG entries
     4  # for the whole release
     5  
     6  # .changes is the directory where the change files are
     7  sources=.changes
     8  
     9  if [ ! -d $sources ]
    10  then
    11      echo "Directory $sources not found"
    12      exit 1
    13  fi
    14  
    15  function check_eol {
    16      file_name=$1
    17      # Checks the last line of the file.
    18      # Counts the number of lines (==EOL)
    19      has_eol=$(tail -n 1 $file_name | wc -l | tr -d ' ' | tr -d '\t')
    20  
    21      # If there isn't an EOL, we add one on the spot
    22      if [ "$has_eol" == "0" ]
    23      then
    24          echo ""
    25      fi
    26  }
    27  
    28  # We must indicate a version on the command line
    29  version=$1
    30  
    31  # If no version was provided, we use the current release version
    32  if [  -z "$version" ] 
    33  then
    34      echo "No version was provided"
    35      exit 1
    36  fi
    37  
    38  
    39  # If the provided version does not exist, there is nothing to do
    40  if [ ! -d  $sources/$version ]
    41  then
    42      echo "# Changes directory $sources/$version not found"
    43      exit 1
    44  fi
    45  
    46  # The "sections" file contains the CHANGELOG headers
    47  if [ ! -f $sources/sections ]
    48  then
    49      echo "File $sources/sections not found"
    50      exit 1
    51  fi
    52  sections=$(cat $sources/sections)
    53  
    54  cd $sources/$version
    55  
    56  for section in $sections
    57  do
    58      # Check whether we have any file for this section
    59      num=$(ls | grep "\-${section}.md" | wc -l | tr -d ' \t')
    60      # if there are no files for this section, we skip
    61      if [ "$num" == "0" ]
    62      then
    63          continue
    64      fi
    65  
    66      # Generate the header
    67      echo "### $(echo $section | tr 'a-z' 'A-Z' | tr '-' ' ')"
    68  
    69      # Print the changes files, sorted by PR number
    70      for f in $(ls *${section}.md | sort -n)
    71      do
    72          cat $f
    73          check_eol $f
    74      done
    75      echo ""
    76  done
    77