Skip to content

Commit c9069b6

Browse files
authored
docs: add top-level explanation to pr-check-changelog.sh (#1337) (#1362)
Signed-off-by: Parth J Chaudhary <parthchaudhary.jc@yahoo.com>
1 parent e35db57 commit c9069b6

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

.github/scripts/pr-check-changelog.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,79 @@
11
#!/bin/bash
22

3+
# ==============================================================================
4+
# Executes When:
5+
# - Run by GitHub Actions workflow: .github/workflows/pr-check-changelog.yml
6+
# - Triggers: workflow_dispatch (manual) and pull_request (opened, edited, synch).
7+
#
8+
# Goal:
9+
# It acts as a gatekeeper for Pull Requests, blocking any merge unless the user
10+
# has added a new entry to CHANGELOG.md and correctly placed it under the
11+
# [Unreleased] section with a proper category subtitle.
12+
#
13+
# ------------------------------------------------------------------------------
14+
# Flow: Basic Idea
15+
# 1. Grabs the official blueprints (upstream/main) to compare against current work.
16+
# 2. Checks if anything new was written. If not, fails immediately.
17+
# 3. Walks through the file line-by-line to ensure new notes are strictly filed
18+
# under [Unreleased] and organized under a category (e.g., "Added", "Fixed").
19+
# 4. If notes are missing, misplaced, or dangling, it fails the build.
20+
# If filed correctly, it approves the build.
21+
#
22+
# ------------------------------------------------------------------------------
23+
# Flow: Detailed Technical Steps
24+
#
25+
# 1️⃣ Network Setup & Fetch
26+
# - Action: Sets up a remote connection to GitHub and runs 'git fetch upstream main'.
27+
# - Why: Needs the "Source of Truth" to compare the Pull Request against.
28+
#
29+
# 2️⃣ Diff Analysis & Visualization
30+
# - Action: Runs 'git diff upstream/main -- CHANGELOG.md'.
31+
# - UX/Display: Prints raw diff with colors (Green=Additions, Red=Deletions)
32+
# strictly for human readability in logs; logic does not rely on colors.
33+
# - Logic: Extracts two lists:
34+
# * added_bullets: Every line starting with '+' (new text).
35+
# * deleted_bullets: Every line starting with '-' (removed text).
36+
# - Immediate Fail Check: If 'added_bullets' is empty, sets failed=1 and exits.
37+
# (You cannot merge code without a changelog entry).
38+
#
39+
# 3️⃣ Context Tracking
40+
# As the script reads the file line-by-line, it tracks:
41+
# - current_release: Main version header (e.g., [Unreleased] or [1.0.0]).
42+
# - current_subtitle: Sub-category (e.g., ### Added, ### Fixed).
43+
# - in_unreleased: Flag (0 or 1).
44+
# * 1 (True) -> Currently inside [Unreleased] (Safe Zone).
45+
# * 0 (False) -> Reading an old version (Danger Zone).
46+
#
47+
# 4️⃣ Sorting
48+
# Flag is ON (1) AND Subtitle is Set -> correctly_placed -> PASS ✅
49+
# Flag is ON (1) BUT Subtitle is Empty -> orphan_entries -> FAIL ❌ (It's dangling, not under a category)
50+
# Flag is OFF (0) -> wrong_release_entries -> FAIL ❌ (edited old history)
51+
#
52+
# 5️⃣ Final Result
53+
# Aggregates failures from Step 4. If any FAIL buckets are not empty, exit 1.
54+
#
55+
# ------------------------------------------------------------------------------
56+
# Parameters:
57+
# None. (The script accepts no command-line arguments).
58+
#
59+
# Environment Variables (Required):
60+
# - GITHUB_REPOSITORY: Used to fetch the upstream 'main' branch for comparison.
61+
#
62+
# Dependencies:
63+
# - git (must be able to fetch upstream)
64+
# - grep, sed (standard Linux utilities)
65+
# - CHANGELOG.md (file must exist in the root directory)
66+
#
67+
# Permissions:
68+
# - 'contents: read' (to access the file structure).
69+
# - Network access (to run 'git fetch upstream').
70+
#
71+
# Returns:
72+
# 0 (Success) - Changes are valid and correctly placed.
73+
# 1 (Failure) - Missing entries, wrong placement (e.g. under released version),
74+
# orphan entries (no subtitle), or accidental deletions.
75+
# ==============================================================================
76+
377
CHANGELOG="CHANGELOG.md"
478

579
# ANSI color codes

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
8888
- Added `Client.from_env()` and network-specific factory methods (e.g., `Client.for_testnet()`) to simplify client initialization and reduce boilerplate. [[#1251](https://github.com/hiero-ledger/hiero-sdk-python/issues/1251)]
8989

9090
### Changed
91+
- Added comprehensive documentation to the PR changelog check script (`.github/scripts/pr-check-changelog.sh`) to clarify behavior, inputs, permissions, and dependencies [(#1337)]
9192
- Refactored `account_create_transaction_without_alias.py` into smaller, modular functions.(#1321)
9293
- Renamed bot-inactivity workflow files to remove "-phase" suffix since the process no longer uses phased execution (#1339)
9394
- Renamed the GitHub notify team script to match its corresponding workflow filename for better maintainability (#1338)

0 commit comments

Comments
 (0)