File: extract-release-notes.sh

package info (click to toggle)
php-json-schema 6.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,588 kB
  • sloc: php: 12,943; sh: 176; makefile: 153; python: 28
file content (63 lines) | stat: -rwxr-xr-x 1,227 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
set -e

# Script to extract release notes for a specific version from CHANGELOG.md
# Usage: ./bin/extract-release-notes.sh "6.7.0"
#
# Arguments:
#   $1 - Version number (e.g., "6.7.0")
#
# This script extracts all the content between the specified version header
# and the next version header

if [ $# -lt 1 ]; then
  echo "Usage: $0 <version>"
  echo ""
  echo "Example: $0 '6.7.0'"
  exit 1
fi

VERSION="$1"

if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
    echo "Error: Version must be in format X.Y.Z (e.g., 6.7.0)"
    exit 1
fi

# Check if CHANGELOG.md exists
if [ ! -f CHANGELOG.md ]; then
  echo "Error: CHANGELOG.md not found in current directory"
  exit 1
fi

# Use awk to extract the release notes for the specified version
awk -v version="$VERSION" '
BEGIN { in_version = 0; found = 0 }

# Match the version header
$0 ~ "^## \\[" version "\\]" {
  in_version = 1
  found = 1
  next
}

# Match any other version header
/^## \[/ {
  if (in_version) {
    exit
  }
  next
}

# Print content when in the correct version section
in_version {
  print
}

END {
  if (!found) {
    print "Error: Version " version " not found in CHANGELOG.md" > "/dev/stderr"
    exit 1
  }
}
' CHANGELOG.md