From 85099d80550048081bcd4ca635e4c1ae92556549 Mon Sep 17 00:00:00 2001 From: David Gogl <1381862+kengou@users.noreply.github.com> Date: Tue, 23 Apr 2024 17:58:07 +0200 Subject: [PATCH 1/4] init gh-actions for helm chart test and push to github oci registry --- .github/ct.yaml | 13 +++++ .github/workflows/helm-lint.yaml | 66 +++++++++++++++++++++++ .github/workflows/helm-push.yaml | 90 ++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 .github/ct.yaml create mode 100644 .github/workflows/helm-lint.yaml create mode 100644 .github/workflows/helm-push.yaml diff --git a/.github/ct.yaml b/.github/ct.yaml new file mode 100644 index 0000000000..6d2a381ea2 --- /dev/null +++ b/.github/ct.yaml @@ -0,0 +1,13 @@ +# See https://github.com/helm/chart-testing#configuration +remote: origin +target-branch: master +validate-maintainers: false +check-version-increment: false +chart-dirs: + - common + - global + - openstack + - prometheus-exporters + - prometheus-rules + - px + - system diff --git a/.github/workflows/helm-lint.yaml b/.github/workflows/helm-lint.yaml new file mode 100644 index 0000000000..0baef01464 --- /dev/null +++ b/.github/workflows/helm-lint.yaml @@ -0,0 +1,66 @@ +name: "Helm lint" +on: + pull_request: + types: [ opened, synchronize, reopened ] + +env: + REGISTRY: ghcr.io + +jobs: + helm-lint: + runs-on: [ default ] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + + - uses: actions/setup-python@v5 + with: + python-version: 3.9 + check-latest: true + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.6.1 + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}) + if [[ -n "$changed" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + fi + + - name: Run chart-testing (lint) + if: steps.list-changed.outputs.changed == 'true' + run: ct lint --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }} + + - name: Check version bump + id: check-bump + if: steps.list-changed.outputs.changed == 'true' + continue-on-error: true + run: | + for chart in $(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}); do + chart_version=$(yq .version "$chart/Chart.yaml") + if helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/$(basename $chart)" --version $chart_version; then + echo "chart=$(basename $chart)" >> "$GITHUB_OUTPUT" + echo "chart_version=${chart_version}" >> "$GITHUB_OUTPUT" + echo "needsbump=true" >> "$GITHUB_OUTPUT" + exit 1 + fi + done + + - uses: actions/github-script@v6 + if: steps.check-bump.outputs.needsbump == 'true' + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: ':warning: Chart `oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/${{ steps.check-bump.outputs.chart }}:${{ steps.check-bump.outputs.chart_version }}` already exists in registry. Please increment the chart version.' + }) diff --git a/.github/workflows/helm-push.yaml b/.github/workflows/helm-push.yaml new file mode 100644 index 0000000000..4b9ee51b85 --- /dev/null +++ b/.github/workflows/helm-push.yaml @@ -0,0 +1,90 @@ +name: Package Helm Chart and publish to GitHub Packages + +on: + push: + branches: + - master + +permissions: + contents: write + packages: write + +env: + REGISTRY: ghcr.io + ACTIONS_RUNNER_DEBUG: false + +jobs: + helm-release: + runs-on: [ default ] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + + - uses: actions/setup-python@v5 + with: + python-version: 3.9 + check-latest: true + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}) + if [[ -n "$changed" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + fi + + - name: Run chart-testing (lint) + if: steps.list-changed.outputs.changed == 'true' + run: ct lint --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }} + + - name: Check if Helm chart with same version already exists + id: check-chart + if: steps.list-changed.outputs.changed == 'true' + run: | + for chart in $(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}); do + chart_version=$(yq .version "$chart/Chart.yaml") + if helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/$(basename $chart)" --version $chart_version; then + echo "chart=$(basename $chart)" >> "$GITHUB_OUTPUT" + echo "chart_version=${chart_version}" >> "$GITHUB_OUTPUT" + echo "needsbump=true" >> "$GITHUB_OUTPUT" + exit 1 + fi + done + + - name: Chart needs version bump + if: steps.check-chart.outputs.bump == 'true' + env: + CHART_VERSION: ${{ steps.check-chart.outputs.chart_version }} + run: | + echo "Chart ${{ matrix.chartDir }}:${{ env.CHART_VERSION }} already exists in OCI registry. Skipping upload. Please increment the chart version." + exit 1 + + - name: Push Charts to GHCR + if: steps.list-changed.outputs.changed == 'true' && steps.check-chart.outputs.bump != 'true' + run: | + for chart in $(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}); do + helm dependency update $chart + helm package $chart -d $chart + PKG_NAME=`ls $chart/*.tgz` + helm push ${PKG_NAME} oci://${{ env.REGISTRY }}/${{ github.repository }}/ + done From 855e6e34e0e1bd00a8b6bb531387f817328bbd98 Mon Sep 17 00:00:00 2001 From: David Gogl <1381862+kengou@users.noreply.github.com> Date: Tue, 23 Apr 2024 18:02:13 +0200 Subject: [PATCH 2/4] update gh-actions runner --- .github/workflows/helm-lint.yaml | 2 +- .github/workflows/helm-push.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/helm-lint.yaml b/.github/workflows/helm-lint.yaml index 0baef01464..8f5d8f8e90 100644 --- a/.github/workflows/helm-lint.yaml +++ b/.github/workflows/helm-lint.yaml @@ -8,7 +8,7 @@ env: jobs: helm-lint: - runs-on: [ default ] + runs-on: [ ubuntu-latest ] steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/helm-push.yaml b/.github/workflows/helm-push.yaml index 4b9ee51b85..8fab751440 100644 --- a/.github/workflows/helm-push.yaml +++ b/.github/workflows/helm-push.yaml @@ -15,7 +15,7 @@ env: jobs: helm-release: - runs-on: [ default ] + runs-on: [ ubuntu-latest ] steps: - uses: actions/checkout@v4 From c88ead3bf86c5251452a873dccbe2398e8a7b455 Mon Sep 17 00:00:00 2001 From: Arno Uhlig Date: Tue, 23 Apr 2024 18:24:58 +0200 Subject: [PATCH 3/4] marry with ci config --- .github/ct.yaml | 13 ------------- .github/workflows/helm-lint.yaml | 6 +++--- .github/workflows/helm-push.yaml | 8 ++++---- 3 files changed, 7 insertions(+), 20 deletions(-) delete mode 100644 .github/ct.yaml diff --git a/.github/ct.yaml b/.github/ct.yaml deleted file mode 100644 index 6d2a381ea2..0000000000 --- a/.github/ct.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# See https://github.com/helm/chart-testing#configuration -remote: origin -target-branch: master -validate-maintainers: false -check-version-increment: false -chart-dirs: - - common - - global - - openstack - - prometheus-exporters - - prometheus-rules - - px - - system diff --git a/.github/workflows/helm-lint.yaml b/.github/workflows/helm-lint.yaml index 8f5d8f8e90..5d6269ad43 100644 --- a/.github/workflows/helm-lint.yaml +++ b/.github/workflows/helm-lint.yaml @@ -30,21 +30,21 @@ jobs: - name: Run chart-testing (list-changed) id: list-changed run: | - changed=$(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}) + changed=$(ct list-changed --config ci/config.yaml --target-branch ${{ github.event.repository.default_branch }}) if [[ -n "$changed" ]]; then echo "changed=true" >> "$GITHUB_OUTPUT" fi - name: Run chart-testing (lint) if: steps.list-changed.outputs.changed == 'true' - run: ct lint --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }} + run: ct lint --chart-yaml-schema ci/chart_schema.yaml --lint-conf ci/lintconf.yaml --config ci/config.yaml --target-branch ${{ github.event.repository.default_branch }} - name: Check version bump id: check-bump if: steps.list-changed.outputs.changed == 'true' continue-on-error: true run: | - for chart in $(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}); do + for chart in $(ct list-changed --config ct/config.yaml --target-branch ${{ github.event.repository.default_branch }}); do chart_version=$(yq .version "$chart/Chart.yaml") if helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/$(basename $chart)" --version $chart_version; then echo "chart=$(basename $chart)" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/helm-push.yaml b/.github/workflows/helm-push.yaml index 8fab751440..4f39ec4387 100644 --- a/.github/workflows/helm-push.yaml +++ b/.github/workflows/helm-push.yaml @@ -48,20 +48,20 @@ jobs: - name: Run chart-testing (list-changed) id: list-changed run: | - changed=$(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}) + changed=$(ct list-changed --config ct/config.yaml --target-branch ${{ github.event.repository.default_branch }}) if [[ -n "$changed" ]]; then echo "changed=true" >> "$GITHUB_OUTPUT" fi - name: Run chart-testing (lint) if: steps.list-changed.outputs.changed == 'true' - run: ct lint --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }} + run: ct lint --chart-yaml-schema ci/chart_schema.yaml --lint-conf ci/lintconf.yaml --config ci/config.yaml --target-branch ${{ github.event.repository.default_branch }} - name: Check if Helm chart with same version already exists id: check-chart if: steps.list-changed.outputs.changed == 'true' run: | - for chart in $(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}); do + for chart in $(ct list-changed --config ct/config.yaml --target-branch ${{ github.event.repository.default_branch }}); do chart_version=$(yq .version "$chart/Chart.yaml") if helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/$(basename $chart)" --version $chart_version; then echo "chart=$(basename $chart)" >> "$GITHUB_OUTPUT" @@ -82,7 +82,7 @@ jobs: - name: Push Charts to GHCR if: steps.list-changed.outputs.changed == 'true' && steps.check-chart.outputs.bump != 'true' run: | - for chart in $(ct list-changed --config .github/ct.yaml --target-branch ${{ github.event.repository.default_branch }}); do + for chart in $(ct list-changed --config ct/config.yaml --target-branch ${{ github.event.repository.default_branch }}); do helm dependency update $chart helm package $chart -d $chart PKG_NAME=`ls $chart/*.tgz` From 863ca6a6f2b93f65c8b3a95bcfd02882185ec646 Mon Sep 17 00:00:00 2001 From: Arno Uhlig Date: Tue, 23 Apr 2024 18:29:13 +0200 Subject: [PATCH 4/4] ignore .github for chart testing --- ci/config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/config.yaml b/ci/config.yaml index 947c06cc64..34623f7d7a 100644 --- a/ci/config.yaml +++ b/ci/config.yaml @@ -15,6 +15,7 @@ chart-dirs: # Don't look here. excluded-charts: - ci + - .github # Adds remote chart repositories to be used for the tests. chart-repos: