name: "Charts: Test" on: workflow_call: inputs: checkoutCommit: required: true type: string chartChanges: required: true type: string env: HELM_VERSION: 3.9.2 jobs: generate-test-matrix: name: Generate matrix for install runs-on: ubuntu-22.04 outputs: install-matrix: | { "chart": ${{ steps.list-changed.outputs.charts }}, "k8s_version": ["v1.22.12", "v1.24.3"] } unittest-matrix: | { "chart": ${{ steps.list-changed.outputs.charts }} } detected: ${{ steps.list-changed.outputs.detected }} steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 ref: ${{ inputs.checkoutCommit }} - name: Run chart-testing (list-changed) id: list-changed if: inputs.chartChanges != '' run: | EXCLUDED=$(yq -o json eval '.excluded-charts-install' .ci/ct/ct.yaml) CHARTS_JSON=$(yq --null-input -o json eval '"${{ inputs.chartChanges }}" | split(" ")') OUTPUT_JSON=$(yq --null-input -o json eval "$CHARTS_JSON - $EXCLUDED") echo ::set-output name=charts::${OUTPUT_JSON} if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then echo "::set-output name=detected::true" fi install-charts: needs: - generate-test-matrix if: needs.generate-test-matrix.outputs.detected == 'true' name: Install charts strategy: matrix: ${{ fromJson(needs.generate-test-matrix.outputs.install-matrix) }} fail-fast: false runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 ref: ${{ inputs.checkoutCommit }} - name: Install Kubernetes tools uses: yokawasa/action-setup-kube-tools@v0.8.2 with: setup-tools: | helmv3 kubectl helm: "${{ env.HELM_VERSION }}" kubectl: "${{ matrix.k8s_version }}" - uses: actions/setup-python@v4 with: python-version: "3.10" - name: Set up chart-testing uses: helm/chart-testing-action@v2.2.1 - name: Create k3d cluster uses: nolar/setup-k3d-k3s@v1 with: version: ${{ matrix.k8s_version }} - name: Remove node taints run: | kubectl taint --all=true nodes node.cloudprovider.kubernetes.io/uninitialized- || true - name: Run chart-testing (install) run: ct install --config .ci/ct/ct.yaml --charts ${{ matrix.chart }} # Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7 install_success: needs: - generate-test-matrix - install-charts if: | always() name: Install successful runs-on: ubuntu-22.04 steps: - name: Check install matrix status if: ${{ (needs.generate-test-matrix.outputs.detected == 'true') && (needs.install-charts.result != 'success') }} run: exit 1 unittest: name: Run unit tests runs-on: ubuntu-20.04 needs: - generate-test-matrix if: needs.generate-test-matrix.outputs.detected == 'true' strategy: matrix: ${{ fromJson(needs.generate-test-matrix.outputs.unittest-matrix) }} fail-fast: false steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 ref: ${{ inputs.checkoutCommit }} - name: Install Kubernetes tools uses: yokawasa/action-setup-kube-tools@v0.8.2 with: setup-tools: | helmv3 helm: "${{ env.HELM_VERSION }}" - name: Run tests run: | helm plugin install https://github.com/vbehar/helm3-unittest --version v1.0.16 cd ${{ matrix.chart }} helm unittest -f "tests/**/*_test.yaml" . # Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7 unittest_success: needs: - generate-test-matrix - unittest if: | always() name: Unittest successful runs-on: ubuntu-22.04 steps: - name: Check unittest matrix status if: ${{ (needs.generate-test-matrix.outputs.detected == 'true') && (needs.unittest.result != 'success') }} run: exit 1