|
| 1 | +## Reference: https://github.com/helm/chart-testing-action |
| 2 | +## Reference: https://github.com/quintush/helm-unittest |
| 3 | +name: Lint and Test Charts |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - master |
| 9 | + types: |
| 10 | + - opened |
| 11 | + - edited |
| 12 | + - reopened |
| 13 | + - ready_for_review |
| 14 | + - synchronize |
| 15 | + paths: |
| 16 | + - "charts/**" |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.head_ref }}-lint-test |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | +env: |
| 26 | + HELM_VERSION: 3.9.2 # Also update in release.yaml |
| 27 | + |
| 28 | +jobs: |
| 29 | + lint-charts: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + outputs: |
| 32 | + matrix: ${{ steps.list-changed.outputs.matrix }} |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v3 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + |
| 39 | + - name: Set up Helm |
| 40 | + uses: azure/setup-helm@v3 |
| 41 | + with: |
| 42 | + version: ${{ env.HELM_VERSION }} |
| 43 | + |
| 44 | + - name: Set up Python |
| 45 | + uses: actions/setup-python@v4 |
| 46 | + with: |
| 47 | + python-version: 3.9 |
| 48 | + |
| 49 | + - name: 'Set up jq' |
| 50 | + |
| 51 | + |
| 52 | + - name: Set up chart-testing |
| 53 | + |
| 54 | + |
| 55 | + - name: Run chart-testing (list-changed) |
| 56 | + id: list-changed |
| 57 | + run: | |
| 58 | + set -o xtrace |
| 59 | + changed=$(ct list-changed --config ct.yaml) |
| 60 | + charts=$(echo "$changed" | tr '\n' ' ' | xargs) |
| 61 | + if [[ -n "$changed" ]]; then |
| 62 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 63 | + echo "changed_charts=$charts" >> $GITHUB_OUTPUT |
| 64 | + echo "matrix=$(echo $charts | jq -R 'split(" ")' | jq '. | if index("charts/cf-common-test") then . else . += ["charts/cf-common-test"] end' | jq -c .)" >> $GITHUB_OUTPUT |
| 65 | + echo $matrix |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Run chart-testing (lint) |
| 69 | + run: ct lint --config "ct.yaml" --lint-conf "lintconf.yaml" --debug --excluded-charts "cf-common-test" |
| 70 | + |
| 71 | + - name: Run docs-testing (helm-docs) |
| 72 | + id: helm-docs |
| 73 | + run: | |
| 74 | + ./scripts/helm-docs.sh |
| 75 | + if [[ $(git diff --stat) != '' ]]; then |
| 76 | + echo -e '\033[0;31mDocumentation outdated!\033[0m ❌ Run ./scripts/helm-docs.sh before commit!' |
| 77 | + git diff --color |
| 78 | + exit 1 |
| 79 | + else |
| 80 | + echo -e '\033[0;32mDocumentation up to date\033[0m ✔' |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Create kind cluster |
| 84 | + |
| 85 | + |
| 86 | + - name: Run chart-testing (install) |
| 87 | + run: | |
| 88 | + changed=$(ct list-changed --config "ct.yaml") |
| 89 | + if [[ "$changed" == "charts/cf-common" ]]; then |
| 90 | + # Do not run `ct install` for cf-common (library chart) |
| 91 | + exit 0 |
| 92 | + fi |
| 93 | + ct install --config "ct.yaml" |
| 94 | +
|
| 95 | + unittest-charts: |
| 96 | + needs: |
| 97 | + - lint-charts |
| 98 | + runs-on: ubuntu-latest |
| 99 | + # There are no Unit Test suites in `charts/cf-common`. They are located in `charts/cf-common-test`. So `charts/cf-common` is excluded from this job. |
| 100 | + if: ${{ needs.lint-charts.outputs.matrix != '[]' && needs.lint-charts.outputs.matrix != '["charts/cf-common"]' }} |
| 101 | + strategy: |
| 102 | + matrix: |
| 103 | + chart: ${{ fromJSON(needs.lint-charts.outputs.matrix) }} |
| 104 | + exclude: |
| 105 | + - chart: charts/cf-common |
| 106 | + fail-fast: true |
| 107 | + steps: |
| 108 | + - name: Checkout |
| 109 | + uses: actions/checkout@v3 |
| 110 | + with: |
| 111 | + fetch-depth: 0 |
| 112 | + |
| 113 | + - name: Set up Helm |
| 114 | + uses: azure/setup-helm@v3 |
| 115 | + with: |
| 116 | + version: ${{ env.HELM_VERSION }} |
| 117 | + |
| 118 | + - name: Run unit tests |
| 119 | + run: | |
| 120 | + echo ${{ matrix.chart }} |
| 121 | + helm plugin install https://github.com/quintush/helm-unittest --version v0.2.11 |
| 122 | + helm dep update ${{ matrix.chart }} |
| 123 | + helm unittest --helm3 --color --debug -f "tests/**/*_test.yaml" ${{ matrix.chart }} |
| 124 | +
|
| 125 | + push-charts-dev-cm: |
| 126 | + needs: |
| 127 | + - lint-charts |
| 128 | + - unittest-charts |
| 129 | + runs-on: ubuntu-latest |
| 130 | + strategy: |
| 131 | + matrix: |
| 132 | + chart: ${{ fromJSON(needs.lint-charts.outputs.matrix) }} |
| 133 | + fail-fast: true |
| 134 | + steps: |
| 135 | + - name: Checkout |
| 136 | + uses: actions/checkout@v3 |
| 137 | + with: |
| 138 | + fetch-depth: 0 |
| 139 | + |
| 140 | + - name: Set up Helm |
| 141 | + uses: azure/setup-helm@v3 |
| 142 | + with: |
| 143 | + version: v3.8.2 |
| 144 | + |
| 145 | + - name: Set up yq |
| 146 | + uses: chrisdickinson/setup-yq@latest |
| 147 | + |
| 148 | + - name: Set short SHA |
| 149 | + run: echo "GITHUB_SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV |
| 150 | + |
| 151 | + - name: Push Helm Chart to Dev ChartMuseum |
| 152 | + run: | |
| 153 | + set -o xtrace |
| 154 | + CHART_NAME=$(yq read ${{ matrix.chart }}/Chart.yaml name) |
| 155 | + CHART_VERSION=$(yq read ${{ matrix.chart }}/Chart.yaml version)-$GITHUB_SHORT_SHA |
| 156 | +
|
| 157 | + helm plugin install https://github.com/chartmuseum/helm-push.git |
| 158 | + helm repo add chartmuseum ${{ secrets.CHARTMUSEUM_DEV_URL }}/$CHART_NAME --username ${{ secrets.CHARTMUSEUM_DEV_USERNAME }} --password ${{ secrets.CHARTMUSEUM_DEV_PASSWORD }} |
| 159 | + helm dependency update ${{ matrix.chart }} |
| 160 | +
|
| 161 | + helm cm-push ${{ matrix.chart }} chartmuseum --version $CHART_VERSION |
0 commit comments