Skip to content

Commit

Permalink
[build] update change log file to accept language
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Dec 8, 2023
1 parent c606239 commit 757de62
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions scripts/update-changelogs.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
#!/usr/bin/env bash

# Update changelogs in each of the bindings based on commits between provided reference and HEAD
PREVIOUS_TAG=$1
VERSION=$1
IFS='.' read -r MAJOR_VERSION MINOR_VERSION PATCH_VERSION <<< "$VERSION"
LANGUAGE=$2

calculate_previous_tag() {
if [ "$PATCH_VERSION" -ne 0 ]; then
PREVIOUS_TAG="selenium-$MAJOR_VERSION.$MINOR_VERSION.$(($PATCH_VERSION - 1))"
if [ -n "$LANGUAGE" ] && [ "$PATCH_VERSION" -gt 1 ]; then
PREVIOUS_TAG="${PREVIOUS_TAG}-$(get_tag_language)"
fi
elif [ $MINOR_VERSION -ne 0 ]; then
PREVIOUS_TAG="selenium-$MAJOR_VERSION.$(($MINOR_VERSION - 1)).0"
else
echo "Cannot determine the previous tag from $VERSION"
exit 1
fi
}

get_tag_language() {
case $LANGUAGE in
py) echo "python" ;;
rb) echo "ruby" ;;
*) echo "$LANGUAGE" ;;
esac
}

prepend_git_log_to_file() {
local FILE="$1"
local DIR="${FILE%/*}"

local TEMP_FILE="$(mktemp)"

git --no-pager log "${PREVIOUS_TAG}...${HEAD}" --pretty=format:"* %B %n %an http://github.com/seleniumhq/selenium/commit/%H" --reverse -- "$DIR/" > "$TEMP_FILE"
git --no-pager log "${PREVIOUS_TAG}...HEAD" --pretty=format:"* %B %n %an http://github.com/seleniumhq/selenium/commit/%H" --reverse -- "$DIR/" > "$TEMP_FILE"
echo -e "\n\n" >> "$TEMP_FILE"

cat "$FILE" >> "$TEMP_FILE"
mv "$TEMP_FILE" "$FILE"
}

git --no-pager log "${PREVIOUS_TAG}...${HEAD}" --pretty=format:"* %B %n %an http://github.com/seleniumhq/selenium/commit/%H" --reverse -- . ':!rb/' ':!py/' ':!javascript/' ':!dotnet/' ':!java/' ':!rust/' >> changelog_updates.md
update_language_changelogs() {
calculate_previous_tag

for changelog in "${CHANGELOGS[@]}"; do
lang=$(echo "$changelog" | cut -d/ -f1)
if [[ "$LANGUAGE" == "$lang" || "$LANGUAGE" == "all" ]]; then
prepend_git_log_to_file "$changelog"
fi
done
}

print_generic_changes() {
git --no-pager log "${PREVIOUS_TAG}...HEAD" --pretty=format:"* %B %n %an http://github.com/seleniumhq/selenium/commit/%H" --reverse -- . ':!rb/' ':!py/' ':!javascript/' ':!dotnet/' ':!java/' ':!rust/' >> changelog_updates.md
}

CHANGELOGS=(
"dotnet/CHANGELOG"
Expand All @@ -27,6 +63,5 @@ CHANGELOGS=(
"rust/CHANGELOG.md"
)

for changelog in "${CHANGELOGS[@]}"; do
prepend_git_log_to_file "$changelog"
done
update_language_changelogs
print_generic_changes

0 comments on commit 757de62

Please sign in to comment.