|
| 1 | +name: Helm |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - master |
| 9 | +env: |
| 10 | + HELM_VERSION: 3.12.1 |
| 11 | + PYTHON_VERSION: 3.9 |
| 12 | + TARGET_BRANCH: chart-testing-target-branch |
| 13 | + TARGET_REMOTE: test |
| 14 | +jobs: |
| 15 | + helm-jobs: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + - name: Set up Helm |
| 23 | + uses: azure/setup-helm@v4 |
| 24 | + with: |
| 25 | + version: "v${{ env.HELM_VERSION }}" |
| 26 | + - uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: ${{ env.PYTHON_VERSION }} |
| 29 | + check-latest: true |
| 30 | + # --------------------------------------------------------------- |
| 31 | + # -- Instead of comparing to the master branch, I'm getting |
| 32 | + # -- the commit hash set in the previous step from a |
| 33 | + # -- currently released chart. If it doesn't exists, then |
| 34 | + # -- I assume that chart is not released and compare to the |
| 35 | + # -- previous commit |
| 36 | + # -- |
| 37 | + # -- Also, I'm setting the RepoURL here. Since we plan to support |
| 38 | + # -- the official chart in this git repository, the helm |
| 39 | + # -- repository is expected to belong to this repo as well. |
| 40 | + # --------------------------------------------------------------- |
| 41 | + - name: Retrieve the latest commit sha from the helm chart |
| 42 | + run: | |
| 43 | + HELM_REPO_URL="https://${GITHUB_REPOSITORY_OWNER}.github.io/${GITHUB_REPOSITORY#*/}" |
| 44 | + if helm repo add sql-exporter $HELM_REPO_URL |
| 45 | + then |
| 46 | + helm repo update |
| 47 | + echo "TARGET_COMMIT=$(helm show chart sql-exporter/sql-exporter | yq '.annotations.git/commit-sha')" >> "${GITHUB_ENV}" |
| 48 | + else |
| 49 | + echo "TARGET_COMMIT=$(git show HEAD^1 --pretty=format:%H --no-patch)" >> "${GITHUB_ENV}" |
| 50 | + fi |
| 51 | + # --------------------------------------------------------------- |
| 52 | + # -- As I could find CT doesn't support testing against commits |
| 53 | + # -- directly, so I'm creating a new fake remote from a commit |
| 54 | + # -- and testing the chart against it. This workaround doesn't |
| 55 | + # -- support maintainers validation, but we have it disabled |
| 56 | + # -- anyway |
| 57 | + # --------------------------------------------------------------- |
| 58 | + - name: Prepare a dummy remote to test the chart |
| 59 | + run: | |
| 60 | + DUMMY_REMOTE=$(mktemp -d) |
| 61 | + git init "${DUMMY_REMOTE}" |
| 62 | + git remote add "${TARGET_REMOTE}" "${DUMMY_REMOTE}" |
| 63 | + git checkout -b "${TARGET_BRANCH}" "${TARGET_COMMIT}" |
| 64 | + git push --set-upstream "${TARGET_REMOTE}" "${TARGET_BRANCH}" |
| 65 | + git checkout "${GITHUB_SHA}" |
| 66 | + - name: Set up chart-testing |
| 67 | + uses: helm/chart-testing-action@v2.6.0 |
| 68 | + - name: Run chart-testing (list-changed) |
| 69 | + id: list-changed |
| 70 | + run: | |
| 71 | + changed=$(ct list-changed --chart-dirs . --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}") |
| 72 | + if [[ -n "$changed" ]]; then |
| 73 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 74 | + fi |
| 75 | + - name: Run chart-testing (lint) |
| 76 | + if: steps.list-changed.outputs.changed == 'true' |
| 77 | + run: ct lint --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --validate-maintainers=false --chart-dirs . |
| 78 | + - name: Setup helmfile |
| 79 | + if: steps.list-changed.outputs.changed == 'true' |
| 80 | + uses: mamezou-tech/setup-helmfile@v2.0.0 |
| 81 | + - name: Create kind cluster |
| 82 | + if: steps.list-changed.outputs.changed == 'true' |
| 83 | + uses: helm/kind-action@v1.9.0 |
| 84 | + - name: Init postgres server |
| 85 | + if: steps.list-changed.outputs.changed == 'true' |
| 86 | + run: | |
| 87 | + helmfile -f helm/ci/helmfile.yaml sync |
| 88 | + - name: Run chart-testing (install) |
| 89 | + if: steps.list-changed.outputs.changed == 'true' |
| 90 | + run: ct install --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --chart-dirs . |
| 91 | + - name: Run chart-testing (upgrade) |
| 92 | + if: steps.list-changed.outputs.changed == 'true' |
| 93 | + run: ct install --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --chart-dirs . --upgrade |
| 94 | + - name: Configure Git |
| 95 | + run: | |
| 96 | + git config user.name "$GITHUB_ACTOR" |
| 97 | + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" |
| 98 | + # --------------------------------------------------------------- |
| 99 | + # -- On each run we're setting an annotation with the current |
| 100 | + # -- commit hash, so in case it's released, we will see it |
| 101 | + # -- running `$ helm show sql-exporter/sql-exporter` |
| 102 | + # --------------------------------------------------------------- |
| 103 | + - name: Set the git sha annotations in the helm chart |
| 104 | + run: yq -i ".annotations.git/commit-sha = \"${GITHUB_SHA}\"" ./helm/Chart.yaml |
| 105 | + |
| 106 | + - name: Release charts |
| 107 | + if: ${{ github.event.repository.default_branch && github.event_name == 'push' }} |
| 108 | + uses: helm/chart-releaser-action@main |
| 109 | + with: |
| 110 | + charts_dir: . |
| 111 | + mark_as_latest: false |
| 112 | + packages_with_index: true |
| 113 | + env: |
| 114 | + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 115 | + CR_RELEASE_NAME_TEMPLATE: "chart-{{ .Name }}-{{ .Version }}" |
0 commit comments