aboutsummaryrefslogtreecommitdiff
path: root/.github/scripts/changelog.sh
diff options
context:
space:
mode:
Diffstat (limited to '.github/scripts/changelog.sh')
-rw-r--r--.github/scripts/changelog.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/.github/scripts/changelog.sh b/.github/scripts/changelog.sh
new file mode 100644
index 0000000..76492cf
--- /dev/null
+++ b/.github/scripts/changelog.sh
@@ -0,0 +1,74 @@
1#!/bin/sh
2# Copyright (c) 2023 Joshua Sing <joshua@hypera.dev>
3#
4# Permission to use, copy, modify, and distribute this software for any
5# purpose with or without fee is hereby granted, provided that the above
6# copyright notice and this permission notice appear in all copies.
7#
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16#
17# Usage: changelog.sh <version>
18# Reads the changelog for the specified version from the changelog file.
19# The output will be reformatted for use in GitHub releases.
20#
21# The changelog file defaults to "ChangeLog", but can be changed by setting
22# the environment variable $CHANGELOG_FILE
23#
24
25set -e
26
27# Check if the version argument is provided
28if [ "$#" -ne 1 ]; then
29 echo "Usage: $0 <version>"
30 exit 1
31fi
32
33version="${1#v}"
34changelog_file="${CHANGELOG_FILE:-ChangeLog}"
35found_version=false
36changelog=""
37
38# Check if the specified changelog file exists
39if [ ! -f "$changelog_file" ]; then
40 echo "Error: Changelog file '$changelog_file' not found"
41 exit 1
42fi
43
44# Read the changelog file line by line
45while IFS= read -r line; do
46 # Check for the version line
47 if echo "$line" | grep -Eq "^${version} - "; then
48 found_version=true
49 continue
50 fi
51
52 # Continue reading the changelog until the next version or end of file,
53 # skipping empty lines
54 if $found_version; then
55 echo "$line" | grep -Eq "^\s*$" && continue
56 echo "$line" | grep -Eq "^[0-9]+\.[0-9]+\.[0-9]+ - " && break
57 changelog="${changelog}${line}\n"
58 fi
59done < "$changelog_file"
60
61# If the specified version was not found, print an error
62if ! $found_version; then
63 echo "Error: Version $version was not found in changelog"
64 exit 1
65fi
66
67# Tidy up the changelog for displaying on GitHub
68changelog=$(echo "$changelog" | sed -e 's/^\t\*/###/' -e 's/^\t//')
69
70# Print the changelog for the specified version
71echo "$changelog"
72echo
73echo "Full changelog: https://github.com/libressl/portable/blob/master/ChangeLog"
74exit 0