From 6b38521a42a00aabbb37d4a06927c9cefe483289 Mon Sep 17 00:00:00 2001 From: lukasmetzner <lukas.metzner@hetzner-cloud.de> Date: Tue, 17 Dec 2024 15:41:06 +0100 Subject: [PATCH 1/9] ci: added golangci-lint to pre-commit Added golangci-lint run hook to pre-commit configuration and removed separate CI step. --- .github/workflows/ci.yml | 16 ---------------- .pre-commit-config.yaml | 6 ++++++ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19d2bb45..05727c67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,22 +36,6 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - uses: golangci/golangci-lint-action@v6 - with: - version: v1.62.2 # renovate: datasource=github-releases depName=golangci/golangci-lint - - # In general linting is quite fast with warm caches, but a fresh run might take some time. - args: --timeout 5m - deploy-manifests: name: Check deployment manifests runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca811bf3..c954e3bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,6 +46,12 @@ repos: entry: shfmt -i 2 -ci -sr -kp -w types: [shell] + - repo: https://github.com/golangci/golangci-lint/ + rev: v1.62.2 + hooks: + - id: golangci-lint + args: [--timeout=5m] + - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.10.0.1 hooks: From 687e4e70d4adcfd1680c2f3c578183038f238bad Mon Sep 17 00:00:00 2001 From: lukasmetzner <lukas.metzner@hetzner-cloud.de> Date: Tue, 17 Dec 2024 15:50:20 +0100 Subject: [PATCH 2/9] ci: pin golangci-lint language version Pin golangci-lint language version and let it manage via renovate --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c954e3bb..0fdf571a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -51,6 +51,7 @@ repos: hooks: - id: golangci-lint args: [--timeout=5m] + language_version: 1.23.4 # renovate: datasource=golang-version - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.10.0.1 From be07d31ac2dc58c782161873dc2cce544744231a Mon Sep 17 00:00:00 2001 From: Lukas Metzner <lukas.metzner@hetzner-cloud.de> Date: Tue, 17 Dec 2024 15:51:18 +0100 Subject: [PATCH 3/9] Update .pre-commit-config.yaml Co-authored-by: Jonas L. <jooola@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0fdf571a..c0e07965 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,7 @@ repos: entry: shfmt -i 2 -ci -sr -kp -w types: [shell] - - repo: https://github.com/golangci/golangci-lint/ + - repo: https://github.com/golangci/golangci-lint rev: v1.62.2 hooks: - id: golangci-lint From 195dbb6148c545a9aafbacdaee65e019bcfb0124 Mon Sep 17 00:00:00 2001 From: lukasmetzner <lukas.metzner@hetzner-cloud.de> Date: Tue, 17 Dec 2024 15:53:49 +0100 Subject: [PATCH 4/9] ci: use golangci-lint-full as we use pre-commit in the ci --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c0e07965..240b0985 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,7 +49,7 @@ repos: - repo: https://github.com/golangci/golangci-lint rev: v1.62.2 hooks: - - id: golangci-lint + - id: golangci-lint-full args: [--timeout=5m] language_version: 1.23.4 # renovate: datasource=golang-version From 4a4318dcf7031117443aead0866e7cd4772b19d5 Mon Sep 17 00:00:00 2001 From: lukasmetzner <lukas.metzner@hetzner-cloud.de> Date: Tue, 17 Dec 2024 16:03:10 +0100 Subject: [PATCH 5/9] style: moved golangci-lint to ensure shell formatters are grouped --- .pre-commit-config.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 240b0985..abe3cac3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,6 +36,13 @@ repos: files: \.(md|ya?ml)$ exclude: ^(CHANGELOG.md|chart/templates/.*|chart/.snapshots/.*)$ + - repo: https://github.com/golangci/golangci-lint + rev: v1.62.2 + hooks: + - id: golangci-lint-full + args: [--timeout=5m] + language_version: 1.23.4 # renovate: datasource=golang-version + - repo: local hooks: - id: shfmt @@ -46,13 +53,6 @@ repos: entry: shfmt -i 2 -ci -sr -kp -w types: [shell] - - repo: https://github.com/golangci/golangci-lint - rev: v1.62.2 - hooks: - - id: golangci-lint-full - args: [--timeout=5m] - language_version: 1.23.4 # renovate: datasource=golang-version - - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.10.0.1 hooks: From 8a4933ede15d96e7fc878331a41e99a3531003c2 Mon Sep 17 00:00:00 2001 From: lukasmetzner <lukas.metzner@hetzner-cloud.de> Date: Tue, 17 Dec 2024 16:20:29 +0100 Subject: [PATCH 6/9] ci: add cache for golangci-lint --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05727c67..50dc0add 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,11 @@ jobs: with: python-version: 3.x + - uses: actions/cache@v4 + with: + path: ~/.cache/golangci-lint + key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + - uses: pre-commit/action@v3.0.1 test: From 92b8c15a75c8b904c266db61b082bdbf63bbbcfb Mon Sep 17 00:00:00 2001 From: Lukas Metzner <lukas.metzner@hetzner-cloud.de> Date: Tue, 17 Dec 2024 22:12:59 +0100 Subject: [PATCH 7/9] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50dc0add..66a96663 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/cache@v4 with: path: ~/.cache/golangci-lint - key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + key: pre-commit-golangci-lint|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} - uses: pre-commit/action@v3.0.1 From 006f0b33d5272ff3104406ea38d02281d8e2373f Mon Sep 17 00:00:00 2001 From: lukasmetzner <lukas.metzner@hetzner-cloud.de> Date: Wed, 18 Dec 2024 10:03:25 +0100 Subject: [PATCH 8/9] ci: include hash of source files to cache key Additionally include restore-keys. --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66a96663..e65461f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,11 @@ jobs: - uses: actions/cache@v4 with: path: ~/.cache/golangci-lint - key: pre-commit-golangci-lint|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + key: pre-commit-golangci-lint|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}|${{ hashFiles('**/*.go') }} + restore-keys: | + pre-commit-golangci-lint|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}| + pre-commit-golangci-lint|${{ env.pythonLocation }}| + pre-commit-golangci-lint| - uses: pre-commit/action@v3.0.1 From 1fed6bc3c1305c153ab6d971ed3ff18253d8fb13 Mon Sep 17 00:00:00 2001 From: lukasmetzner <lukas.metzner@hetzner-cloud.de> Date: Wed, 18 Dec 2024 10:08:34 +0100 Subject: [PATCH 9/9] ci: golangci-lint as last pre-commit step golangci-lint has by far the longest runtime and should therefore be executed last. --- .pre-commit-config.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index abe3cac3..d04dbf77 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,13 +36,6 @@ repos: files: \.(md|ya?ml)$ exclude: ^(CHANGELOG.md|chart/templates/.*|chart/.snapshots/.*)$ - - repo: https://github.com/golangci/golangci-lint - rev: v1.62.2 - hooks: - - id: golangci-lint-full - args: [--timeout=5m] - language_version: 1.23.4 # renovate: datasource=golang-version - - repo: local hooks: - id: shfmt @@ -57,3 +50,10 @@ repos: rev: v0.10.0.1 hooks: - id: shellcheck + + - repo: https://github.com/golangci/golangci-lint + rev: v1.62.2 + hooks: + - id: golangci-lint-full + args: [--timeout=5m] + language_version: 1.23.4 # renovate: datasource=golang-version