From bf4660912f0e34710ea530bddffb70ab051c69a5 Mon Sep 17 00:00:00 2001 From: Max Kotliar Date: Fri, 14 Nov 2025 16:20:20 +0200 Subject: [PATCH] .github: Add changelog tip linter --- .github/scripts/lint-changelog-tip.sh | 48 ++++++++++++++++++++++++++ .github/workflows/changelog-linter.yml | 19 ++++++++++ 2 files changed, 67 insertions(+) create mode 100755 .github/scripts/lint-changelog-tip.sh create mode 100644 .github/workflows/changelog-linter.yml diff --git a/.github/scripts/lint-changelog-tip.sh b/.github/scripts/lint-changelog-tip.sh new file mode 100755 index 0000000000..bd4e853e94 --- /dev/null +++ b/.github/scripts/lint-changelog-tip.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh + +set -e + +CHANGELOG_FILE="docs/victoriametrics/changelog/CHANGELOG.md" + +GITHUB_BASE_REF=${GITHUB_BASE_REF:-"master"} +GIT_REMOTE=${GIT_REMOTE:-"origin"} + +git diff "${GIT_REMOTE}/${GITHUB_BASE_REF}"...HEAD -- $CHANGELOG_FILE > diff.txt +if ! grep -q "^+" diff.txt; then + echo "No additions in CHANGELOG.md" + exit 0 +fi + +ADDED_LINES=$(grep "^+\S" diff.txt | sed 's/^+//') + +START_TIP=$(grep -n "^## tip" "$CHANGELOG_FILE" | head -1 | cut -d: -f1) +if [ -z "$START_TIP" ]; then + echo "ERROR: ${CHANGELOG_FILE} does not contain a ## tip section" + exit 1 +fi + +END_TIP=$(awk "NR>$START_TIP && /^## / {print NR; exit}" "${CHANGELOG_FILE}") +if [ -z "$END_TIP" ]; then + END_TIP=$(wc -l < "$CHANGELOG_FILE") +fi + +BAD=0 +while IFS= read -r line; do + # Grep exact line inside the file and get line numbers + MATCHES=$(grep -n -F "$line" "$CHANGELOG_FILE" | cut -d: -f1) + for m in $MATCHES; do + if [ "$m" -lt "$START_TIP" ] || [ "$m" -gt "$END_TIP" ]; then + echo "'$line' on line ${m} is outside ## tip section (lines ${START_TIP}-${END_TIP})" + BAD=1 + fi + done +done << EOF +$ADDED_LINES +EOF + +if [ "$BAD" -ne 0 ]; then + echo "CHANGELOG modifications must be placed inside the ## tip section." + exit 1 +fi + +echo "CHANGELOG modifications are valid." \ No newline at end of file diff --git a/.github/workflows/changelog-linter.yml b/.github/workflows/changelog-linter.yml new file mode 100644 index 0000000000..f42e4f2842 --- /dev/null +++ b/.github/workflows/changelog-linter.yml @@ -0,0 +1,19 @@ +name: 'changelog-linter' + +on: + pull_request: + paths: + - "docs/victoriametrics/changelog/CHANGELOG.md" + +jobs: + tip-lint: + runs-on: 'ubuntu-latest' + steps: + - uses: 'actions/checkout@v4' + with: + # needed for proper diff + fetch-depth: 0 + + - name: 'Validate that changelog changes are under ## tip' + run: | + GITHUB_BASE_REF=${{ github.base_ref }} ./.github/scripts/lint-changelog-tip.sh