Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting job #432

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/helm-docs.sh
Original file line number Diff line number Diff line change
@@ -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
69 changes: 68 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 # [email protected]
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:
Expand All @@ -17,7 +84,7 @@ jobs:
- name: Set up Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # [email protected]
with:
version: v3.10.0
version: v3.10.3

- uses: actions/setup-python@5ccb29d8773c3f3f653e1705f474dfaa8a06a912 # pin@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ charts/*/Chart.lock

# Vim swap files
*.swp

.github/bin
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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."