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 8526f433..b973a3f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,9 +3,76 @@ name: Test Charts on: pull_request: paths: + - ".github/workflows/test.yml" + - ".github/helm-docs.sh" - "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 }} + + - name: Check docs updated + 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: @@ -17,7 +84,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: 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."