Skip to content

Commit

Permalink
chore: add a validation for the changelog format (#761)
Browse files Browse the repository at this point in the history
* chore: add a validation for the changelog format

Signed-off-by: Jorge Turrado <[email protected]>

* update changelog

Signed-off-by: Jorge Turrado <[email protected]>

---------

Signed-off-by: Jorge Turrado <[email protected]>
Co-authored-by: Tom Kerkhove <[email protected]>
  • Loading branch information
JorTurFer and tomkerkhove authored Aug 22, 2023
1 parent 1986161 commit 179b26a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,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
16 changes: 8 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ This changelog keeps track of work items that have been completed and are ready

### Fixes

- **Scaler**: remplement custom interceptor metrics ([#718](https://github.com/kedacore/http-add-on/issues/718))
- **Operator**: Remove ScaledObject `name` & `app` custom labels ([#717](https://github.com/kedacore/http-add-on/issues/717))
- **Interceptor**: fatal error: concurrent map iteration and map write ([#726](https://github.com/kedacore/http-add-on/issues/726))
- **Interceptor**: Keep original Host in the Host header ([#331](https://github.com/kedacore/http-add-on/issues/331))
- **Interceptor**: Provide graceful shutdown for http servers on SIGINT and SIGTERM ([#731](https://github.com/kedacore/http-add-on/issues/731))
- **Interceptor**: Keep original Host in the Host header ([#731](https://github.com/kedacore/http-add-on/issues/331))
- **Operator**: Remove ScaledObject `name` & `app` custom labels ([#717](https://github.com/kedacore/http-add-on/issues/717))
- **Scaler**: Provide graceful shutdown for grpc server on SIGINT and SIGTERM ([#731](https://github.com/kedacore/http-add-on/issues/731))
- **Scaler**: remplement custom interceptor metrics ([#718](https://github.com/kedacore/http-add-on/issues/718))

### Deprecations

Expand All @@ -49,7 +49,7 @@ Previously announced deprecation(s):

### Other

- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
- **General**: Adding a changelog validating script to check for formatting and order ([#761](https://github.com/kedacore/http-add-on/pull/761))

## v0.5.0

Expand All @@ -59,23 +59,23 @@ None.

### New

- **General**: Log incoming requests using the Combined Log Format ([#669](https://github.com/kedacore/http-add-on/pull/669))
- **Routing**: Add multi-host support to `HTTPScaledObject` ([#552](https://github.com/kedacore/http-add-on/issues/552))
- **Routing**: Support path-based routing ([#338](https://github.com/kedacore/http-add-on/issues/338))
- **General**: Log incoming requests using the Combined Log Format ([#669](https://github.com/kedacore/http-add-on/pull/669))

### Improvements

- **General**: Automatically tag Docker image with commit SHA ([#567](https://github.com/kedacore/http-add-on/issues/567))
- **RBAC**: Introduce fine-grained permissions per component and reduce required permissions ([#612](https://github.com/kedacore/http-add-on/issues/612))
- **Operator**: Migrate project to Kubebuilder v3 ([#625](https://github.com/kedacore/http-add-on/issues/625))
- **RBAC**: Introduce fine-grained permissions per component and reduce required permissions ([#612](https://github.com/kedacore/http-add-on/issues/612))
- **Routing**: New routing table implementation that relies on the live state of HTTPScaledObjects on the K8s Cluster instead of a ConfigMap that is updated periodically ([#605](https://github.com/kedacore/http-add-on/issues/605))

### Fixes

- **General**: Changes to HTTPScaledObjects now take effect ([#605](https://github.com/kedacore/http-add-on/issues/605))
- **General**: HTTPScaledObject is the owner of the underlying ScaledObject ([#703](https://github.com/kedacore/http-add-on/issues/703))
- **Routing**: Lookup host without port ([#608](https://github.com/kedacore/http-add-on/issues/608))
- **Controller**: Use kedav1alpha1.ScaledObject default values ([#607](https://github.com/kedacore/http-add-on/issues/607))
- **General**: Changes to HTTPScaledObjects now take effect ([#605](https://github.com/kedacore/http-add-on/issues/605))
- **Routing**: Lookup host without port ([#608](https://github.com/kedacore/http-add-on/issues/608))

### Deprecations

Expand Down
73 changes: 73 additions & 0 deletions hack/validate-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/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

# Storing the version to be checked
mapfile -t versions < <(awk '/## History/{flag=1;next}/## /{flag=0}flag' "$filename" | grep -o '\[[^]]*\]' | grep -v "v1." | sed 's/[][]//g')

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

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

# Separate and sort the **General**: lines
local sorted_general_lines=$(echo "$content" | grep '^- \*\*General\*\*:' | sort --ignore-case)

# Sort the remaining lines
local sorted_content=$(echo "$content" | grep -v '^- \*\*General\*\*:' | sort --ignore-case)

# Check if sorted_general_lines is not empty, then concatenate
if [[ -n "$sorted_general_lines" ]]; then
sorted_content=$(printf "%s\n%s" "$sorted_general_lines" "$sorted_content")
fi

# 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|TODO]+)\]\(https:\/\/github\.com\/kedacore\/(http-add-on|charts|governance)\/(pull|issues|discussions)\/\2\)(?:\|\[#(\d+)\]\(https:\/\/github\.com\/kedacore\/(http-add-on|charts|governance)\/(pull|issues|discussions)\/\5\)){0,}\))$' <<< "$content")

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


# Extract release sections, including "Unreleased", and check them
for version in "${versions[@]}"; do
release_content=$(awk "/## $version/{flag=1;next}/## v[0-9\.]+/{flag=0}flag" "$filename")


if [[ -z "$release_content" ]]; then
echo "No content found for $version Skipping."
continue
fi

echo "Checking section: $version"

# Separate content into different sections and check sorting for each release
extract_and_check "New" "$release_content"
extract_and_check "Experimental" "$release_content"
extract_and_check "Improvements" "$release_content"
extract_and_check "Fixes" "$release_content"
extract_and_check "Deprecations" "$release_content"
extract_and_check "Other" "$release_content"

done

0 comments on commit 179b26a

Please sign in to comment.