Release Charts #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Charts | |
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: "Target branch to release" | |
default: "main" | |
base-branch: | |
description: "The base branch to compare the version" | |
jobs: | |
tests: | |
uses: ./.github/workflows/lint-test.yaml | |
find-charts-to-release: | |
runs-on: ubuntu-latest | |
needs: [tests] | |
outputs: | |
modified-charts-files: ${{ steps.list-changed-charts.outputs.all_modified_files }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.inputs.branch }} | |
- name: Get list of changed charts | |
id: list-changed-charts | |
uses: tj-actions/changed-files@v42 | |
with: | |
base_sha: ${{ github.event.inputs.base-branch }} | |
files: charts/*/Chart.yaml | |
generate-charts-changelog: | |
needs: find-charts-to-release | |
if: needs.find-charts-to-release.outputs.modified-charts-files | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.inputs.branch }} | |
- uses: Bpazy/setup-git-chglog@v1 | |
with: | |
git-chglog-version: "0.15.4" | |
- name: Generate charts changelog files | |
shell: bash | |
run: | | |
set -x | |
sudo add-apt-repository ppa:rmescandon/yq | |
sudo apt update && sudo apt install yq -y | |
for chart_file in ${{ needs.find-charts-to-release.outputs.modified-charts-files }}; do | |
chart_name=$(grep -Po "(?<=^name: ).+" ${chart_file}) | |
chart_version=$(grep -Po "(?<=^version: ).+" ${chart_file}) | |
chart_tag="${chart_name}@${chart_version}" | |
chart_path="charts/${chart_name}" | |
# | |
# Generate chart CHANGELOG.md file. | |
git-chglog \ | |
--output "${chart_path}/CHANGELOG.md" \ | |
--tag-filter-pattern "${chart_name}" \ | |
--next-tag "${chart_tag}" \ | |
--path "${chart_path}" | |
# | |
# Generate RELEASE-NOTES.md file (used for Github release notes and ArtifactHub "changes" annotation). | |
git-chglog \ | |
--output "${chart_path}/RELEASE-NOTES.md" \ | |
--tag-filter-pattern "${chart_name}" \ | |
--next-tag "${chart_tag}" \ | |
--path "${chart_path}" "${chart_tag}" | |
# | |
# Update ArtifactHub "changes" annotation in the Chart.yaml file. | |
# https://artifacthub.io/docs/topics/annotations/helm/#supported-annotations | |
change_types="Added Changed Deprecated Removed Fixed Security" | |
# TODO: Rethink about this approach of using bash to generate YAML changes for ArtifactHub, | |
# and find out if there is a better/cleaner way to make it. | |
echo '|' > "${chart_path}/changes-for-artifacthub.yaml" | |
for change_type in ${change_types}; do | |
change_type_section=$(sed -rn "/^\#+\s${change_type}/,/^(#|$)/p" "${chart_path}/RELEASE-NOTES.md") | |
if [[ -n "${change_type_section}" ]]; then | |
echo "${change_type_section}" | egrep '^-' | sed 's/^- //g' | while read commit_message; do | |
echo " - kind: ${change_type,,}" | |
echo " description: \"${commit_message}\"" | |
done >> "${chart_path}/changes-for-artifacthub.yaml" | |
fi | |
done | |
cat "${chart_path}/changes-for-artifacthub.yaml" | |
# Merge changes back to the Chart.yaml file. | |
yq eval-all \ | |
'select(fileIndex==0).annotations."artifacthub.io/changes" = select(fileIndex==1) | select(fileIndex==0)' \ | |
${chart_path}/Chart.yaml ${chart_path}/changes-for-artifacthub.yaml > \ | |
${chart_path}/Chart-with-artifacthub-changes.yaml | |
mv ${chart_path}/Chart-with-artifacthub-changes.yaml ${chart_path}/Chart.yaml | |
done | |
- name: Stash generated charts changelog files | |
uses: actions/upload-artifact@v4 | |
with: | |
name: charts-generated-changelog | |
path: | | |
charts/*/RELEASE-NOTES.md | |
charts/*/CHANGELOG.md | |
charts/*/Chart.yaml | |
release-charts: | |
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions | |
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token | |
permissions: | |
contents: write | |
needs: generate-charts-changelog | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.inputs.branch }} | |
- name: Unstash generated charts changelog files | |
uses: actions/download-artifact@v4 | |
with: | |
name: charts-generated-changelog | |
path: charts | |
- name: Configure Git | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
- name: Install Helm | |
uses: azure/setup-helm@v4.0.0 | |
# - name: Add dependencies | |
# run: | | |
# helm repo add dex https://charts.dexidp.io | |
# helm repo add prometheus https://prometheus-community.github.io/helm-charts | |
# helm repo add jaeger https://jaegertracing.github.io/helm-charts | |
- name: Run chart-releaser | |
uses: helm/chart-releaser-action@v1.6.0 | |
env: | |
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
commit-charts-changelog: | |
needs: | |
- find-charts-to-release | |
- release-charts | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.inputs.branch }} | |
- name: Unstash generated charts changelog files | |
uses: actions/download-artifact@v4 | |
with: | |
name: charts-generated-changelog | |
path: charts | |
- name: Commit charts CHANGELOG.md file | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
released_charts_files="${{ needs.find-charts-to-release.outputs.modified-charts-files }}" | |
echo "released_charts_files: ${released_charts_files}" | |
# Commit changes locally. | |
chart_names="" | |
for chart_file in ${released_charts_files}; do | |
chart_name=$(grep -Po "(?<=^name: ).+" ${chart_file}) | |
chart_version=$(grep -Po "(?<=^version: ).+" ${chart_file}) | |
chart_path="charts/${chart_name}" | |
git add ${chart_path}/CHANGELOG.md | |
chart_names="${chart_names} ${chart_name}:${chart_version}" | |
done | |
git commit -m "Update CHANGELOG for charts ${chart_names}" | |
# Push changes to the main branch. | |
git push origin "${GITHUB_REF##*/}":main |