yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Jay KwakAdd a new option to use hash for release-note script (#8096)1088e57b6

master
3.6 KiB122 linesraw
1#!/usr/bin/env bash
2# This script generates a release note.
3# It prints information about breaking-changes first and the rest.
4# The content is mostly based on `git log --oneline --since 202X-YY-ZZ`.
5
6# Usage: the script takes command-line arguments to specify the range of commits to include.
7# You can use either:
8# 1. Date-based range with --since: docs/scripts/release-note.sh --since 2025-08-06
9# 2. Hash-based range with --previous-hash: docs/scripts/release-note.sh --previous-hash abc123
10# 3. Legacy positional argument (deprecated): docs/scripts/release-note.sh 2024-07-01
11
12# This script is supposed to work on all Windows based shell systems including WSL and git-bash.
13# If you make any modifications, please test them, because CI doesn't test this script.
14
15verbose=true
16$verbose && echo "Reminder: PLEASE make sure your local repo is up-to-date before running the script." >&2
17
18gh=""
19for candidate in \
20  "$(which gh)" \
21  "$(which gh.exe)" \
22  "/mnt/c/Program Files/GitHub CLI/gh.exe" \
23  "/c/Program Files/GitHub CLI/gh.exe" \
24  "/cygdrive/c/Program Files/GitHub CLI/gh.exe"; do
25  if [ -x "$candidate" ]; then
26    gh="$candidate"
27    break
28  fi
29done
30if [ "$gh" = "" ] || ! [ -x "$gh" ]; then
31  echo "File not found: gh or gh.exe"
32  echo "GitHub CLI can be downloaded from https://cli.github.com"
33  exit 1
34fi
35$verbose && echo "gh is found from: $gh" >&2
36
37# Parse command-line arguments
38use_hash=false
39since=""
40previous_hash=""
41
42while [[ $# -gt 0 ]]; do
43  case $1 in
44  --since)
45    since="$2"
46    use_hash=false
47    shift 2
48    ;;
49  --previous-hash)
50    previous_hash="$2"
51    use_hash=true
52    shift 2
53    ;;
54  *)
55    # Legacy positional argument support
56    if [ "$since" = "" ] && [ "$previous_hash" = "" ]; then
57      since="$1"
58      use_hash=false
59    else
60      echo "Too many arguments or mixed argument styles"
61      exit 1
62    fi
63    shift
64    ;;
65  esac
66done
67
68# Validate arguments
69if [ "$since" = "" ] && [ "$previous_hash" = "" ]; then
70  echo "This script requires either --since or --previous-hash option."
71  echo "Usage: $0 [--since DATE | --previous-hash HASH]"
72  echo "  --since DATE          Generate notes since the given date (e.g., 2025-08-06)"
73  echo "  --previous-hash HASH  Generate notes since the given commit hash"
74  echo ""
75  echo "Legacy usage (deprecated): $0 DATE"
76  exit 1
77fi
78
79# Get commits based on the specified range
80if [ "$use_hash" = true ]; then
81  commits="$(git log --oneline "$previous_hash"..HEAD)"
82else
83  commits="$(git log --oneline --since "$since")"
84fi
85commitsCount="$(echo "$commits" | wc -l)"
86
87echo "=== Breaking changes ==="
88breakingChanges=""
89for i in $(seq "$commitsCount"); do
90  line="$(echo "$commits" | head -n "$i" | tail -1)"
91
92  # Get PR number from the git commit title
93  pr="$(echo "$line" | grep '#[1-9][0-9][0-9][0-9][0-9]*' | sed 's|.* (\#\([1-9][0-9][0-9][0-9][0-9]*\))|\1|')"
94  [ "$pr" = "" ] && continue
95
96  # Check if the PR is marked as a breaking change
97  if "$gh" issue view "$pr" --json labels | grep -q 'pr: breaking change'; then
98    breakingChanges+="$line"
99  fi
100done
101if [ "$breakingChanges" = "" ]; then
102  echo "No breaking changes"
103else
104  echo "$breakingChanges"
105fi
106echo ""
107
108echo "=== All changes for this release ==="
109for i in $(seq "$commitsCount"); do
110  line="$(echo "$commits" | head -n "$i" | tail -1)"
111
112  result="$line"
113  # Get PR number from the git commit title
114  pr="$(echo "$line" | grep '#[1-9][0-9][0-9][0-9][0-9]*' | sed 's|.* (\#\([1-9][0-9][0-9][0-9][0-9]*\))|\1|')"
115  if [ "$pr" != "" ]; then
116    # Mark breaking changes with "[BREAKING]"
117    if "$gh" issue view "$pr" --json labels | grep -q 'pr: breaking change'; then
118      result="[BREAKING] $line"
119    fi
120  fi
121  echo "$result"
122done