Skip to content

Commit

Permalink
build(chart): change log and release notes for helm chart
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Feb 20, 2024
1 parent 99222fc commit 9247659
Showing 5 changed files with 35 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@ jobs:
run: echo ${LATEST_TAG}
- name: Update tag in docs and files
run: ./update_tag_in_docs_and_files.sh ${LATEST_TAG} ${NEXT_TAG}
- name: Update chart CHANGELOG
run: ./generate_chart_changelog.sh HEAD
- name: Build images
run: VERSION="${GRID_VERSION}" BUILD_DATE=${BUILD_DATE} make build
- name: Login Docker Hub
4 changes: 4 additions & 0 deletions .github/workflows/helm-chart-release.yml
Original file line number Diff line number Diff line change
@@ -25,10 +25,14 @@ jobs:
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Get chart release notes (chart_release_notes.md)
run: ./generate_chart_changelog.sh HEAD

- name: Run chart-releaser
uses: helm/chart-releaser-action@main
with:
mark_as_latest: false
skip_existing: true
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_RELEASE_NOTES_FILE: RELEASE_NOTES.md
34 changes: 0 additions & 34 deletions .github/workflows/update-chart-changelog.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -151,3 +151,4 @@ ENV/
/charts/*/charts
/charts/*/**.lock
/charts/*.tgz
/charts/*/RELEASE_NOTES.md
37 changes: 28 additions & 9 deletions generate_chart_changelog.sh
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
CHART_DIR="./charts/selenium-grid"
CHANGELOG_FILE="./charts/selenium-grid/CHANGELOG.md"
TAG_PATTERN="selenium-grid"
SET_TAG=${1:-""}

# 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:]')
@@ -27,24 +28,27 @@ generate_changelog() {
commit_range="${previous_tag}..${current_tag}"
fi

change_title=$current_tag
if [ "$SET_TAG" = "HEAD" ]; then
current_tag="${SET_TAG}"
CURRENT_CHART_VERSION=$(find . \( -type d -name .git -prune \) -o -type f -name 'Chart.yaml' -print0 | xargs -0 cat | grep ^version | cut -d ':' -f 2 | tr -d '[:space:]')
change_title="${TAG_PATTERN}-${CURRENT_CHART_VERSION}"
fi
echo "Generating changelog for ${change_title}"

# 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/^/- /')
k8s_versions_tested=$(echo "Chart is tested on Kubernetes versions: $(cat .github/workflows/helm-chart-test.yml | grep -oP "k8s-version: '\Kv.*(?=')" | tr '\n' ',')")
k8s_versions_tested=$(echo "Chart is tested on Kubernetes versions: $(cat .github/workflows/helm-chart-test.yml | grep -oP "k8s-version: '\Kv.*(?=')" | tr '\n' ' ')" | 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 "## :heavy_check_mark: ${change_title}" >> "$temp_file"
echo "" >> "$temp_file"
echo "$image_tag_changes" >> "$temp_file"
echo "$k8s_versions_tested" >> "$temp_file"
@@ -74,11 +78,26 @@ generate_changelog() {
echo "" >> "$temp_file"
fi

# Create chart_release_notes.md
release_notes_file="$CHART_DIR/RELEASE_NOTES.md"
chart_description=$(find . \( -type d -name .git -prune \) -o -type f -name 'Chart.yaml' -print0 | xargs -0 cat | grep ^description | cut -d ':' -f 2)
echo "$chart_description" > "$release_notes_file"
echo "" >> "$release_notes_file"
cat $temp_file >> "$release_notes_file"
echo "Generated release notes at $release_notes_file"

# 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"
if [[ $(cat $CHANGELOG_FILE) == *"${change_title}"* ]]; then
echo "Changelog already generated for ${change_title}"
rm -rf "$temp_file"
exit 0
else
# Overwrite CHANGELOG with the content of the temporary file
mv "$temp_file" "$CHANGELOG_FILE"
fi

}

# Run the function to generate the changelog

0 comments on commit 9247659

Please sign in to comment.