From f398a01c3ce4d3b6f9e2656c0160546f73f11f13 Mon Sep 17 00:00:00 2001 From: merni-ns <66267867+merni-ns@users.noreply.github.com> Date: Wed, 25 Dec 2024 19:32:34 +0530 Subject: [PATCH] Fix: Changelog script was broken on markdown changelogs (#13195) --- .github/changelog.py | 36 ++++++++++++++++++++++++++++ .github/changelog.sh | 16 ------------- .github/workflows/release-source.yml | 11 ++++++++- 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 .github/changelog.py delete mode 100755 .github/changelog.sh diff --git a/.github/changelog.py b/.github/changelog.py new file mode 100644 index 0000000000..007774e8ec --- /dev/null +++ b/.github/changelog.py @@ -0,0 +1,36 @@ +import sys + +""" +This script assumes changelogs use the following format: + ## .x (eg. "## 15.x") to indicate a major version series + ### .[-] (eg. "## 15.0 (2025-04-01)", "### 15.1-beta1 (2024-12-25)") to indicate an individual version +""" + +def main(): + current_version = sys.argv[1] + stable_version = current_version.split("-")[0] + major_version = current_version.split(".")[0] + # set when current version is found + current_found = False + + with open("changelog.md", "r") as file: + for line in file: + if line.startswith("### "): + if not line.startswith(f"### {current_version} ") and not current_found: + # First version in changelog should be the current one + sys.stderr.write(f"Changelog doesn't start with current version ({current_version})\n") + sys.exit(1) + if not line.startswith(f"### {stable_version}"): + # Reached a previous stable version + break + if line.startswith(f"### {current_version} "): + current_found = True + elif line.startswith("## "): + if not line.startswith(f"## {major_version}.x"): + # Reached a previous major version + break + + print(line.rstrip()) + +if __name__ == '__main__': + main() diff --git a/.github/changelog.sh b/.github/changelog.sh deleted file mode 100755 index 26a66d6bdd..0000000000 --- a/.github/changelog.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -tag=$(git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed 's@\^0$@@') - -# If we are a tag, show the part of the changelog till (but excluding) the last stable -if [ -n "$tag" ]; then - grep='^[0-9]\+\.[0-9]\+[^-]' - next=$(cat changelog.md | grep '^[0-9]' | awk 'BEGIN { show="false" } // { if (show=="true") print $0; if ($1=="'$tag'") show="true"} ' | grep "$grep" | head -n1 | sed 's/ .*//') - cat changelog.md | awk 'BEGIN { show="false" } /^[0-9]+.[0-9]+/ { if ($1=="'$next'") show="false"; if ($1=="'$tag'") show="true";} // { if (show=="true") print $0 }' - exit 0 -fi - -# In all other cases, show the git log of the last 7 days -revdate=$(git log -1 --pretty=format:"%ci") -last_week=$(date -d "$revdate -7days" +"%Y-%m-%d %H:%M") -git log --after="${last_week}" --pretty=fuller diff --git a/.github/workflows/release-source.yml b/.github/workflows/release-source.yml index 59de61e232..9377e73dc7 100644 --- a/.github/workflows/release-source.yml +++ b/.github/workflows/release-source.yml @@ -90,10 +90,10 @@ jobs: - name: Generate metadata id: metadata + shell: bash run: | echo "::group::Prepare metadata files" cmake -DGENERATE_OTTDREV=1 -P cmake/scripts/FindVersion.cmake - ./.github/changelog.sh > .changelog TZ='UTC' date +"%Y-%m-%d %H:%M UTC" > .release_date cat .ottdrev | cut -f 1 -d$'\t' > .version @@ -103,6 +103,8 @@ jobs: FOLDER="${{ env.FOLDER_RELEASES }}" TRIGGER_TYPE="new-tag" + + python3 ./.github/changelog.py "$(cat .version)" > .changelog else IS_TAG="false" @@ -123,6 +125,13 @@ jobs: # put in their own folder. FOLDER="${{ env.FOLDER_BRANCHES }}/${BRANCH}" TRIGGER_TYPE="new-branch" + + # For nightlies, use the git log of the last 7 days as changelog. + revdate=$(git log -1 --pretty=format:"%ci") + last_week=$(date -d "$revdate -7days" +"%Y-%m-%d %H:%M") + echo "## Version $(cat .version) - changes since ${last_week}" > .changelog + echo "" >> .changelog + git log --oneline --after="${last_week}" >> .changelog fi fi