@@ -12,17 +12,23 @@ permissions:
1212 id-token : write
1313 packages : write
1414
15+ env :
16+ _CHART_NAME : ${{ inputs.chart_name }}
17+
1518jobs :
1619 build :
1720 name : Build Helm charts
1821 runs-on : ubuntu-22.04
19- environment : Production
2022 permissions :
2123 contents : read
2224 id-token : write
2325 steps :
2426 - name : Checkout repo
2527 uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
28+ with :
29+ persist-credentials : false
30+ fetch-depth : 0
31+ fetch-tags : true
2632
2733 - name : Set up Helm
2834 uses : Azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5
@@ -59,6 +65,110 @@ jobs:
5965 - name : Log out from Azure
6066 uses : bitwarden/gh-actions/azure-logout@main
6167
68+ - name : Generate release notes
69+ id : release_notes
70+ env :
71+ GH_TOKEN : ${{ github.token }}
72+ run : |
73+ # Get the last release tag
74+ last_tag=$(gh release list --exclude-pre-releases --exclude-drafts --json "tagName" --limit 100 | jq -r --arg prefix "$_CHART_NAME" '.[] | select(.tagName | startswith($prefix)) | .tagName' | head -1)
75+
76+ if [ -z "$last_tag" ]; then
77+ echo "No previous release tag found, generating notes from initial commit"
78+ commit_range="$(git rev-list --max-parents=0 HEAD)..HEAD"
79+ else
80+ echo "Generating release notes since tag: $last_tag"
81+ commit_range="${last_tag}..HEAD"
82+ fi
83+
84+ changelog_file="charts/${_CHART_NAME}/CHANGELOG.md"
85+ chart_description=$(helm show chart "charts/${_CHART_NAME}" | yq -e '.description')
86+ chart_version=$(helm show chart "charts/${_CHART_NAME}" | yq -e '.version')
87+
88+ # Initialize arrays for tracking
89+ declare -A prs_found
90+ declare -A contributors
91+ declare -A new_contributors
92+ whats_changed=""
93+
94+ # Get all commits for this chart
95+ while IFS= read -r commit_hash; do
96+ commit_msg=$(git log -1 --pretty=format:"%s" "$commit_hash")
97+ commit_author=$(git log -1 --pretty=format:"%an" "$commit_hash")
98+ commit_email=$(git log -1 --pretty=format:"%ae" "$commit_hash")
99+
100+ # Try to extract PR number from commit message (e.g., "message (#123)" or "Merge pull request #123")
101+ pr_num=""
102+ if [[ $commit_msg =~ \(#([0-9]+)\) ]]; then
103+ pr_num="${BASH_REMATCH[1]}"
104+ elif [[ $commit_msg =~ Merge\ pull\ request\ #([0-9]+) ]]; then
105+ pr_num="${BASH_REMATCH[1]}"
106+ elif [[ $commit_msg =~ \#([0-9]+) ]]; then
107+ pr_num="${BASH_REMATCH[1]}"
108+ fi
109+
110+ # If we found a PR number and haven't processed it yet
111+ if [[ -n "$pr_num" ]] && [[ -z "${prs_found[$pr_num]}" ]]; then
112+ prs_found[$pr_num]=1
113+
114+ # Try to get PR details from GitHub API
115+ if pr_data=$(gh pr view "$pr_num" --json title,author,number,url 2>/dev/null); then
116+ pr_title=$(echo "$pr_data" | jq -r '.title')
117+ pr_author=$(echo "$pr_data" | jq -r '.author.login')
118+ pr_url=$(echo "$pr_data" | jq -r '.url')
119+
120+ # Add to what's changed
121+ whats_changed+="- ${pr_title} by [@${pr_author}](https://github.com/${pr_author}) in [#${pr_num}](${pr_url})"$'\n'
122+
123+ # Track contributor
124+ contributors[$pr_author]=1
125+
126+ # Check if this is a new contributor (first PR)
127+ pr_count=$(gh pr list --author "$pr_author" --state merged --limit 100 --json number | jq '. | length')
128+ if [[ "$pr_count" -eq 1 ]]; then
129+ new_contributors[$pr_author]="[#${pr_num}](${pr_url})"
130+ fi
131+ else
132+ # Fallback if API call fails - use commit info
133+ whats_changed+="- ${commit_msg} (${commit_hash:0:7})"$'\n'
134+ fi
135+ elif [[ -z "$pr_num" ]]; then
136+ # No PR found, add commit directly
137+ whats_changed+="- ${commit_msg} (${commit_hash:0:7})"$'\n'
138+ fi
139+ done < <(git log "$commit_range" --pretty=format:"%H" --reverse -- "charts/${_CHART_NAME}")
140+
141+ # Build the changelog content
142+ {
143+ echo "$chart_description"
144+ echo ""
145+ echo "## What's Changed"
146+ if [[ -n "$whats_changed" ]]; then
147+ echo "$whats_changed"
148+ else
149+ echo "No changes found for this chart."
150+ fi
151+
152+ # Add new contributors section if any
153+ if [[ ${#new_contributors[@]} -gt 0 ]]; then
154+ echo ""
155+ echo "## New Contributors"
156+ for contributor in "${!new_contributors[@]}"; do
157+ pr_link="${new_contributors[$contributor]}"
158+ echo "- [@${contributor}](https://github.com/${contributor}) made their first contribution in ${pr_link}"
159+ done
160+ fi
161+
162+ # Add full changelog link
163+ if [[ -n "$last_tag" ]]; then
164+ echo ""
165+ echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${last_tag}...${_CHART_NAME}-${chart_version}"
166+ fi
167+ } > "$changelog_file"
168+
169+ echo "Release notes generated:"
170+ cat "$changelog_file"
171+
62172 - name : Package Helm chart
63173 id : helm_package
64174 run : |
@@ -67,12 +177,14 @@ jobs:
67177 --key "DevOps Team" \
68178 --keyring private.gpg \
69179 --passphrase-file .passphrase \
70- charts/${{ inputs.chart_name }}
71- PKG_NAME=$(ls *.tgz)
180+ " charts/${_CHART_NAME}"
181+ PKG_NAME=$(ls ./ *.tgz)
72182 echo "name=$PKG_NAME" >> "$GITHUB_OUTPUT"
73183
74184 - name : Verify Helm chart
75- run : helm verify ${{ steps.helm_package.outputs.name }} --keyring public.gpg
185+ env :
186+ _HELM_OUTPUT_NAME : ${{ steps.helm_package.outputs.name }}
187+ run : helm verify "${_HELM_OUTPUT_NAME}" --keyring public.gpg
76188
77189 - name : Upload Helm chart artifact
78190 uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
0 commit comments