name: Chart Releases on: workflow_dispatch: push: branches: - main paths: - 'charts/**' # tags: # - "v*.*.*" env: HELM_VERSION: 3.14.3 jobs: find-charts-to-release: runs-on: ubuntu-latest outputs: modified-charts-files: ${{ steps.list-changed-charts.outputs.all_modified_files }} steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - name: Get list of changed charts id: list-changed-charts uses: tj-actions/changed-files@v44 with: 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 container: quay.io/git-chglog/git-chglog:0.15.4 steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - name: Install main dependencies run: | apk add bash nodejs - name: Generate charts changelog files shell: bash run: | set -x apk add git grep yq # TODO: Bundle all of that logic in a Github Action to make it easy to share. 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: needs: generate-charts-changelog runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - name: Unstash generated charts 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 "$GITHUB_ACTOR@users.noreply.github.com" - name: Install Helm uses: azure/setup-helm@v3 with: version: "${{ env.HELM_VERSION }}" - name: Run Chart Releaser id: release_step uses: helm/chart-releaser-action@v1.6.0 env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" with: config: .github/config/chart-releaser.yaml commit-charts-changelog: runs-on: ubuntu-latest needs: - find-charts-to-release - release-charts steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - 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 "$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. 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 git commit -m "Update CHANGELOG for chart ${chart_name} ${chart_version}" done # Push changes to the main branch. git push origin "${GITHUB_REF##*/}":main