Skip to content

Commit

Permalink
adding the script to validate changelog
Browse files Browse the repository at this point in the history
Signed-off-by: ntishchauhan0022 <nitishchauhan0022@gmail.com>
  • Loading branch information
nitishchauhan0022 committed Aug 11, 2023
1 parent ee81112 commit 9be2e36
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@ jobs:
output: ''
exit-code: 1
publish: false

validateChangelog:
name: Validate changelog
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Validate changelog
run: make validate-changelog
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,7 @@ help: ## Display this help.
.PHONY: docker-build-dev-containers
docker-build-dev-containers: ## Build dev-containers image
docker build -f .devcontainer/Dockerfile .

.PHONY: validate-changelog
validate-changelog: ## Validate changelog
./hack/validate-changelog.sh
53 changes: 53 additions & 0 deletions hack/validate-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

# Define filename
filename="$SCRIPT_ROOT/CHANGELOG.md"

# Check if file exists
if [[ ! -f "$filename" ]]; then
echo "Error: $filename does not exist."
exit 1
fi

# Read content between "## Unreleased" and "## v" into variable
unreleased=$(awk '/## Unreleased/{flag=1;next}/## v[0-9\.]+/{flag=0}flag' "$filename")

# Check if "Unreleased" section exists
if [[ -z "$unreleased" ]]; then
echo "Error: No 'Unreleased' section found in $filename."
exit 1
fi

# Define a function to extract and sort sections
function extract_and_check() {
local section=$1
local content=$(awk "/### $section/{flag=1;next}/### /{flag=0}flag" <<< "$unreleased" | grep '^- \*\*')

# Skip if content does not exist
if [[ -z "$content" ]]; then
return
fi

local sorted_content=$(echo "$content" | sort)

# Check pattern and throw error if wrong pattern found
echo "$content" | grep -Pv '^(-\s\*\*[^*]+\*\*: .*\(\[#(\d+)\]\(https:\/\/github\.com\/kedacore\/keda\/(pull|issues)\/\2\)\))$' | while read -r line ; do
echo "Error: Wrong pattern found in $section section, line: $line"
exit 1
done

if [ "$content" != "$sorted_content" ]; then
echo "Error: The $section section is not sorted correctly. Correct order:"
echo "$sorted_content"
exit 1
fi
}

# Separate content into different sections and check sorting
extract_and_check "New"
extract_and_check "Improvements"
extract_and_check "Fixes"
extract_and_check "Deprecations"
extract_and_check "Other"

0 comments on commit 9be2e36

Please sign in to comment.