Skip to content

ci: test manual workflow trigger #36

ci: test manual workflow trigger

ci: test manual workflow trigger #36

Workflow file for this run

name: Release Charts
on:
push:
branches:
- ci/release-manual
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: main
- uses: nrwl/nx-set-shas@v4
id: main_branch
with:
main-branch-name: dd805e391c9f19add8d9e9cc048bd9407cb69c85
workflow-id: "lint-test.yaml"
- name: Get list of changed charts
id: list-changed-charts
uses: tj-actions/changed-files@v40
with:
base_sha: ${{ steps.main_branch.outputs.base }}
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: main
- 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@v3
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: main
- name: Unstash generated cazure/setup-helmharts changelog files
uses: actions/download-artifact@v3
with:
name: charts-generated-changelog
path: charts
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v3
- 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/[email protected]
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:
ref: main
- name: Unstash generated charts changelog files
uses: actions/download-artifact@v3
with:
name: charts-generated-changelog
path: charts
- name: Commit charts CHANGELOG.md file
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
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