From a5e2543a50eb5b7533bf3e9521cf81f07891432d Mon Sep 17 00:00:00 2001 From: Max! Date: Sun, 31 Mar 2024 10:02:51 +0200 Subject: [PATCH] Update cd-helm-release.yml --- .github/workflows/cd-helm-release.yml | 154 ++++++++++++++++++++++---- 1 file changed, 131 insertions(+), 23 deletions(-) diff --git a/.github/workflows/cd-helm-release.yml b/.github/workflows/cd-helm-release.yml index 456fdf7..24e006c 100644 --- a/.github/workflows/cd-helm-release.yml +++ b/.github/workflows/cd-helm-release.yml @@ -1,38 +1,146 @@ -name: Release +name: Lint and Test Chart on: - workflow_dispatch: - push: - branches: - - main + pull_request: paths: - 'charts/**' + workflow_dispatch: + +permissions: + contents: read jobs: - release: - environment: helm-release - permissions: - contents: write + lint: + name: Lint runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 0 - - - name: Configure Git - run: | - git config user.name "$GITHUB_ACTOR" - git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + fetch-depth: "0" - name: Install Helm uses: azure/setup-helm@v3.5 - id: helm-install - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Run chart-releaser - uses: helm/chart-releaser-action@v1.6.0 - env: - CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - CR_GENERATE_RELEASE_NOTES: true + - 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 --target-branch ${{ github.event.repository.default_branch }}) + #if [[ -n "$changed" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + #fi + + - name: Run chart-testing (lint) + id: lint + if: steps.list-changed.outputs.changed == 'true' + run: ct lint --target-branch ${{ github.event.repository.default_branch }} + + - name: Create kind cluster + uses: helm/kind-action@v1.9.0 + if: steps.list-changed.outputs.changed == 'true' + + - name: verify cluster and local path + run: | + kubectl config set-context kind-chart-testing + kubectl cluster-info + kubectl get pods -A + pwd + ls -hal + + - name: Install Certmanager + run: | + helm repo add jetstack https://charts.jetstack.io + helm repo update + helm install cert-manager jetstack/cert-manager \ + --namespace cert-manager \ + --create-namespace \ + --set installCRDs=true \ + --set prometheus.enabled=false \ + --wait + + - name: Install CNPG Operator + run: | + helm repo add cnpg-operator https://cloudnative-pg.github.io/charts + helm repo update + helm install cnpg-operator cnpg-operator/cloudnative-pg \ + --namespace cnpg-system \ + --create-namespace \ + --wait + + - name: Creat testing values + working-directory: ./charts/cloudnative-pg-cluster + run: | + cat << EOF > test-values.yaml + name: "cnpg" + instances: 3 + bootstrap: + initdb: + database: app + owner: app + secret: + name: null + certificates: + server: + enabled: true + generate: true + serverTLSSecret: "" + serverCASecret: "" + client: + enabled: true + generate: true + clientCASecret: "" + replicationTLSSecret: "" + user: + enabled: true + username: + - "app" + monitoring: + enablePodMonitor: false + postgresql: + pg_hba: + - hostssl all all all cert + resources: + requests: + cpu: "50m" + memory: "256Mi" + limits: + cpu: "1000m" + memory: "1024Mi" + storage: + size: 1Gi + testApp: + enabled: false + EOF + + - name: Install CNPG cluster + working-directory: ./charts/cloudnative-pg-cluster + run: | + helm repo add cnpg-cluster https://small-hack.github.io/cloudnative-pg-cluster-chart + helm repo update + helm install cnpg-cluster cnpg-cluster/cnpg-cluster \ + --values test-values.yaml + + ITER=0 + while true; do + if [[ $ITER -ge 300 ]]; then + echo "Cluster not ready" + exit 1 + fi + READY_INSTANCES=$(kubectl get cluster cnpg -o jsonpath='{.status.readyInstances}') + if [[ "$READY_INSTANCES" == 3 ]]; then + echo "Cluster up and running" + break + fi + sleep 1 + STATUS=$(kubectl get cluster) + echo "$STATUS" + (( ++ITER )) + done + + - name: Run chart-testing (install) + id: install + if: steps.list-changed.outputs.changed == 'true' + run: ct install --target-branch ${{ github.event.repository.default_branch }}