Skip to content

Commit cdb8317

Browse files
authored
Add formatting configurations and yamllint action (#376)
Adds a pipeline step to ensure kustomization and yaml validity before merging. Also adds configurations for yamlfmt and pre-commit to ease formatting for users. Changes: * lint-yaml job that executes `yamllint` for all directories except the CRDs that are autogenerated by kubebuilder. * `.yamllint` file for configuration of [yamllint](https://github.com/adrienverge/yamllint) * `.yamlfmt` file for configuration of [yamlfmt](https://github.com/google/yamlfmt) * `.pre-commit-config.yaml` file for configuration of [pre-commit](https://pre-commit.com/)
1 parent 2b4019c commit cdb8317

File tree

150 files changed

+475
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+475
-269
lines changed

.github/dependabot.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
version: 2
23
updates:
34
- package-ecosystem: github-actions

.github/workflows/build-image.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: Build docker image
3-
on:
3+
on: # yamllint disable-line rule:truthy
44
push:
55
branches:
66
- main
@@ -33,7 +33,7 @@ jobs:
3333
id: meta
3434
uses: docker/metadata-action@v5.7.0
3535
with:
36-
images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
36+
images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
3737
tags: |
3838
# (for commits on the main branch only) generate a tag named `latest`
3939
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}

.github/workflows/codeql.yml

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
# For most projects, this workflow file will not need changing; you simply need
23
# to commit it to your repository.
34
#
@@ -11,11 +12,11 @@
1112
#
1213
name: "CodeQL Advanced"
1314

14-
on:
15+
on: # yamllint disable-line rule:truthy
1516
push:
16-
branches: [ "main" ]
17+
branches: ["main"]
1718
pull_request:
18-
branches: [ "main" ]
19+
branches: ["main"]
1920
schedule:
2021
- cron: '41 6 * * 1'
2122

@@ -43,58 +44,58 @@ jobs:
4344
fail-fast: false
4445
matrix:
4546
include:
46-
- language: actions
47-
build-mode: none
48-
- language: go
49-
build-mode: autobuild
50-
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
51-
# Use `c-cpp` to analyze code written in C, C++ or both
52-
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
53-
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
54-
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
55-
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
56-
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
57-
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
47+
- language: actions
48+
build-mode: none
49+
- language: go
50+
build-mode: autobuild
51+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
52+
# Use `c-cpp` to analyze code written in C, C++ or both
53+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
54+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
55+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
56+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
57+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
58+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
5859
steps:
59-
- name: Checkout repository
60-
uses: actions/checkout@v4
60+
- name: Checkout repository
61+
uses: actions/checkout@v4
6162

62-
# Add any setup steps before running the `github/codeql-action/init` action.
63-
# This includes steps like installing compilers or runtimes (`actions/setup-node`
64-
# or others). This is typically only required for manual builds.
65-
# - name: Setup runtime (example)
66-
# uses: actions/setup-example@v1
63+
# Add any setup steps before running the `github/codeql-action/init` action.
64+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
65+
# or others). This is typically only required for manual builds.
66+
# - name: Setup runtime (example)
67+
# uses: actions/setup-example@v1
6768

68-
# Initializes the CodeQL tools for scanning.
69-
- name: Initialize CodeQL
70-
uses: github/codeql-action/init@v3
71-
with:
72-
languages: ${{ matrix.language }}
73-
build-mode: ${{ matrix.build-mode }}
74-
# If you wish to specify custom queries, you can do so here or in a config file.
75-
# By default, queries listed here will override any specified in a config file.
76-
# Prefix the list here with "+" to use these queries and those in the config file.
69+
# Initializes the CodeQL tools for scanning.
70+
- name: Initialize CodeQL
71+
uses: github/codeql-action/init@v3
72+
with:
73+
languages: ${{ matrix.language }}
74+
build-mode: ${{ matrix.build-mode }}
75+
# If you wish to specify custom queries, you can do so here or in a config file.
76+
# By default, queries listed here will override any specified in a config file.
77+
# Prefix the list here with "+" to use these queries and those in the config file.
7778

78-
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
79-
# queries: security-extended,security-and-quality
79+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
80+
# queries: security-extended,security-and-quality
8081

81-
# If the analyze step fails for one of the languages you are analyzing with
82-
# "We were unable to automatically build your code", modify the matrix above
83-
# to set the build mode to "manual" for that language. Then modify this step
84-
# to build your code.
85-
# ℹ️ Command-line programs to run using the OS shell.
86-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
87-
- if: matrix.build-mode == 'manual'
88-
shell: bash
89-
run: |
90-
echo 'If you are using a "manual" build mode for one or more of the' \
91-
'languages you are analyzing, replace this with the commands to build' \
92-
'your code, for example:'
93-
echo ' make bootstrap'
94-
echo ' make release'
95-
exit 1
82+
# If the analyze step fails for one of the languages you are analyzing with
83+
# "We were unable to automatically build your code", modify the matrix above
84+
# to set the build mode to "manual" for that language. Then modify this step
85+
# to build your code.
86+
# ℹ️ Command-line programs to run using the OS shell.
87+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
88+
- if: matrix.build-mode == 'manual'
89+
shell: bash
90+
run: |
91+
echo 'If you are using a "manual" build mode for one or more of the' \
92+
'languages you are analyzing, replace this with the commands to build' \
93+
'your code, for example:'
94+
echo ' make bootstrap'
95+
echo ' make release'
96+
exit 1
9697
97-
- name: Perform CodeQL Analysis
98-
uses: github/codeql-action/analyze@v3
99-
with:
100-
category: "/language:${{matrix.language}}"
98+
- name: Perform CodeQL Analysis
99+
uses: github/codeql-action/analyze@v3
100+
with:
101+
category: "/language:${{matrix.language}}"

.github/workflows/e2e-tests.yaml

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
---
12
# Modified from https://github.com/prometheus-operator/prometheus-operator/blob/main/.github/workflows/e2e-feature-gated.yaml
23
name: e2e-tests
34
permissions:
45
contents: read
5-
on:
6+
on: # yamllint disable-line rule:truthy
67
push:
78
branches:
89
- main
@@ -20,41 +21,41 @@ jobs:
2021
name: Against netbox version 3.7.8
2122
runs-on: ubuntu-latest
2223
steps:
23-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
24-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
25-
with:
26-
go-version: 1.24.4
27-
- name: Import environment variables from file
28-
run: |
29-
cat ".github/env" >> "$GITHUB_ENV"
30-
- name: Run e2e tests
31-
run: |
32-
make test-e2e-3.7.8
24+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
25+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
26+
with:
27+
go-version: 1.24.4
28+
- name: Import environment variables from file
29+
run: |
30+
cat ".github/env" >> "$GITHUB_ENV"
31+
- name: Run e2e tests
32+
run: |
33+
make test-e2e-3.7.8
3334
e2e-tests-4-0-11:
3435
name: Against netbox version 4.0.11
3536
runs-on: ubuntu-latest
3637
steps:
37-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
38-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
39-
with:
40-
go-version: 1.24.4
41-
- name: Import environment variables from file
42-
run: |
43-
cat ".github/env" >> "$GITHUB_ENV"
44-
- name: Run e2e tests
45-
run: |
46-
make test-e2e-4.0.11
38+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
39+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
40+
with:
41+
go-version: 1.24.4
42+
- name: Import environment variables from file
43+
run: |
44+
cat ".github/env" >> "$GITHUB_ENV"
45+
- name: Run e2e tests
46+
run: |
47+
make test-e2e-4.0.11
4748
e2e-tests-4-1-11:
4849
name: Against netbox version 4.1.11
4950
runs-on: ubuntu-latest
5051
steps:
51-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
52-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
53-
with:
54-
go-version: 1.24.4
55-
- name: Import environment variables from file
56-
run: |
57-
cat ".github/env" >> "$GITHUB_ENV"
58-
- name: Run e2e tests
59-
run: |
60-
make test-e2e-4.1.11
52+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
53+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
54+
with:
55+
go-version: 1.24.4
56+
- name: Import environment variables from file
57+
run: |
58+
cat ".github/env" >> "$GITHUB_ENV"
59+
- name: Run e2e tests
60+
run: |-
61+
make test-e2e-4.1.11

.github/workflows/govuln.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: Go Vulnerability Checker
3-
on:
3+
on: # yamllint disable-line rule:truthy
44
push:
55
branches:
66
- main
@@ -12,11 +12,11 @@ jobs:
1212
test:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
16-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
15+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
16+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
1717
with:
1818
go-version: 1.24.4
19-
- run: |
19+
- run: |-
2020
set -euo pipefail
2121
2222
make vulncheck

.github/workflows/integration-test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: Integration Tests
3-
on:
3+
on: # yamllint disable-line rule:truthy
44
push:
55
branches:
66
- main
@@ -13,11 +13,11 @@ jobs:
1313
test:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
17-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
16+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
17+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
1818
with:
1919
go-version: 1.24.4
2020
- name: tests
21-
run: |
21+
run: |-
2222
go install github.com/onsi/ginkgo/v2/ginkgo
2323
make integration-test

.github/workflows/lint.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: Static analysis
3-
on:
3+
on: # yamllint disable-line rule:truthy
44
push:
55
branches:
66
- main
@@ -12,12 +12,12 @@ jobs:
1212
go-and-crds:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
16-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
15+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
16+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
1717
with:
1818
go-version: 1.24.4
1919
- name: golangci-lint
20-
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
20+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
2121
with:
2222
version: v2.1.2
2323
args: --config tools/.golangci.yaml
@@ -61,8 +61,14 @@ jobs:
6161
codespell:
6262
runs-on: ubuntu-latest
6363
steps:
64-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
64+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
6565
- name: Run codespell
6666
uses: codespell-project/actions-codespell@v2
6767
with:
6868
skip: '*.svg'
69+
yamllint:
70+
runs-on: ubuntu-latest
71+
steps:
72+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
73+
- name: 'Yamllint'
74+
uses: karancode/yamllint-github-action@master

.github/workflows/unit-test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: Unit tests
3-
on:
3+
on: # yamllint disable-line rule:truthy
44
push:
55
branches:
66
- main
@@ -13,10 +13,10 @@ jobs:
1313
test:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
17-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
16+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
17+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
1818
with:
1919
go-version: 1.24.4
2020
- name: tests
21-
run: |
21+
run: |-
2222
make test

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# todo: run in CI. similar to https://scm.swisscom.com/5gdmc/misc/ci-templates/-/blob/main/stage_lint/jobs/pre-commit.yaml?ref_type=heads
2+
3+
---
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.5.0
7+
hooks:
8+
- id: check-yaml
9+
args: [--allow-multiple-documents]
10+
- id: end-of-file-fixer
11+
- id: mixed-line-ending
12+
- id: trailing-whitespace
13+
- repo: https://github.com/Lucas-C/pre-commit-hooks
14+
rev: v1.5.5
15+
hooks:
16+
- id: remove-crlf
17+
- repo: https://github.com/google/yamlfmt
18+
rev: v0.17.0
19+
hooks:
20+
- id: yamlfmt
21+
language: system
22+
exclude: ^config/crd|^config/rbac|^config/manager|^config/default|^config/prometheus|^config/network-policy
23+
- repo: "https://github.com/adrienverge/yamllint"
24+
rev: v1.35.1
25+
hooks:
26+
- id: yamllint
27+
exclude: ^config/crd|^config/rbac|^config/manager|^config/default|^config/prometheus|^config/network-policy
28+
- repo: https://github.com/codespell-project/codespell
29+
rev: v2.1.0
30+
hooks:
31+
- id: codespell
32+
files: ^.*\.(py|c|h|md|rst|yml)$
33+
args: [--ignore-words-list, "swisscom,thor,cpbroker", "--skip", "*.svg", "--write-changes"]

.yamlfmt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
formatter:
2+
type: basic
3+
include_document_start: true
4+
pad_line_comments: 2
5+
trim_trailing_whitespace: true
6+
retain_line_breaks_single: true
7+
eof_newline: true

0 commit comments

Comments
 (0)