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@v4 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: Install main dependencies run: | apk add bash nodejs # https://github.com/git-chglog/git-chglog/issues/23#issuecomment-1716941412 - name: Workaround for git-chglog and git-tag shell: bash run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Generate charts changelog files shell: bash run: | set -x apk add git grep yq 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}" 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: needs: generate-charts-changelog runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - 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 with: version: "${{ env.HELM_VERSION }}" - name: Run Chart Releaser id: release_step if: ( !env.ACT && ( success() || failure() ) ) uses: helm/chart-releaser-action@v1.6.0 env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" with: config: .github/config/chart-releaser.yaml skip_existing: true commit-charts-changelog: runs-on: ubuntu-latest needs: - find-charts-to-release - release-charts steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Unstash generated charts changelog files uses: actions/download-artifact@v4 with: name: charts-generated-changelog path: charts - name: Commit charts CHANGELOG.md file if: ( !env.ACT && ( success() || failure() ) ) 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