From 6c09bf3dfd70e78c458f8061eb6a0a2e92aee141 Mon Sep 17 00:00:00 2001 From: Ciara Stacke Date: Tue, 1 Aug 2023 10:51:22 +0100 Subject: [PATCH 1/3] Add yaml lint to pre-commit and CI --- .github/workflows/lint.yml | 25 +++++++++++++++++++------ .pre-commit-config.yaml | 11 ++++++++--- .yamllint.yaml | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 .yamllint.yaml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 613cffd74c..4be00b6b8f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -81,13 +81,13 @@ jobs: name: Markdown Lint runs-on: ubuntu-22.04 steps: - - name: Checkout Repository - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - name: Checkout Repository + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - - uses: DavidAnson/markdownlint-cli2-action@8f3516061301755c97ff833a8e933f09282cc5b5 # v11.0.0 - with: - config: ${{ github.workspace }}/.markdownlint-cli2.yaml - globs: '**/*.md' + - uses: DavidAnson/markdownlint-cli2-action@8f3516061301755c97ff833a8e933f09282cc5b5 # v11.0.0 + with: + config: ${{ github.workspace }}/.markdownlint-cli2.yaml + globs: '**/*.md' chart-lint: name: Chart Lint @@ -97,3 +97,16 @@ jobs: uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - name: Lint chart run: make lint-helm + + yaml-lint: + name: Yaml Lint + runs-on: ubuntu-22.04 + steps: + - name: Checkout Repository + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + + - name: Install yamllint + run: pip install yamllint + + - name: Lint YAML files + run: yamllint . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4a155f1ded..268b0a58d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,12 +49,17 @@ repos: - id: golangci-lint args: [--new-from-patch=/tmp/diff.patch] - # Rules are in .markdownlint-cli2.yaml file - # See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md for rule descriptions + # Rules are in .markdownlint-cli2.yaml file + # See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md for rule descriptions - repo: https://github.com/DavidAnson/markdownlint-cli2 rev: v0.8.1 hooks: - - id: markdownlint-cli2-fix + - id: markdownlint-cli2-fix + + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.29.0 + hooks: + - id: yamllint ci: skip: [golang-diff, golangci-lint, prettier, markdownlint-cli2-fix] diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000000..e5c6e634c8 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,33 @@ +--- + +yaml-files: + - '*.yaml' + - '*.yml' + +rules: + braces: enable + brackets: enable + colons: enable + commas: enable + comments: + require-starting-space: true + ignore-shebangs: true + min-spaces-from-content: 1 + comments-indentation: + level: warning + document-end: disable + document-start: disable + empty-lines: enable + empty-values: disable + float-values: disable + hyphens: enable + indentation: enable + key-duplicates: enable + key-ordering: disable + line-length: disable + new-line-at-end-of-file: enable + new-lines: enable + octal-values: disable + quoted-strings: disable + trailing-spaces: enable + truthy: disable From 1a62941844719cf8b7de43fcb227a3edd0ad1015 Mon Sep 17 00:00:00 2001 From: Ciara Stacke Date: Tue, 1 Aug 2023 11:24:29 +0100 Subject: [PATCH 2/3] Fix yaml lint issues --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/conformance.yml | 2 +- .github/workflows/scorecards.yml | 1 + .golangci.yml | 6 ++--- .pre-commit-config.yaml | 4 ++- .yamllint.yaml | 28 ++++++++++++++++----- examples/http-header-filter/echo-route.yaml | 2 +- examples/http-header-filter/headers.yaml | 3 ++- 8 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5d59b30f53..1d5f0ecbba 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -62,7 +62,7 @@ jobs: # and modify them (or add more) to build your code if your project # uses a compiled language - #- run: | + # - run: | # make bootstrap # make release diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index 3451325f68..4414b59322 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -107,7 +107,7 @@ jobs: nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1) nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2) if [ ${{ github.event_name }} == "schedule" ]; then - export GW_API_VERSION=main + export GW_API_VERSION=main fi make install-nkg-local-no-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag} working-directory: ./conformance diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 633e93ca83..334f32c2eb 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -2,6 +2,7 @@ name: Scorecards supply-chain security on: # Only the default branch is supported. branch_protection_rule: + types: [created, edited, deleted] schedule: - cron: "27 5 * * 0" push: diff --git a/.golangci.yml b/.golangci.yml index 656cb6818a..7b84de3ecc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -34,11 +34,11 @@ linters-settings: min-complexity: 15 govet: enable: - - fieldalignment + - fieldalignment lll: line-length: 120 linters: - enable: + enable: - asciicheck - errcheck - errorlint @@ -63,7 +63,7 @@ linters: - unparam - unused - wastedassign - disable-all: true + disable-all: true issues: max-issues-per-linter: 0 max-same-issues: 0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 268b0a58d5..47069ea9b1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,11 +56,13 @@ repos: hooks: - id: markdownlint-cli2-fix + # Rules are in .yamllint.yaml file + # See https://yamllint.readthedocs.io/en/stable/rules.html# for rule descriptions - repo: https://github.com/adrienverge/yamllint.git rev: v1.29.0 hooks: - id: yamllint ci: - skip: [golang-diff, golangci-lint, prettier, markdownlint-cli2-fix] + skip: [golang-diff, golangci-lint, prettier, markdownlint-cli2-fix, yamllint] autofix_prs: false diff --git a/.yamllint.yaml b/.yamllint.yaml index e5c6e634c8..636e58214d 100644 --- a/.yamllint.yaml +++ b/.yamllint.yaml @@ -4,6 +4,9 @@ yaml-files: - '*.yaml' - '*.yml' +ignore: + - deploy/helm-chart/templates/ + rules: braces: enable brackets: enable @@ -13,21 +16,34 @@ rules: require-starting-space: true ignore-shebangs: true min-spaces-from-content: 1 - comments-indentation: - level: warning + comments-indentation: enable document-end: disable document-start: disable empty-lines: enable - empty-values: disable + empty-values: enable float-values: disable hyphens: enable - indentation: enable + indentation: + spaces: consistent + indent-sequences: consistent + check-multi-line-strings: true + ignore: | + deploy/manifests/nginx-conf.yaml + deploy/manifests/njs-modules.yaml key-duplicates: enable key-ordering: disable - line-length: disable + line-length: + max: 120 + allow-non-breakable-words: true + allow-non-breakable-inline-mappings: true + ignore: | + .github/workflows/ + deploy/manifests/deployment.yaml new-line-at-end-of-file: enable new-lines: enable octal-values: disable quoted-strings: disable trailing-spaces: enable - truthy: disable + truthy: + ignore: | + .github/workflows/ diff --git a/examples/http-header-filter/echo-route.yaml b/examples/http-header-filter/echo-route.yaml index b3f5da29dd..b92357128a 100644 --- a/examples/http-header-filter/echo-route.yaml +++ b/examples/http-header-filter/echo-route.yaml @@ -22,7 +22,7 @@ spec: add: - name: Accept-Encoding value: compress - - name: My-cool-header + - name: My-cool-header value: this-is-an-appended-value remove: - User-Agent diff --git a/examples/http-header-filter/headers.yaml b/examples/http-header-filter/headers.yaml index a15cd03798..4324c41e9f 100644 --- a/examples/http-header-filter/headers.yaml +++ b/examples/http-header-filter/headers.yaml @@ -30,6 +30,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: headers-config +# yamllint disable rule:indentation data: nginx.conf: |- user nginx; @@ -61,7 +62,7 @@ data: return s; } export default {getRequestHeaders}; - +# yamllint enable rule:indentation --- apiVersion: v1 kind: Service From c32785086385a459a72a6cf399e08efd921b9191 Mon Sep 17 00:00:00 2001 From: Ciara Stacke Date: Wed, 2 Aug 2023 11:28:24 +0100 Subject: [PATCH 3/3] Update after rebase and review feedback --- .yamllint.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.yamllint.yaml b/.yamllint.yaml index 636e58214d..ee5549f963 100644 --- a/.yamllint.yaml +++ b/.yamllint.yaml @@ -6,6 +6,7 @@ yaml-files: ignore: - deploy/helm-chart/templates/ + - deploy/helm-chart/crds/ rules: braces: enable @@ -28,7 +29,7 @@ rules: indent-sequences: consistent check-multi-line-strings: true ignore: | - deploy/manifests/nginx-conf.yaml + deploy/manifests/nginx-gateway.yaml deploy/manifests/njs-modules.yaml key-duplicates: enable key-ordering: disable @@ -38,7 +39,7 @@ rules: allow-non-breakable-inline-mappings: true ignore: | .github/workflows/ - deploy/manifests/deployment.yaml + deploy/manifests/nginx-gateway.yaml new-line-at-end-of-file: enable new-lines: enable octal-values: disable