From 9cc2089a546464d2e3f4f996f56e9c399cc926e9 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Wed, 30 Nov 2022 12:55:51 +0100 Subject: [PATCH 1/3] Add linting job Signed-off-by: Marco Franssen --- .github/workflows/test.yml | 52 +++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8526f433..35bb0886 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,9 +3,59 @@ name: Test Charts on: pull_request: paths: + - ".github/workflows/test.yml" - "charts/**" jobs: + build-matrix: + name: Find charts + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3 + with: + fetch-depth: 0 + + - name: Find charts + id: build-matrix + run: | + charts=$(find charts -type f -name 'Chart.yaml' | sed -r 's|/[^/]+$||' | sort | uniq | jq -c --slurp --raw-input 'split("\n") | map(select(. != ""))') + echo "charts=$charts" >> $GITHUB_OUTPUT + + outputs: + charts: ${{ steps.build-matrix.outputs.charts }} + + lint: + runs-on: ubuntu-latest + needs: [build-matrix] + + strategy: + fail-fast: false + matrix: + chart: ${{ fromJson(needs.build-matrix.outputs.charts) }} + + steps: + - name: Checkout + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # pin@v3.5 + with: + version: v3.10.3 + + - name: Setup Sigstore Helm repo + run: | + helm repo add sigstore https://sigstore.github.io/helm-charts + helm repo update + + - name: Check lock file updated + run: | + helm dependency update . && helm dependency build . + git diff --exit-code + working-directory: ${{ matrix.chart }} + test: runs-on: ubuntu-latest steps: @@ -17,7 +67,7 @@ jobs: - name: Set up Helm uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # pin@v3.5 with: - version: v3.10.0 + version: v3.10.3 - uses: actions/setup-python@5ccb29d8773c3f3f653e1705f474dfaa8a06a912 # pin@v4 with: From 5465f9e33796902aeb0535449bb2c1009e49508c Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Wed, 30 Nov 2022 13:02:29 +0100 Subject: [PATCH 2/3] Check for helm-docs are updated Signed-off-by: Marco Franssen --- .github/helm-docs.sh | 39 ++++++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 5 +++++ .gitignore | 2 ++ CONTRIBUTING.md | 6 ++++++ 4 files changed, 52 insertions(+) create mode 100755 .github/helm-docs.sh diff --git a/.github/helm-docs.sh b/.github/helm-docs.sh new file mode 100755 index 00000000..909528ec --- /dev/null +++ b/.github/helm-docs.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPTPATH=$(dirname "$0") +HELM_DOCS_VERSION="1.11.0" + +function install_helm_docs { + case "$(uname -s)" in + Linux*) + machine=Linux + shasum=sha256sum + ;; + Darwin*) + machine=Darwin + shasum=shasum + ;; + esac + + 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 helm-docs + mv helm-docs "$SCRIPTPATH/bin/" + rm helm-docs_"${HELM_DOCS_VERSION}"_${machine}_x86_64.tar.gz +} + +if [ ! -f "$SCRIPTPATH/bin/helm-docs" ] ; then + install_helm_docs +elif [[ ! "$("$SCRIPTPATH/bin/helm-docs" --version)" =~ .*"$HELM_DOCS_VERSION".* ]] ; then + install_helm_docs +else + echo "Using '$("$SCRIPTPATH/bin/helm-docs" --version)'" +fi + +# validate docs +"$SCRIPTPATH/bin/helm-docs" -g $1 +git diff --exit-code diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35bb0886..6d7dd952 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,7 @@ on: pull_request: paths: - ".github/workflows/test.yml" + - ".github/helm-docs.sh" - "charts/**" jobs: @@ -56,6 +57,10 @@ jobs: git diff --exit-code working-directory: ${{ matrix.chart }} + - name: Check docs updated + run: ../../.github/helm-docs.sh . + working-directory: ${{ matrix.chart }} + test: runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index c81f8645..e9b8ff01 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ charts/*/Chart.lock # Vim swap files *.swp + +.github/bin diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 42fb98d1..f89531a9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,5 +57,11 @@ Any changes to Chart.yaml or values.yaml require an update of the README.md. Thi helm-docs -g charts/«chart-name» ``` +or + +```shell +.github/helm-docs.sh charts/«chart-name» +``` + [crane]: https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane.md "Crane is a tool for managing container images" [helm-docs]: https://github.com/norwoodj/helm-docs "The helm-docs tool auto-generates documentation from helm charts into markdown files." From 2a7c45b16ae4bef41a3e0e08bb38d48f994025f6 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Wed, 30 Nov 2022 13:24:17 +0100 Subject: [PATCH 3/3] Add job summary to point to contributing.md Signed-off-by: Marco Franssen --- .github/workflows/test.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d7dd952..b973a3f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,6 +61,18 @@ jobs: run: ../../.github/helm-docs.sh . working-directory: ${{ matrix.chart }} + - name: Print job summary + if: failure() + run: | + echo '### Linting summary:' >> $GITHUB_STEP_SUMMARY + echo '' >> $GITHUB_STEP_SUMMARY + echo 'Please check our CONTRIBUTING.md sections:' >> $GITHUB_STEP_SUMMARY + echo '' >> $GITHUB_STEP_SUMMARY + echo "- [Bumping helm chart dependencies](${REPO_URL}/blob/main/CONTRIBUTING.md#bumping-helm-chart-dependencies)" >> $GITHUB_STEP_SUMMARY + echo "- [Generating documentation](${REPO_URL}/blob/main/CONTRIBUTING.md#generating-documentation)" >> $GITHUB_STEP_SUMMARY + env: + REPO_URL: github.com/${{ github.repository }} + test: runs-on: ubuntu-latest steps: