Fix: Changelog script was broken on markdown changelogs (#13195)

This commit is contained in:
merni-ns 2024-12-25 19:32:34 +05:30 committed by GitHub
parent ee860a5c8e
commit f398a01c3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 17 deletions

36
.github/changelog.py vendored Normal file
View File

@ -0,0 +1,36 @@
import sys
"""
This script assumes changelogs use the following format:
## <major>.x (eg. "## 15.x") to indicate a major version series
### <major>.<minor>[-<suffix>] <date etc> (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()

16
.github/changelog.sh vendored
View File

@ -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

View File

@ -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