From 5025bdaf37d23da49e260497c43cabb1cd77122a Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Thu, 8 Dec 2022 13:14:31 +0100 Subject: [PATCH 1/6] Add Helm chart workflow that checks for updated documentation Signed-off-by: Marco Franssen --- .github/scripts/helm-docs.sh | 46 ++++++++++++++++++++++++++++ .github/workflows/helm-chart-ci.yaml | 23 ++++++++++++++ .gitignore | 1 + 3 files changed, 70 insertions(+) create mode 100755 .github/scripts/helm-docs.sh create mode 100644 .github/workflows/helm-chart-ci.yaml create mode 100644 .gitignore diff --git a/.github/scripts/helm-docs.sh b/.github/scripts/helm-docs.sh new file mode 100755 index 0000000..d77d15c --- /dev/null +++ b/.github/scripts/helm-docs.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPTPATH=$(dirname "$0") +HELM_DOCS_VERSION="1.11.0" + +case "$(uname -s)" in + Linux*) + machine=Linux + shasum=sha256sum + exe=helm-docs + ;; + Darwin*) + machine=Darwin + shasum=shasum + exe=helm-docs + ;; + MINGW64*) + machine=Windows + shasum=sha256sum + exe=helm-docs.exe + ;; +esac + +function install_helm_docs { + curl -LO https://github.com/norwoodj/helm-docs/releases/download/v"${HELM_DOCS_VERSION}"/helm-docs_"${HELM_DOCS_VERSION}"_${machine}_x86_64.tar.gz + curl -L --output /tmp/checksums_helm-docs.txt https://github.com/norwoodj/helm-docs/releases/download/v${HELM_DOCS_VERSION}/checksums.txt + grep helm-docs_${HELM_DOCS_VERSION}_${machine}_x86_64.tar.gz /tmp/checksums_helm-docs.txt | $shasum -c - + mkdir -p "$SCRIPTPATH/bin" + tar -xf helm-docs_"${HELM_DOCS_VERSION}"_${machine}_x86_64.tar.gz ${exe} + mv ${exe} "$SCRIPTPATH/bin/" + rm helm-docs_"${HELM_DOCS_VERSION}"_${machine}_x86_64.tar.gz +} + +if [ ! -f "$SCRIPTPATH/bin/${exe}" ] ; then + install_helm_docs +elif [[ ! "$("$SCRIPTPATH/bin/${exe}" --version)" =~ .*"$HELM_DOCS_VERSION".* ]] ; then + install_helm_docs +else + echo "Using '$("$SCRIPTPATH/bin/${exe}" --version)'" +fi + +# validate docs +"$SCRIPTPATH/bin/${exe}" +git diff --exit-code diff --git a/.github/workflows/helm-chart-ci.yaml b/.github/workflows/helm-chart-ci.yaml new file mode 100644 index 0000000..cecd1ce --- /dev/null +++ b/.github/workflows/helm-chart-ci.yaml @@ -0,0 +1,23 @@ +name: Helm Chart CI + +on: + pull_request: + paths: + - 'charts/**' + - '.github/workflows/helm-chart-ci.yml' + - '.github/scripts/*.sh' + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + check-docs: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout + uses: actions/checkout@v3.1.0 + + - name: Verify Docs updated + run: .github/scripts/helm-docs.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bcaef3e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.github/scripts/bin From 9779a1295bdea426b67e07ea8d980735c515b1a2 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Thu, 8 Dec 2022 13:28:04 +0100 Subject: [PATCH 2/6] Add job to lint helm-chart Signed-off-by: Marco Franssen --- .github/workflows/helm-chart-ci.yaml | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.github/workflows/helm-chart-ci.yaml b/.github/workflows/helm-chart-ci.yaml index cecd1ce..fd20bde 100644 --- a/.github/workflows/helm-chart-ci.yaml +++ b/.github/workflows/helm-chart-ci.yaml @@ -21,3 +21,32 @@ jobs: - name: Verify Docs updated run: .github/scripts/helm-docs.sh + + lint-chart: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout + uses: actions/checkout@v3.1.0 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@v3.4 + with: + version: v3.10.2 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11.1 + + - name: Setup chart-testing + uses: helm/chart-testing-action@v2.3.1 + with: + version: v3.7.1 + + - name: Run chart-testing (lint) + run: | + ct lint --debug \ + --target-branch main From f7443d22b89f6e3a68a675622a7a6637a874f563 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Thu, 8 Dec 2022 13:37:56 +0100 Subject: [PATCH 3/6] Add job to test Helm chart using Kind Signed-off-by: Marco Franssen --- .github/kind/conf/kind-config.yaml | 17 ++++++ .github/workflows/helm-chart-ci.yaml | 79 ++++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 .github/kind/conf/kind-config.yaml diff --git a/.github/kind/conf/kind-config.yaml b/.github/kind/conf/kind-config.yaml new file mode 100644 index 0000000..6c900fe --- /dev/null +++ b/.github/kind/conf/kind-config.yaml @@ -0,0 +1,17 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +kubeadmConfigPatches: + - | + apiVersion: kubeadm.k8s.io/v1beta2 + kind: ClusterConfiguration + metadata: + name: config + apiServer: + extraArgs: + service-account-key-file: /etc/kubernetes/pki/sa.pub + service-account-signing-key-file: /etc/kubernetes/pki/sa.key + service-account-issuer: api,spire-agent + api-audiences: api,spire-server + # admission-control-config-file: /etc/kubernetes/pki/admctrl/admission-control.yaml +nodes: + - role: control-plane diff --git a/.github/workflows/helm-chart-ci.yaml b/.github/workflows/helm-chart-ci.yaml index fd20bde..aafa8a9 100644 --- a/.github/workflows/helm-chart-ci.yaml +++ b/.github/workflows/helm-chart-ci.yaml @@ -6,11 +6,17 @@ on: - 'charts/**' - '.github/workflows/helm-chart-ci.yml' - '.github/scripts/*.sh' + - '.github/kind/conf/kind-config.yaml' concurrency: group: ${{ github.ref }} cancel-in-progress: true +env: + HELM_VERSION: v3.10.2 + PYTHON_VERSION: 3.11.1 + CHART_TESTING_VERSION: v3.7.1 + jobs: check-docs: runs-on: ubuntu-22.04 @@ -34,19 +40,86 @@ jobs: - name: Set up Helm uses: azure/setup-helm@v3.4 with: - version: v3.10.2 + version: ${{ env.HELM_VERSION }} - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.11.1 + python-version: ${{ env.PYTHON_VERSION }} - name: Setup chart-testing uses: helm/chart-testing-action@v2.3.1 with: - version: v3.7.1 + version: ${{ env.CHART_TESTING_VERSION }} + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --target-branch main) + if [[ -n "$changed" ]]; then + echo "changed=true" >> $GITHUB_OUTPUT + fi - name: Run chart-testing (lint) run: | ct lint --debug \ --target-branch main + + outputs: + changed: ${{ steps.list-changed.outputs.changed }} + + test: + runs-on: ubuntu-22.04 + needs: + - lint-chart + + strategy: + fail-fast: false + matrix: + # Choose tags corresponding to the version of Kind being used. + # At a minimum, we should test the currently supported versions of + # Kubernetes, but can go back farther as long as we don't need heroics + # to pull it off (i.e. kubectl version juggling). + k8s: + - v1.25.3 + - v1.24.7 + - v1.23.13 + - v1.22.15 + - v1.21.14 + + steps: + - name: Checkout + uses: actions/checkout@v3.1.0 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@v3.4 + with: + version: ${{ env.HELM_VERSION }} + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Setup chart-testing + uses: helm/chart-testing-action@v2.3.1 + with: + version: ${{ env.CHART_TESTING_VERSION }} + + - name: Create kind ${{ matrix.k8s }} cluster + uses: helm/kind-action@v1.4.0 + # Only build a kind cluster if there are chart changes to test. + if: needs.lint-chart.outputs.changed == 'true' + with: + version: v0.17.0 + node_image: kindest/node:${{ matrix.k8s }} + config: .github/kind/conf/kind-config.yaml + verbosity: 1 + + - name: Run chart-testing (install) + run: | + ct install --debug \ + --target-branch main \ + --exclude-deprecated From d1106fdd4c91fb474d9f6ba5578d0714e1df16a9 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Thu, 8 Dec 2022 14:15:31 +0100 Subject: [PATCH 4/6] Allow manual dispatch of CI workflow Signed-off-by: Marco Franssen --- .github/workflows/helm-chart-ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/helm-chart-ci.yaml b/.github/workflows/helm-chart-ci.yaml index aafa8a9..49c83ff 100644 --- a/.github/workflows/helm-chart-ci.yaml +++ b/.github/workflows/helm-chart-ci.yaml @@ -1,6 +1,7 @@ name: Helm Chart CI on: + workflow_dispatch: pull_request: paths: - 'charts/**' From 1ed5cf123919c51b4430afdde2653fa477e01583 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Tue, 13 Dec 2022 12:17:54 +0100 Subject: [PATCH 5/6] Bump actions to latest version Signed-off-by: Marco Franssen --- .github/workflows/helm-chart-ci.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/helm-chart-ci.yaml b/.github/workflows/helm-chart-ci.yaml index 49c83ff..80fa796 100644 --- a/.github/workflows/helm-chart-ci.yaml +++ b/.github/workflows/helm-chart-ci.yaml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 - name: Verify Docs updated run: .github/scripts/helm-docs.sh @@ -34,12 +34,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 with: fetch-depth: 0 - name: Set up Helm - uses: azure/setup-helm@v3.4 + uses: azure/setup-helm@v3.5 with: version: ${{ env.HELM_VERSION }} @@ -90,12 +90,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 with: fetch-depth: 0 - name: Set up Helm - uses: azure/setup-helm@v3.4 + uses: azure/setup-helm@v3.5 with: version: ${{ env.HELM_VERSION }} From 320dce4eb24117b405c08cf0815d00070c2dc988 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Thu, 15 Dec 2022 10:20:49 +0100 Subject: [PATCH 6/6] Only run tests if a chart changed Signed-off-by: Marco Franssen --- .github/workflows/helm-chart-ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/helm-chart-ci.yaml b/.github/workflows/helm-chart-ci.yaml index 80fa796..c064f83 100644 --- a/.github/workflows/helm-chart-ci.yaml +++ b/.github/workflows/helm-chart-ci.yaml @@ -74,6 +74,8 @@ jobs: needs: - lint-chart + if: needs.lint-chart.outputs.changed == 'true' + strategy: fail-fast: false matrix: @@ -112,7 +114,6 @@ jobs: - name: Create kind ${{ matrix.k8s }} cluster uses: helm/kind-action@v1.4.0 # Only build a kind cluster if there are chart changes to test. - if: needs.lint-chart.outputs.changed == 'true' with: version: v0.17.0 node_image: kindest/node:${{ matrix.k8s }}