Skip to content

Commit

Permalink
Add script to generate chart CHANGELOG after released (#2054)
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Dec 8, 2023
1 parent 3e19181 commit 772d592
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/helm-chart-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,18 @@ jobs:
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: Update chart CHANGELOG
run: ./generate_chart_changelog.sh

- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "Selenium CI Bot"
git commit -m "Update chart CHANGELOG [skip ci]" -a
- name: Push changes
uses: ad-m/github-push-action@d91a481090679876dfc4178fef17f286781251df # master
with:
github_token: ${{ secrets.SELENIUM_CI_TOKEN }}
branch: trunk
19 changes: 17 additions & 2 deletions charts/selenium-grid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Change Log
## :heavy_check_mark: selenium-grid-0.26.0

All notable changes to this helm chart will be documented in this file.
- Chart is using image tag 4.16.0-20231206

### Added
- feat(chart): Add default annotations for ingress nginx controller (#2047) :: Viet Nguyen Duc
- feat: Video image with based FFmpeg-6.1 on Ubuntu-22.04 (#2042) :: Viet Nguyen Duc

### Fixed
- bug(#1824): Container ENV SE_NODE_SESSION_TIMEOUT not take effect (#2044) :: Viet Nguyen Duc
- bug(#2038): Rollback io.opentelemetry 1.31.0 - add test tracing enabled (#2040) :: Viet Nguyen Duc

### Changed
- Update tag in docs and files :: Selenium CI Bot
- Update chart CHANGELOG [skip ci] :: Viet Nguyen Duc
- test(chart): Parallel tests execution against autoscaling in Kubernetes (#2046) :: Viet Nguyen Duc
- test(chart): Chart template render and assert output (#2043) :: Viet Nguyen Duc
- test(chart): Add test for setting registry to pull images (#2036) :: Viet Nguyen Duc

## :heavy_check_mark: 0.25.3

Expand Down
85 changes: 85 additions & 0 deletions generate_chart_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

# Specify the output file for the CHANGELOG
CHART_DIR="./charts/selenium-grid"
CHANGELOG_FILE="./charts/selenium-grid/CHANGELOG.md"
TAG_PATTERN="selenium-grid"

# Get current chart app version
CHART_APP_VERSION=$(find . \( -type d -name .git -prune \) -o -type f -name 'Chart.yaml' -print0 | xargs -0 cat | grep ^appVersion | cut -d ':' -f 2 | tr -d '[:space:]')

# Generate the changelog
generate_changelog() {
# Get a list of tags sorted by commit date
tags=($(git tag --sort=committerdate | grep "^$TAG_PATTERN"))
tags_size=${#tags[@]}

# Check if there are tags
if [ ${#tags[@]} -eq 0 ]; then
commit_range="HEAD"
elif [ ${#tags[@]} -eq 1 ]; then
previous_tag="${tags[$tags_size-1]}"
current_tag="HEAD"
commit_range="${previous_tag}..${current_tag}"
else
previous_tag="${tags[$tags_size-2]}"
current_tag="${tags[$tags_size-1]}"
commit_range="${previous_tag}..${current_tag}"
fi

# Get the changes for each section (Added, Removed, Fixed, Changed)
image_tag_changes=$(echo "Chart is using image tag $CHART_APP_VERSION" | sed -e 's/^/- /')
added_changes=$(git log --pretty=format:"%s :: %an" "$commit_range" -- "$CHART_DIR" | grep -iE "^feat|^add" | sed -e 's/^/- /')
removed_changes=$(git log --pretty=format:"%s :: %an" "$commit_range" -- "$CHART_DIR" | grep -iE "^remove|^deprecate|^delete" | sed -e 's/^/- /')
fixed_changes=$(git log --pretty=format:"%s :: %an" "$commit_range" -- "$CHART_DIR" | grep -iE "^fix|^bug" | sed -e 's/^/- /')
changed_changes=$(git log --pretty=format:"%s :: %an" "$commit_range" -- "$CHART_DIR" | grep -iEv "^feat|^add|^remove|^deprecate|^delete|^fix|^bug" | sed -e 's/^/- /')

if [[ $(cat $CHANGELOG_FILE) == *"${current_tag}"* ]]; then
echo "Changelog already generated for ${current_tag}"
exit 0
fi

# Create a temporary file
temp_file=$(mktemp)

# Write to the temporary file
echo "## :heavy_check_mark: ${current_tag}" >> "$temp_file"
echo "" >> "$temp_file"
echo "$image_tag_changes" >> "$temp_file"
echo "" >> "$temp_file"

if [ -n "$added_changes" ]; then
echo "### Added" >> "$temp_file"
echo "$added_changes" >> "$temp_file"
echo "" >> "$temp_file"
fi

if [ -n "$removed_changes" ]; then
echo "### Removed" >> "$temp_file"
echo "$removed_changes" >> "$temp_file"
echo "" >> "$temp_file"
fi

if [ -n "$fixed_changes" ]; then
echo "### Fixed" >> "$temp_file"
echo "$fixed_changes" >> "$temp_file"
echo "" >> "$temp_file"
fi

if [ -n "$changed_changes" ]; then
echo "### Changed" >> "$temp_file"
echo "$changed_changes" >> "$temp_file"
echo "" >> "$temp_file"
fi

# Append the existing content of CHANGELOG to the temporary file
cat "$CHANGELOG_FILE" >> "$temp_file"

# Overwrite CHANGELOG with the content of the temporary file
mv "$temp_file" "$CHANGELOG_FILE"
}

# Run the function to generate the changelog
generate_changelog

echo "Changelog generated successfully at $CHANGELOG_FILE"
4 changes: 2 additions & 2 deletions update_tag_in_docs_and_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ echo -e "\033[0;32m LATEST_TAG -> ${LATEST_TAG}\033[0m"
echo -e "\033[0;32m NEXT_TAG -> ${NEXT_TAG}\033[0m"

# If you want to test this locally and you are using macOS, do `brew install gnu-sed` and change `sed` for `gsed`.
find . \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s/${LATEST_TAG}/${NEXT_TAG}/g"
find . \( -type d -name .git -prune \) -o -type f ! -name 'CHANGELOG.md' -print0 | xargs -0 sed -i "s/${LATEST_TAG}/${NEXT_TAG}/g"

echo -e "\033[0;32m Updating date used in some docs and files...\033[0m"
echo -e "\033[0;32m LATEST_DATE -> ${LATEST_DATE}\033[0m"
echo -e "\033[0;32m NEXT_DATE -> ${NEXT_DATE}\033[0m"

# If you want to test this locally and you are using macOS, do `brew install gnu-sed` and change `sed` for `gsed`.
find . \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s/${LATEST_DATE}/${NEXT_DATE}/g"
find . \( -type d -name .git -prune \) -o -type f ! -name 'CHANGELOG.md' -print0 | xargs -0 sed -i "s/${LATEST_DATE}/${NEXT_DATE}/g"

# Bump chart version and appVersion if next tag is different
if [ "$latest_chart_app_version" == $LATEST_TAG ] && [ "$latest_chart_app_version" != "$NEXT_TAG" ]; then
Expand Down

0 comments on commit 772d592

Please sign in to comment.