Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding the script to validate changelog #4731

Merged
merged 14 commits into from
Aug 17, 2023
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
nitishchauhan0022 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ repos:
entry: golangci-lint run
types: [go]
pass_filenames: false
- id: validate-changelog
name: Validate Changelog
language: system
entry: "bash hack/validate-changelog.sh"
pass_filenames: false
files: CHANGELOG\.md
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ None.

- **General**: Paused ScaledObject continues working after removing the annotation ([#4733](https://github.com/kedacore/keda/issues/4733))
- **General**: Skip resolving secrets if namespace is restricted ([#4519](https://github.com/kedacore/keda/issues/4519))
- **General**: Adding a changelog validating script to check for formatting and order in make and github action ([#3190](https://github.com/kedacore/keda/issues/3190))
nitishchauhan0022 marked this conversation as resolved.
Show resolved Hide resolved
- **Prometheus**: Authenticated connections to Prometheus work in non-PodIdenty case ([#4695](https://github.com/kedacore/keda/issues/4695))


### Deprecations

You can find all deprecations in [this overview](https://github.com/kedacore/keda/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abreaking-change) and [join the discussion here](https://github.com/kedacore/keda/discussions/categories/deprecations).
Expand Down
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
while IFS= read -r line; do
echo "Error: Wrong pattern found in $section section, line: $line"
exit 1
done < <(grep -Pv '^(-\s\*\*[^*]+\*\*: .*\(\[#(\d+)\]\(https:\/\/github\.com\/kedacore\/keda\/(pull|issues)\/\2\)\))$' <<< "$content")

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"