From 0b9e9166d1b867ed3b5cdcc940e3be8d3499b44b Mon Sep 17 00:00:00 2001 From: Artem Torubarov Date: Wed, 6 Nov 2024 16:49:58 +0100 Subject: [PATCH] ci: generated chart examples check --- .github/workflows/ci.yml | 32 ++++++++++++++++++++++++++++++-- README.md | 23 +++++++++++++++++++++++ pkg/processor/meta.go | 2 +- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cdcb21bb..2bb91fa2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,18 @@ jobs: cache: false - name: Fmt - run: go fmt ./... - + run: | + # Run gofmt in "diff" mode to check for unformatted code + UNFORMATTED_FILES=$(gofmt -l .) + # Check if any files are unformatted + if [[ -n "$UNFORMATTED_FILES" ]]; then + echo "::error::The following Go files are not formatted correctly:" + echo "$UNFORMATTED_FILES" # List unformatted files in the log + echo "::error::Please format your Go code by running \`go fmt ./...\` and commit the changes." + exit 1 # Fail the check + else + echo "All Go files are properly formatted." + fi - name: Vet run: go vet ./... @@ -33,6 +43,24 @@ jobs: uses: golangci/golangci-lint-action@v3 with: version: v1.54 +# Generate example charts + - name: Generate example charts + run: | + cat test_data/sample-app.yaml | go run ./cmd/helmify examples/app + cat test_data/k8s-operator-kustomize.output | go run ./cmd/helmify examples/operator + - name: Check that chart examples were commited + run: | + if [[ -n "$(git status --porcelain)" ]]; then + # Capture the list of uncommitted files + UNCOMMITTED_FILES=$(git status --porcelain) + echo "::error::Chart examples generation step has uncommitted changes: $UNCOMMITTED_FILES + Please run following commands and commit the results: + - \`cat test_data/sample-app.yaml | go run ./cmd/helmify examples/app\` + - \`cat test_data/k8s-operator-kustomize.output | go run ./cmd/helmify examples/operator\`" + exit 1 + else + echo "Chart examples generation check passed. No uncommitted changes." + fi # Dry-run generated charts in cluster - name: Install k8s cluster uses: helm/kind-action@v1.4.0 diff --git a/README.md b/README.md index 592b299d..590a12eb 100644 --- a/README.md +++ b/README.md @@ -162,3 +162,26 @@ go test ./... Beside unit-tests, project contains e2e test `pkg/app/app_e2e_test.go`. It's a go test, which uses `test_data/*` to generate a chart in temporary directory. Then runs `helm lint --strict` to check if generated chart is valid. + +## Contribute + +Following rules will help changes to be accepted faster: +- For more than one-line bugfixes consider creating an issue with bug description or feature request +- For feature request try to think about and cover following topics (when applicable): + - Motivation: why feature is needed? Which problem does it solve? What is current workaround? + - Backward-compatibility: existing users expect that after upgrading helmify version their existing generated charts wont be changed without consent. +- For bugfix PR consider adding example to [/test_data](./test_data/) source yamls reproducing bug. + +### Contribution flow + +Check list before submitting PR: +1. Run `go fmt ./...` +2. Run tests `go test ./...` +3. Update chart examples: + ```shell + cat test_data/sample-app.yaml | go run ./cmd/helmify examples/app + ``` + ```shell + cat test_data/k8s-operator-kustomize.output | go run ./cmd/helmify examples/operator + ``` +4. In case of long commit history (more than 3) squash local commits into one diff --git a/pkg/processor/meta.go b/pkg/processor/meta.go index 660c7cad..6593e161 100644 --- a/pkg/processor/meta.go +++ b/pkg/processor/meta.go @@ -82,7 +82,7 @@ func ProcessObjMeta(appMeta helmify.AppMetadata, obj *unstructured.Unstructured, } } - if (obj.GetNamespace() != "") && (appMeta.Config().PreserveNs){ + if (obj.GetNamespace() != "") && (appMeta.Config().PreserveNs) { namespace, err = yamlformat.Marshal(map[string]interface{}{"namespace": obj.GetNamespace()}, 2) if err != nil { return "", err