From 3b8ccd665e3b34d0f37ec3260393ba85c0ee39ce Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Mon, 7 Aug 2023 13:28:08 +0100 Subject: [PATCH] ci: Try to fix ct lint --- .github/workflows/checks.yml | 45 +++++++++++++++++++++++++----------- devbox.json | 41 +++++++++++++++----------------- devbox.lock | 30 ++++++++++++++++++++++++ make/go.mk | 16 ++++++++++++- 4 files changed, 94 insertions(+), 38 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 8e9a485b0..fc24a1b01 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -152,57 +152,74 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install devbox uses: jetpack-io/devbox-install-action@v0.5.0 with: enable-cache: true - - if: github.ref != 'refs/heads/main' - name: Fetch main if necessary - run: git fetch origin main:main - - name: Run chart-testing (list-changed) id: list-changed run: | - changed=$(devbox run -- ct list-changed --target-branch ${{ github.event.repository.default_branch }}) + changed="$(devbox run -- \ + ct list-changed --config charts/ct-config.yaml \ + )" if [[ -n "$changed" ]]; then echo "changed=true" >> "$GITHUB_OUTPUT" fi - if: steps.list-changed.outputs.changed == 'true' name: Run chart-testing (lint) - run: devbox run -- ct lint --config charts/ct-config.yaml + run: | + devbox run -- \ + ct lint --config charts/ct-config.yaml - if: steps.list-changed.outputs.changed == 'true' name: Create kind cluster run: | - devbox run -- kind create cluster \ - --image=ghcr.io/mesosphere/kind-node:"$(kubectl version --output=json --client | gojq --raw-output .clientVersion.gitVersion)" \ - --name=chart-testing + devbox run -- \ + kind create cluster \ + --image=ghcr.io/mesosphere/kind-node:"$(devbox run -- kubectl version --output=json --client | devbox run -- gojq --raw-output .clientVersion.gitVersion)" \ + --name=chart-testing env: KUBECONFIG: ct-kind-kubeconfig - if: steps.list-changed.outputs.changed == 'true' name: Build Docker images - run: devbox run -- make release-snapshot + run: | + devbox run -- \ + make release-snapshot - if: steps.list-changed.outputs.changed == 'true' name: Sideload docker image - run: devbox run -- kind load docker-image --name chart-testing "$(jq -r '.[] | select(.type == "Docker Image" and .goos == "linux" and .goarch == "amd64").name' dist/artifacts.json)" + run: | + devbox run -- \ + kind load docker-image \ + --name chart-testing \ + "$(devbox run -- gojq -r '.[] | select(.type == "Docker Image" and .goos == "linux" and .goarch == "amd64").name' dist/artifacts.json)" - if: steps.list-changed.outputs.changed == 'true' name: Setup Cluster API and cert-manager - run: devbox run -- make clusterctl.init + run: | + devbox run -- \ + make clusterctl.init env: KIND_KUBECONFIG: ct-kind-kubeconfig - if: steps.list-changed.outputs.changed == 'true' name: Run chart-testing (install) - run: devbox run -- ct install --config charts/ct-config.yaml --helm-extra-set-args "--set=image.tag=$(jq -r .version dist/metadata.json)" + run: | + devbox run -- \ + ct install \ + --config charts/ct-config.yaml \ + --helm-extra-set-args "--set=image.tag=$(devbox run -- jq -r .version dist/metadata.json)" env: KUBECONFIG: ct-kind-kubeconfig - if: steps.list-changed.outputs.changed == 'true' && always() name: - run: devbox run -- kind delete cluster --name chart-testing || true + run: | + devbox run -- \ + kind delete cluster --name chart-testing || true diff --git a/devbox.json b/devbox.json index 9b3b9cc1e..735109dde 100644 --- a/devbox.json +++ b/devbox.json @@ -1,41 +1,36 @@ { "packages": [ + "actionlint@latest", + "chart-testing@latest", "clusterctl@latest", + "crane@latest", + "envsubst@latest", + "findutils@latest", "fluxcd@latest", "ginkgo@latest", + "git@latest", "github-cli@latest", - "gojq@latest", + "gnumake@latest", + "gnused@latest", "go@latest", + "gojq@latest", "golangci-lint@latest", + "golines@latest", + "google-cloud-sdk@latest", "goreleaser@latest", - "kubernetes-helm@latest", + "gotestsum@latest", + "hadolint@latest", "helm-docs@latest", "kind@latest", "kubebuilder@latest", "kubectl@latest", + "kubernetes-controller-tools@latest", + "kubernetes-helm@latest", "kustomize@latest", "pre-commit@latest", "shfmt@latest", "upx@latest", - "yamllint@latest", - "chart-testing@latest", - "google-cloud-sdk@latest", - "crane@latest", - "gotestsum@latest", - "golines@latest", - "envsubst@latest", - "kubernetes-controller-tools@latest", - "actionlint@latest", - "hadolint@latest" - ], - "shell": { - "init_hook": [ - "echo 'Welcome to devbox!' > /dev/null" - ], - "scripts": { - "test": [ - "echo \"Error: no test specified\" && exit 1" - ] - } - } + "yamale@latest", + "yamllint@latest" + ] } diff --git a/devbox.lock b/devbox.lock index e764f137e..b2428a4a5 100644 --- a/devbox.lock +++ b/devbox.lock @@ -31,6 +31,12 @@ "source": "devbox-search", "version": "1.4.2" }, + "findutils@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#findutils", + "source": "devbox-search", + "version": "4.9.0" + }, "fluxcd@latest": { "last_modified": "2023-07-23T03:35:12Z", "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#fluxcd", @@ -43,12 +49,30 @@ "source": "devbox-search", "version": "2.11.0" }, + "git@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#git", + "source": "devbox-search", + "version": "2.41.0" + }, "github-cli@latest": { "last_modified": "2023-05-14T19:13:12Z", "resolved": "github:NixOS/nixpkgs/3007746b3f5bfcb49e102b517bca891822a41b31#github-cli", "source": "devbox-search", "version": "2.29.0" }, + "gnumake@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#gnumake", + "source": "devbox-search", + "version": "4.4.1" + }, + "gnused@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#gnused", + "source": "devbox-search", + "version": "4.9" + }, "go@latest": { "last_modified": "2023-07-30T12:29:02Z", "resolved": "github:NixOS/nixpkgs/3acb5c4264c490e7714d503c7166a3fde0c51324#go", @@ -157,6 +181,12 @@ "source": "devbox-search", "version": "4.0.2" }, + "yamale@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#yamale", + "source": "devbox-search", + "version": "4.0.4" + }, "yamllint@latest": { "last_modified": "2023-06-30T04:44:22Z", "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#yamllint", diff --git a/make/go.mk b/make/go.mk index 539477ab9..8afa13815 100644 --- a/make/go.mk +++ b/make/go.mk @@ -126,7 +126,6 @@ endif .PHONY: lint.% lint.%: ## Runs golangci-lint for a specific module lint.%: ; $(info $(M) linting $* module) - $(if $(filter-out root,$*),cd $* && )go fix ./... $(if $(filter-out root,$*),cd $* && )golines -w $$(go list ./... | sed "s|^$$(go list -m)|.|") $(if $(filter-out root,$*),cd $* && )golangci-lint run --fix --config=$(GOLANGCI_CONFIG_FILE) $(if $(filter-out root,$*),cd $* && )golines -w $$(go list ./... | sed "s|^$$(go list -m)|.|") @@ -160,6 +159,20 @@ go-clean.%: ## Cleans go build, test and modules caches for a specific module go-clean.%: ; $(info $(M) running go clean for $* module) $(if $(filter-out root,$*),cd $* && )go clean -r -i -cache -testcache -modcache +.PHONY: go-fix +go-fix: ## Runs go fix for all modules in repository +ifneq ($(wildcard $(REPO_ROOT)/go.mod),) +go-fix: go-fix.root +endif +ifneq ($(words $(GO_SUBMODULES_NO_TOOLS)),0) +go-fix: $(addprefix go-fix.,$(GO_SUBMODULES_NO_TOOLS:/go.mod=)) +endif + +.PHONY: go-fix.% +go-fix.%: ## Runs golangci-lint for a specific module +go-fix.%: ; $(info $(M) linting $* module) + $(if $(filter-out root,$*),cd $* && )go fix ./... + .PHONY: go-generate go-generate: ## Runs go generate go-generate: ; $(info $(M) running go generate) @@ -168,6 +181,7 @@ go-generate: ; $(info $(M) running go generate) output:crd:artifacts:config=charts/capi-runtime-extensions/crds \ output:rbac:artifacts:config=charts/capi-runtime-extensions/templates controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..." + $(MAKE) go-fix .PHONY: go-mod-upgrade go-mod-upgrade: ## Interactive check for direct module dependency upgrades