Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/scripts/pr-check-changelog.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
#!/bin/bash

Comment on lines 1 to 2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add required error handling directives.

Per coding guidelines, scripts in .github/scripts/**/*.sh MUST use set -euo pipefail to fail fast on errors, undefined variables, and pipeline failures.

🔎 Proposed fix
 #!/bin/bash
+set -euo pipefail
 

Based on coding guidelines, all scripts in .github/scripts/ must include this directive.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/bash
#!/bin/bash
set -euo pipefail

# ==============================================================================
# Executes When:
# - Run by GitHub Actions workflow: .github/workflows/pr-check-changelog.yml
# - Triggers: workflow_dispatch (manual) and pull_request (opened, edited, synch).
#
# Goal:
# It acts as a gatekeeper for Pull Requests, blocking any merge unless the user
# has added a new entry to CHANGELOG.md and correctly placed it under the
# [Unreleased] section with a proper category subtitle.
#
# ------------------------------------------------------------------------------
# Flow: Basic Idea
# 1. Grabs the official blueprints (upstream/main) to compare against current work.
# 2. Checks if anything new was written. If not, fails immediately.
# 3. Walks through the file line-by-line to ensure new notes are strictly filed
# under [Unreleased] and organized under a category (e.g., "Added", "Fixed").
# 4. If notes are missing, misplaced, or dangling, it fails the build.
# If filed correctly, it approves the build.
#
# ------------------------------------------------------------------------------
# Flow: Detailed Technical Steps
#
# 1️⃣ Network Setup & Fetch
# - Action: Sets up a remote connection to GitHub and runs 'git fetch upstream main'.
# - Why: Needs the "Source of Truth" to compare the Pull Request against.
#
# 2️⃣ Diff Analysis & Visualization
# - Action: Runs 'git diff upstream/main -- CHANGELOG.md'.
# - UX/Display: Prints raw diff with colors (Green=Additions, Red=Deletions)
# strictly for human readability in logs; logic does not rely on colors.
# - Logic: Extracts two lists:
# * added_bullets: Every line starting with '+' (new text).
# * deleted_bullets: Every line starting with '-' (removed text).
# - Immediate Fail Check: If 'added_bullets' is empty, sets failed=1 and exits.
# (You cannot merge code without a changelog entry).
#
# 3️⃣ Context Tracking
# As the script reads the file line-by-line, it tracks:
# - current_release: Main version header (e.g., [Unreleased] or [1.0.0]).
# - current_subtitle: Sub-category (e.g., ### Added, ### Fixed).
# - in_unreleased: Flag (0 or 1).
# * 1 (True) -> Currently inside [Unreleased] (Safe Zone).
# * 0 (False) -> Reading an old version (Danger Zone).
#
# 4️⃣ Sorting
# The script matches new lines against the current context:
# Flag is ON (1) AND Subtitle is Set -> correctly_placed -> PASS ✅
# Flag is ON (1) BUT Subtitle is Empty -> orphan_entries -> FAIL ❌ (It's dangling, not under a category)
# Flag is OFF (0) -> wrong_release_entries -> FAIL ❌ (edited old history)
#
# 5️⃣ Final Result
# Aggregates failures from Step 4. If any FAIL buckets are not empty, exit 1.
#
# ------------------------------------------------------------------------------
# Parameters:
# None. (The script accepts no command-line arguments).
#
# Environment Variables (Required):
# - GITHUB_REPOSITORY: Used to fetch the upstream 'main' branch for comparison.
#
# Dependencies:
# - git (must be able to fetch upstream)
# - grep, sed (standard Linux utilities)
# - CHANGELOG.md (file must exist in the root directory)
#
# Permissions:
# - 'contents: read' (to access the file structure).
# - Network access (to run 'git fetch upstream').
#
# Returns:
# 0 (Success) - Changes are valid and correctly placed.
# 1 (Failure) - Missing entries, wrong placement (e.g. under released version),
# orphan entries (no subtitle), or accidental deletions.
# ==============================================================================

CHANGELOG="CHANGELOG.md"

# ANSI color codes
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.

### Changed

- Added comprehensive documentation to the PR changelog check script (`.github/scripts/pr-check-changelog.sh`) to clarify behavior, inputs, permissions, and dependencies (#1337)
- Renamed the GitHub notify team script to match its corresponding workflow filename for better maintainability (#1338)
- style: apply black formatting to examples (#1299)
-Update GitHub workflow names in `.github/workflows/bot-workflows.yml` to match correct references [(#1284)]
Expand Down
Loading