diff --git a/.github/actions/test-charts/action.yml b/.github/actions/test-charts/action.yml new file mode 100644 index 00000000..3af4224e --- /dev/null +++ b/.github/actions/test-charts/action.yml @@ -0,0 +1,185 @@ +name: 'Test Charts' +description: 'Set up environment and run chart testing' + +inputs: + target_branch: + description: 'Target branch for chart-testing' + required: true + extra_helm_args: + description: 'Extra Helm arguments to pass to ct install' + required: false + default: '' + all_charts: + description: 'Install all charts instead of only changed ones' + required: false + default: 'false' + +runs: + using: 'composite' + steps: + - name: Set up Helm + uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # renovate: tag=v3.5 + with: + version: v3.10.0 + + - name: Set up Python + uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6 + with: + python-version: 3.14 + + - name: Set up chart-testing + uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f # v2.8.0 + with: + version: '3.14.0' + yamllint_version: '1.37.1' + yamale_version: '6.0.0' + + - name: Run chart-testing (list-changed) + id: list-changed + shell: bash + env: + INPUT_TARGET_BRANCH: ${{ inputs.target_branch }} + INPUT_ALL_CHARTS: ${{ inputs.all_charts }} + run: | + if [[ "$INPUT_ALL_CHARTS" == "true" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + echo "backstageChartChanged=true" >> "$GITHUB_OUTPUT" + else + listChanged=$(ct list-changed --target-branch "$INPUT_TARGET_BRANCH") + if [[ -n "$listChanged" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + if grep 'charts/backstage' <<< "$listChanged"; then + echo "backstageChartChanged=true" >> "$GITHUB_OUTPUT" + fi + fi + fi + + - name: Remove unnecessary files to free up disk space + if: steps.list-changed.outputs.changed == 'true' + uses: endersonmenezes/free-disk-space@e6ed9b02e683a3b55ed0252f1ee469ce3b39a885 # v3 + with: + remove_android: true + remove_dotnet: true + remove_haskell: true + rm_cmd: "rmz" + + - name: Add Helm Repositories + if: steps.list-changed.outputs.changed == 'true' + shell: bash + run: | + helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx + helm repo add bitnami https://charts.bitnami.com/bitnami + helm repo add backstage https://backstage.github.io/charts + helm repo update + + - name: Generate KinD Config + if: steps.list-changed.outputs.changed == 'true' + shell: bash + run: | + cat < /tmp/kind-config.yaml + apiVersion: kind.x-k8s.io/v1alpha4 + kind: Cluster + nodes: + - role: control-plane + extraPortMappings: + - containerPort: 80 + hostPort: 80 + protocol: TCP + - containerPort: 443 + hostPort: 443 + protocol: TCP + EOF + + - name: Create KIND Cluster + if: steps.list-changed.outputs.changed == 'true' + uses: helm/kind-action@92086f6be054225fa813e0a4b13787fc9088faab # v1.13.0 + with: + config: /tmp/kind-config.yaml + + - name: Create custom storage class + if: steps.list-changed.outputs.changed == 'true' + shell: bash + run: | + export defaultScProvisioner=$(kubectl get storageclass -o jsonpath='{.items[?(@.metadata.annotations.storageclass\.kubernetes\.io/is-default-class=="true")].provisioner}') + if [[ -z "$defaultScProvisioner" ]]; then + echo "No default storage class found or it has no provisioner. Exiting early because the test using the custom Storage Class will likely fail. Use a cluster that has a default storage class." + exit 1 + fi + echo "[INFO] defaultScProvisioner=$defaultScProvisioner" + + cat <> "$GITHUB_OUTPUT" - if grep 'charts/backstage' <<< "$listChanged"; then - echo "backstageChartChanged=true" >> "$GITHUB_OUTPUT" - fi - fi - - - name: Remove unnecessary files to free up disk space - if: steps.list-changed.outputs.changed == 'true' - uses: endersonmenezes/free-disk-space@e6ed9b02e683a3b55ed0252f1ee469ce3b39a885 # v3 - with: - remove_android: true - remove_dotnet: true - remove_haskell: true - rm_cmd: "rmz" - - - name: Add Helm Repositories - if: steps.list-changed.outputs.changed == 'true' - run: | - helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx - helm repo add bitnami https://charts.bitnami.com/bitnami - helm repo add backstage https://backstage.github.io/charts - helm repo update - - - name: Generate KinD Config - if: steps.list-changed.outputs.changed == 'true' - run: | - cat < /tmp/kind-config.yaml - apiVersion: kind.x-k8s.io/v1alpha4 - kind: Cluster - nodes: - - role: control-plane - extraPortMappings: - - containerPort: 80 - hostPort: 80 - protocol: TCP - - containerPort: 443 - hostPort: 443 - protocol: TCP - EOF - - - name: Create KIND Cluster - if: steps.list-changed.outputs.changed == 'true' - uses: helm/kind-action@92086f6be054225fa813e0a4b13787fc9088faab # v1.13.0 - with: - config: /tmp/kind-config.yaml - - - name: Create custom storage class - if: steps.list-changed.outputs.changed == 'true' - run: | - export defaultScProvisioner=$(kubectl get storageclass -o jsonpath='{.items[?(@.metadata.annotations.storageclass\.kubernetes\.io/is-default-class=="true")].provisioner}') - if [[ -z "$defaultScProvisioner" ]]; then - echo "No default storage class found or it has no provisioner. Exiting early because the test using the custom Storage Class will likely fail. Use a cluster that has a default storage class." - exit 1 - fi - echo "[INFO] defaultScProvisioner=$defaultScProvisioner" - - cat <