Sdk automated testing (#241) #432
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Lint, test and publish dev charts | |
on: | |
push: | |
paths: | |
- 'charts/**' | |
env: | |
HELM_REGISTRY: ghcr.io/scroll-tech/scroll-sdk/helm/dev | |
jobs: | |
helm-chart-testing-not-scroll-sdk: | |
name: chart-testing-without-scroll-sdk | |
runs-on: ubuntu-latest | |
environment: test | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: v3.12.1 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
check-latest: true | |
- name: Set up chart-testing | |
uses: helm/[email protected] | |
- name: Helm registry login | |
run: | | |
helm registry login ghcr.io/scroll-tech/helm/scroll-sdk --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} | |
# List chart change except scroll-sdk | |
- name: Run chart-testing (list-changed) | |
id: list-changed | |
run: | | |
changed=$(ct list-changed --excluded-charts scroll-sdk --target-branch ${{ github.event.repository.default_branch }} ) | |
if [[ -n "$changed" ]]; then | |
echo "changed=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Run chart-testing (lint) | |
if: steps.list-changed.outputs.changed == 'true' | |
run: ct lint --config ct.yaml --excluded-charts scroll-sdk --target-branch ${{ github.event.repository.default_branch }} | |
publish-ghcr-not-scroll-sdk: | |
name: publish-to-github-without-scroll-sdk | |
runs-on: ubuntu-latest | |
needs: | |
- helm-chart-testing-not-scroll-sdk | |
outputs: | |
charts: ${{ steps.list-changed.outputs.changed }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
base: ${{ github.event.repository.default_branch }} | |
list-files: shell | |
filters: | | |
addedOrModified: | |
- added|modified: 'charts/**' | |
- name: Helm registry login | |
run: | | |
helm registry login ghcr.io/scroll-tech/helm/scroll-sdk --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} | |
# We filter here the scroll-sdk chart | |
- name: Push chart to ghcr | |
if: steps.filter.outputs.addedOrModified == 'true' | |
env: | |
HELM_EXPERIMENTAL_OCI: 1 | |
run: | | |
set -x | |
CHARTS=() | |
PATHS=(${{ steps.filter.outputs.addedOrModified_files }}) | |
echo ${PATHS} | |
# Get only the chart paths | |
for i in "${PATHS[@]}" | |
do | |
chart=$(echo $i | awk -F "/" '{print $2}') | |
if [ "$chart" != "scroll-sdk" ]; then | |
CHARTS+=($chart) | |
fi | |
done | |
# Remove duplicates | |
CHARTS=( `for i in ${CHARTS[@]}; do echo $i; done | sort -u` ) | |
echo "CHARTS: ${CHARTS[@]}" | |
for chart in ${CHARTS[@]}; do | |
helm dependencies build charts/$chart | |
helm package charts/$chart | |
export CHART_VERSION=$(grep 'version:' charts/$chart/Chart.yaml | head -n1 | awk '{ print $2 }') | |
helm push $chart-${CHART_VERSION}.tgz oci://${HELM_REGISTRY} | |
done | |
helm-chart-testing-scroll-sdk: | |
name: chart-testing-scroll-sdk | |
runs-on: ubuntu-latest | |
needs: | |
- publish-ghcr-not-scroll-sdk | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: v3.12.1 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
check-latest: true | |
- name: Set up chart-testing | |
uses: helm/[email protected] | |
- name: Setup scroll-sdk values | |
run: cd charts/scroll-sdk && docker run --rm -t -v .:/contracts/volume scrolltech/scroll-stack-contracts:gen-configs-50c2661f6d3a40c34cc5b4fffbd0d7ba59d3dbae | |
- name: Helm registry login | |
run: | | |
helm registry login ghcr.io/scroll-tech/helm/scroll-sdk --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} | |
# List scroll-sdk chart if it has changed | |
- name: Run chart-testing (list-changed) | |
id: list-changed | |
run: | | |
changed=$(ct list-changed --chart-dirs charts/scroll-sdk --target-branch ${{ github.event.repository.default_branch }} ) | |
if [[ -n "$changed" ]]; then | |
echo "changed=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Run chart-testing (lint) | |
if: steps.list-changed.outputs.changed == 'true' | |
run: ct lint --config ct.yaml --charts scroll-sdk --target-branch ${{ github.event.repository.default_branch }} | |
publish-ghcr-scroll-sdk: | |
name: publish-scroll-sdk-to-github | |
runs-on: ubuntu-latest | |
needs: | |
- helm-chart-testing-scroll-sdk | |
outputs: | |
charts: ${{ steps.list-changed.outputs.changed }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
base: ${{ github.event.repository.default_branch }} | |
list-files: shell | |
filters: | | |
addedOrModified: | |
- added|modified: 'charts/scroll-sdk/**' | |
- name: Helm registry login | |
run: | | |
helm registry login ghcr.io/scroll-tech/helm/scroll-sdk --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} | |
- name: Replace helm registry by helm/dev | |
run: | | |
sed -i 's|oci://ghcr.io/scroll-tech/scroll-sdk/helm|oci://ghcr.io/scroll-tech/scroll-sdk/helm/dev|g' charts/scroll-sdk/Chart.yaml | |
- name: Push chart to ghcr | |
if: steps.filter.outputs.addedOrModified == 'true' | |
env: | |
HELM_EXPERIMENTAL_OCI: 1 | |
run: | | |
set -x | |
CHARTS=() | |
PATHS=(${{ steps.filter.outputs.addedOrModified_files }}) | |
echo ${PATHS} | |
# Get only the chart paths | |
for i in "${PATHS[@]}" | |
do | |
CHARTS+=($(echo $i | awk -F "/" '{print $2}')) | |
done | |
# Remove duplicates | |
CHARTS=( `for i in ${CHARTS[@]}; do echo $i; done | sort -u` ) | |
echo "CHARTS: ${CHARTS[@]}" | |
for chart in ${CHARTS[@]}; do | |
helm dependencies build charts/$chart | |
helm package charts/$chart | |
export CHART_VERSION=$(grep 'version:' charts/$chart/Chart.yaml | head -n1 | awk '{ print $2 }') | |
helm push $chart-${CHART_VERSION}.tgz oci://${HELM_REGISTRY} | |
done | |
kubeconform: | |
name: kubeconform-check | |
runs-on: ubuntu-latest | |
needs: | |
- publish-ghcr-scroll-sdk | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
base: ${{ github.event.repository.default_branch }} | |
list-files: shell | |
filters: | | |
addedOrModified: | |
- added|modified: 'charts/scroll-sdk/**' | |
- name: Helm registry login | |
run: | | |
helm registry login ghcr.io/scroll-tech/helm/scroll-sdk --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} | |
- name: Replace helm registry by helm/dev | |
run: | | |
find charts/ -type f -exec sed -i 's|oci://ghcr.io/scroll-tech/scroll-sdk/helm|oci://ghcr.io/scroll-tech/scroll-sdk/helm/dev|g' {} + | |
- name: Install Kubeconform | |
run: | | |
set -e | |
wget https://github.com/yannh/kubeconform/releases/download/v0.6.7/kubeconform-linux-amd64.tar.gz | |
tar xf kubeconform-linux-amd64.tar.gz | |
sudo mv kubeconform /usr/local/bin/ | |
- name: Add Helm repositories | |
run: | | |
helm repo add grafana https://grafana.github.io/helm-charts | |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts | |
helm repo add blockscout https://blockscout.github.io/helm-charts | |
helm repo update | |
- name: Validate rendered templates | |
run: | | |
set -e | |
failed_charts=() | |
for chart in charts/*; do | |
if [ -d "$chart" ]; then | |
echo "Processing chart $chart" | |
if [[ $(basename $chart) == "common" ]] || [[ $(basename $chart) == "external-secrets-lib" ]]; then | |
echo "Skipping library chart: $chart" | |
continue | |
fi | |
if ! helm dependency update $chart; then | |
failed_charts+=("$chart - dependency update failed") | |
continue | |
fi | |
if ! helm dependency build $chart; then | |
failed_charts+=("$chart - dependency build failed") | |
continue | |
fi | |
if ! helm template $(basename $chart) $chart | kubeconform \ | |
-summary \ | |
-output json \ | |
-schema-location default \ | |
-schema-location https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/jsonnet/prometheus-operator/servicemonitors-crd.json \ | |
-schema-location https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/jsonnet/prometheus-operator/alertmanagers-crd.json \ | |
-schema-location https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/jsonnet/prometheus-operator/prometheusrules-crd.json \ | |
-schema-location https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/jsonnet/prometheus-operator/prometheuses-crd.json \ | |
-schema-location https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/jsonnet/prometheus-operator/podmonitors-crd.json \ | |
-strict \ | |
-; then | |
failed_charts+=("$chart - validation failed") | |
fi | |
fi | |
done | |
if [ ${#failed_charts[@]} -ne 0 ]; then | |
echo "faild charts are:" | |
printf '%s\n' "${failed_charts[@]}" | |
exit 1 | |
fi | |
run-k8s-test: | |
name: check-services-up-and-running | |
runs-on: ubuntu-latest | |
needs: | |
- publish-ghcr-scroll-sdk | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: v3.12.1 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
check-latest: true | |
- name: Set up chart-testing | |
uses: helm/[email protected] | |
- name: Replace helm registry by helm/dev | |
run: | | |
find devnet/ -type f -exec sed -i 's|oci://ghcr.io/scroll-tech/scroll-sdk/helm|oci://ghcr.io/scroll-tech/scroll-sdk/helm/dev|g' {} + | |
- name: Create Kind Cluster | |
uses: helm/[email protected] | |
with: | |
cluster_name: chart-testing | |
- name: Helm registry login | |
run: | | |
helm registry login ghcr.io/scroll-tech/helm/scroll-sdk --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} | |
- name: Run Devnet Bootstrap | |
run: cd devnet && make bootstrap | |
- name: Install Charts using Makefile | |
run: | | |
cd devnet | |
make install | |
- name: Ensure all services are up and running | |
run: | | |
START_TIME=$(date +%s) | |
TIMEOUT=600 | |
while true; do | |
ELAPSED_TIME=$(( $(date +%s) - START_TIME )) | |
if [ "$ELAPSED_TIME" -ge "$TIMEOUT" ]; then | |
echo "Timeout reached: Exiting after $TIMEOUT seconds" | |
exit 1 | |
fi | |
kubectl get pods | |
kubectl describe nodes | |
if kubectl wait --for=condition=Ready pod --all --field-selector=status.phase!=Succeeded,status.phase!=Failed --timeout=5s; then | |
echo "All pods are ready." | |
break | |
else | |
echo "Waiting for pods to be ready..." | |
sleep 10 | |
fi | |
done |