#!/bin/bash
# vi:ft=sh:
# Usage: script/changelog [HEAD]
#
# Show changes to runtime files between HEAD and previous release tag.
set -e

current_tag="${GITHUB_REF#refs/tags/}"
start_ref="HEAD"

# Find the previous release on the same branch, skipping prereleases if the
# current tag is a full release
previous_tag=""
while [[ -z $previous_tag || ( $previous_tag == *-* && $current_tag != *-* ) ]]; do
  previous_tag="$(git describe --tags "$start_ref"^ --abbrev=0)"
  start_ref="$previous_tag"
done

git log --first-parent --format='%C(auto,green)* %s%C(auto,reset)%n%w(0,2,2)%+b' \
  --reverse "${previous_tag}.." -- `script/build files` etc share
