diff --git a/.github/workflows/chart-test.yml b/.github/workflows/chart-test.yml new file mode 100644 index 0000000..d56e381 --- /dev/null +++ b/.github/workflows/chart-test.yml @@ -0,0 +1,171 @@ +# Reusable chart CI: lints and templates one chart, then mock deploys it to a +# kind cluster. Each chart has a small caller workflow that triggers on its +# own paths and passes the chart-specific bits below. +name: Chart test + +on: + workflow_call: + inputs: + chart: + description: Chart directory name under charts/. + type: string + required: true + chart-repos: + description: Comma-separated name=url Helm repositories the chart's dependencies come from. + type: string + default: "" + template-args: + description: >- + One `helm template` run per line, each line holding the extra arguments + for that run. ct lint already renders the chart with its default (or + ci/*-values.yaml) values. + type: string + default: "" + install-cnpg: + description: Install the CloudNativePG operator before deploying the chart. + type: boolean + default: false + release: + description: Release name of the mock deploy, also used as its namespace. + type: string + required: true + install-args: + description: Extra arguments for `helm install`. + type: string + default: "" + install-timeout: + type: string + default: 5m + rollouts: + description: Workloads (one per line, e.g. deployment/foo) that must finish rolling out. + type: string + default: "" + smoke-test: + description: Shell script run against the deployed release, with RELEASE set. + type: string + default: "" + +permissions: + contents: read + +env: + CHART: charts/${{ inputs.chart }} + RELEASE: ${{ inputs.release }} + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: azure/setup-helm@v4 + with: + version: "v3.16.4" + + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2 + + - name: Run chart-testing (lint) + env: + CHART_REPOS: ${{ inputs.chart-repos }} + run: | + ct lint --charts "$CHART" --validate-maintainers=false \ + ${CHART_REPOS:+--chart-repos "$CHART_REPOS"} + + - name: Build chart dependencies + env: + CHART_REPOS: ${{ inputs.chart-repos }} + run: | + for repo in ${CHART_REPOS//,/ }; do + helm repo add "${repo%%=*}" "${repo#*=}" + done + helm dependency build "$CHART" + + - name: helm template + env: + TEMPLATE_ARGS: ${{ inputs.template-args }} + run: | + while IFS= read -r args; do + [ -n "$args" ] || continue + echo "::group::helm template $args" + eval "helm template test \"\$CHART\" $args" + echo "::endgroup::" + done <<< "$TEMPLATE_ARGS" + + mock-deploy: + runs-on: ubuntu-latest + needs: lint + steps: + - uses: actions/checkout@v4 + + - uses: azure/setup-helm@v4 + with: + version: "v3.16.4" + + - name: Create kind cluster + uses: helm/kind-action@v1 + with: + cluster_name: chart-testing + + - name: Install CloudNativePG operator + if: inputs.install-cnpg + run: | + helm repo add cnpg https://cloudnative-pg.github.io/charts + helm upgrade --install cnpg-operator cnpg/cloudnative-pg \ + --namespace cnpg-system --create-namespace \ + --wait --timeout 3m + + - name: Build chart dependencies + env: + CHART_REPOS: ${{ inputs.chart-repos }} + run: | + for repo in ${CHART_REPOS//,/ }; do + helm repo add "${repo%%=*}" "${repo#*=}" + done + helm dependency build "$CHART" + + - name: Install chart + env: + INSTALL_ARGS: ${{ inputs.install-args }} + INSTALL_TIMEOUT: ${{ inputs.install-timeout }} + run: | + eval "helm install \"\$RELEASE\" \"\$CHART\" \ + --namespace \"\$RELEASE\" --create-namespace \ + --wait --timeout \"\$INSTALL_TIMEOUT\" $INSTALL_ARGS" + + - name: Verify workloads are ready + env: + ROLLOUTS: ${{ inputs.rollouts }} + run: | + kubectl -n "$RELEASE" get all + for workload in $ROLLOUTS; do + kubectl -n "$RELEASE" rollout status "$workload" --timeout=120s + done + + - name: Smoke test + if: inputs.smoke-test != '' + run: ${{ inputs.smoke-test }} + + - name: Debug on failure + if: failure() + run: | + kubectl -n "$RELEASE" get all + kubectl -n "$RELEASE" describe pods + for pod in $(kubectl -n "$RELEASE" get pods -o name); do + echo "::group::logs $pod" + kubectl -n "$RELEASE" logs "$pod" --all-containers --prefix --tail=200 || true + echo "::endgroup::" + done + if [ "${{ inputs.install-cnpg }}" = "true" ]; then + kubectl -n cnpg-system logs -l app.kubernetes.io/name=cloudnative-pg --tail=200 || true + fi + + - name: Uninstall + if: always() + run: helm uninstall "$RELEASE" --namespace "$RELEASE" --ignore-not-found diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml deleted file mode 100644 index fbd780e..0000000 --- a/.github/workflows/lint-test.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: Lint & Test Chart - -on: - pull_request: - paths: - - "charts/**" - - ".github/workflows/lint-test.yml" - push: - branches: [main] - paths: - - "charts/**" - - ".github/workflows/lint-test.yml" - workflow_dispatch: {} - -permissions: - contents: read - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: azure/setup-helm@v4 - with: - version: "v3.16.4" - - - uses: actions/setup-python@v5 - with: - python-version: "3.x" - - - name: Set up chart-testing - uses: helm/chart-testing-action@v2 - - - name: Run chart-testing (lint) - run: ct lint --charts charts/open-ev-data --validate-maintainers=false - - - name: helm template (default values) - run: helm template test charts/open-ev-data - - - name: helm template (bring-your-own data source) - run: | - helm template test charts/open-ev-data \ - --set api.database.fetch.enabled=false \ - --set-json 'api.extraVolumes=[{"name":"dataset","persistentVolumeClaim":{"claimName":"my-pvc"}}]' \ - --set-json 'api.extraVolumeMounts=[{"name":"dataset","mountPath":"/data","readOnly":true}]' - - mock-deploy: - runs-on: ubuntu-latest - needs: lint - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: azure/setup-helm@v4 - with: - version: "v3.16.4" - - - name: Create kind cluster - uses: helm/kind-action@v1 - with: - cluster_name: chart-testing - - - name: Install chart - run: | - helm install ev-mock charts/open-ev-data \ - --namespace ev-mock --create-namespace \ - --wait --timeout 5m - - - name: Verify workloads are ready - run: | - kubectl -n ev-mock get all - kubectl -n ev-mock rollout status deployment/ev-mock-api --timeout=120s - - - name: Smoke test the API health endpoint - run: | - kubectl -n ev-mock port-forward svc/ev-mock-api 3000:3000 & - PF_PID=$! - sleep 5 - curl -sf http://localhost:3000/api/v1/health - kill $PF_PID - - - name: Debug on failure - if: failure() - run: | - kubectl -n ev-mock get all - kubectl -n ev-mock describe pods - kubectl -n ev-mock logs -l app.kubernetes.io/name=api --tail=200 || true - kubectl -n ev-mock logs -l app.kubernetes.io/name=api --tail=200 -c fetch-dataset || true - - - name: Uninstall - if: always() - run: helm uninstall ev-mock --namespace ev-mock --ignore-not-found diff --git a/.github/workflows/open-ev-data.yml b/.github/workflows/open-ev-data.yml new file mode 100644 index 0000000..cec5cee --- /dev/null +++ b/.github/workflows/open-ev-data.yml @@ -0,0 +1,34 @@ +name: open-ev-data chart + +on: + pull_request: + paths: + - "charts/open-ev-data/**" + - ".github/workflows/open-ev-data.yml" + - ".github/workflows/chart-test.yml" + push: + branches: [main] + paths: + - "charts/open-ev-data/**" + - ".github/workflows/open-ev-data.yml" + - ".github/workflows/chart-test.yml" + workflow_dispatch: {} + +permissions: + contents: read + +jobs: + test: + uses: ./.github/workflows/chart-test.yml + with: + chart: open-ev-data + template-args: | + --set api.database.fetch.enabled=false --set-json 'api.extraVolumes=[{"name":"dataset","persistentVolumeClaim":{"claimName":"my-pvc"}}]' --set-json 'api.extraVolumeMounts=[{"name":"dataset","mountPath":"/data","readOnly":true}]' + release: ev-mock + rollouts: deployment/ev-mock-api + smoke-test: | + kubectl -n "$RELEASE" port-forward svc/ev-mock-api 3000:3000 & + PF_PID=$! + sleep 5 + curl -sf http://localhost:3000/api/v1/health + kill $PF_PID diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a30bfa3..70231fa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,8 +29,9 @@ Thanks for considering a contribution to this repository. ## Pull requests - Keep PRs focused on a single change where possible. -- CI (`.github/workflows/lint-test.yml`) runs `helm lint`, `helm template` against a couple of value - combinations, and a mock deployment in a `kind` cluster on every PR — make sure it's green. +- CI runs `helm lint`, `helm template` against a couple of value combinations, and a mock deployment + in a `kind` cluster for each chart a PR touches (one workflow per chart, e.g. + `.github/workflows/open-ev-data.yml`) — make sure it's green. - Describe *why* the change is needed, not just what changed. ## Releasing