From 9f0d6c58814fb17cd5daaab1e127ffb9c5001b54 Mon Sep 17 00:00:00 2001 From: Silvestre Zabala Date: Fri, 30 Aug 2024 10:57:44 +0200 Subject: [PATCH] chore(linter): Run linters from devbox # Issue Version skew between GitHub action, `go run` and binary from Nix makes debugging linter issues impossible. # Fix Use Nix binary everywhere. --- .github/workflows/linters.yaml | 84 ++++------------------------------ Makefile | 21 ++++----- devbox.json | 5 +- devbox.lock | 73 ++++++++++++++++++++++++----- 4 files changed, 83 insertions(+), 100 deletions(-) diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index 1996c0edff..b41c7b904e 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -6,40 +6,24 @@ jobs: linters: name: reviewdog runs-on: ubuntu-latest - container: - image: ghcr.io/cloudfoundry/app-autoscaler-release-tools:main steps: - name: Checkout uses: actions/checkout@v4 - name: Trust my checkout run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" - - name: make build-all - run: | - make build-all - - - name: get golangci-lint version - id: get-golangci-lint-version + - name: Install devbox + uses: jetify-com/devbox-install-action@a03caf5813591bc882139eba6ae947930a83a427 # v0.11.0 + with: + enable-cache: 'true' + - name: Make devbox shellenv available run: | - version=v$(grep golangci-lint .tool-versions | cut -d " " -f 2 ) - echo "golangci-lint version from .tool-versions: '${version}'" - echo "version=${version}" >> "$GITHUB_OUTPUT"; + eval "$(devbox shellenv)" + printenv >> $GITHUB_ENV - - name: get go version - id: get-golang-version + - name: Run Go linter run: | - version="$(grep "golang " .tool-versions| cut -f 2 -d " ")" - echo "Go version from .tool-versions: '${version}'" - echo "version=${version}" >> "$GITHUB_OUTPUT"; - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - # runs 'bundle install' and caches installed gems automatically - bundler-cache: true - env: - # Needed for self-hosted runner - ImageOS: ubuntu22 + make lint-go - name: shellcheck uses: reviewdog/action-shellcheck@v1 @@ -63,53 +47,3 @@ jobs: uses: reviewdog/action-markdownlint@v0 with: reporter: github-pr-review - - - name: lint acceptance - uses: reviewdog/action-golangci-lint@v2 - with: - workdir: src/acceptance - go_version: ${{ steps.get-golang-version.outputs.version }} - golangci_lint_version: ${{ steps.get-golangci-lint-version.outputs.version }} - reporter: github-pr-review - filter_mode: nofilter - fail_on_error: true - - - name: lint go test app - uses: reviewdog/action-golangci-lint@v2 - with: - workdir: src/acceptance/assets/app/go_app - go_version: ${{ steps.get-golang-version.outputs.version }} - golangci_lint_version: ${{ steps.get-golangci-lint-version.outputs.version }} - reporter: github-pr-review - filter_mode: nofilter - fail_on_error: true - - - name: lint autoscaler - uses: reviewdog/action-golangci-lint@v2 - with: - workdir: src/autoscaler - go_version: ${{ steps.get-golang-version.outputs.version }} - golangci_lint_version: ${{ steps.get-golangci-lint-version.outputs.version }} - reporter: github-pr-review - filter_mode: nofilter - fail_on_error: true - - - name: lint changelog - uses: reviewdog/action-golangci-lint@v2 - with: - workdir: src/changelog - go_version: ${{ steps.get-golang-version.outputs.version }} - golangci_lint_version: ${{ steps.get-golangci-lint-version.outputs.version }} - reporter: github-pr-review - filter_mode: nofilter - fail_on_error: true - - - name: lint changeloglockcleaner - uses: reviewdog/action-golangci-lint@v2 - with: - workdir: src/changeloglockcleaner - go_version: ${{ steps.get-golang-version.outputs.version }} - golangci_lint_version: ${{ steps.get-golangci-lint-version.outputs.version }} - reporter: github-pr-review - filter_mode: nofilter - fail_on_error: true diff --git a/Makefile b/Makefile index 7d0ef2115b..e201e023f6 100644 --- a/Makefile +++ b/Makefile @@ -223,27 +223,30 @@ integration: build init-db test-certs @make --directory='./src/autoscaler' integration DBURL="${DBURL}" +.PHONY: lint +lint: lint-go lint-ruby lint-actions lint-markdown + .PHONY:lint $(addprefix lint_,$(go_modules)) -lint: $(addprefix lint_,$(go_modules)) rubocop +lint-go: $(addprefix lint_,$(go_modules)) -rubocop: +lint-ruby: @echo " - ruby scripts" @bundle install @bundle exec rubocop ${RUBOCOP_OPTS} ./spec ./packages -.PHONY: markdownlint -markdownlint: markdownlint-cli +.PHONY: lint-markdown +lint-markdown: @echo " - linting markdown files" - @markdownlint . + @markdownlint-cli2 . .PHONY: lint-actions lint-actions: @echo " - linting GitHub actions" - go run github.com/rhysd/actionlint/cmd/actionlint@latest + actionlint $(addprefix lint_,$(go_modules)): lint_%: @echo " - linting: $(patsubst lint_%,%,$@)" - @pushd src/$(patsubst lint_%,%,$@) >/dev/null && go run github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} run --config ${lint_config} ${OPTS} --timeout 5m + @pushd src/$(patsubst lint_%,%,$@) >/dev/null && golangci-lint run --config ${lint_config} ${OPTS} --timeout 5m .PHONY: spec-test spec-test: @@ -326,10 +329,6 @@ workspace: uaac: which uaac || gem install cf-uaac -.PHONY: markdownlint-cli -markdownlint-cli: - which markdownlint || npm install -g --omit=dev markdownlint-cli - .PHONY: deploy-autoscaler deploy-register-cf deploy-autoscaler-bosh deploy-cleanup deploy-autoscaler: go-mod-vendor uaac db scheduler deploy-autoscaler-bosh deploy-register-cf deploy-register-cf: diff --git a/devbox.json b/devbox.json index 99171eb281..7c55ee7ace 100644 --- a/devbox.json +++ b/devbox.json @@ -5,7 +5,6 @@ "path:.#log-cache-cli-plugin": "", "path:.#cloud-mta-build-tool": "", "path:.#uaac": "", - "act": "0.2.64", "actionlint": "1.7.1", "bosh-cli": "7.3.1", "bundix": "latest", @@ -40,7 +39,9 @@ "credhub-cli": "2.9.29", "google-cloud-sdk": "latest", "temurin-bin-21": "latest", - "ruby": "latest" + "ruby": "latest", + "markdownlint-cli2": "latest", + "act": "0.2.63" }, "shell": { "init_hook": [ diff --git a/devbox.lock b/devbox.lock index 882ca01e24..260d8ea469 100644 --- a/devbox.lock +++ b/devbox.lock @@ -1,51 +1,51 @@ { "lockfile_version": "1", "packages": { - "act@0.2.64": { - "last_modified": "2024-07-31T08:48:38Z", - "resolved": "github:NixOS/nixpkgs/c3392ad349a5227f4a3464dce87bcc5046692fce#act", + "act@0.2.63": { + "last_modified": "2024-06-12T20:55:33Z", + "resolved": "github:NixOS/nixpkgs/a9858885e197f984d92d7fe64e9fff6b2e488d40#act", "source": "devbox-search", - "version": "0.2.64", + "version": "0.2.63", "systems": { "aarch64-darwin": { "outputs": [ { "name": "out", - "path": "/nix/store/wyhhhm5zc4jim1w3j3rv4jb38jr6zdd8-act-0.2.64", + "path": "/nix/store/98mhl0n5ki8xmd5fc3hnwmd7cxz51vcb-act-0.2.63", "default": true } ], - "store_path": "/nix/store/wyhhhm5zc4jim1w3j3rv4jb38jr6zdd8-act-0.2.64" + "store_path": "/nix/store/98mhl0n5ki8xmd5fc3hnwmd7cxz51vcb-act-0.2.63" }, "aarch64-linux": { "outputs": [ { "name": "out", - "path": "/nix/store/pi0l9m8glx5ks77207y9gf91vl5kgf9p-act-0.2.64", + "path": "/nix/store/9lgr8kbjd2hvaxslr51qp1n5qnxp27wl-act-0.2.63", "default": true } ], - "store_path": "/nix/store/pi0l9m8glx5ks77207y9gf91vl5kgf9p-act-0.2.64" + "store_path": "/nix/store/9lgr8kbjd2hvaxslr51qp1n5qnxp27wl-act-0.2.63" }, "x86_64-darwin": { "outputs": [ { "name": "out", - "path": "/nix/store/v36y1fr82wyk7mb295ipc62wr0xpfkjy-act-0.2.64", + "path": "/nix/store/86rnzcmj40xfd9akmfgv3421zpsxfvi6-act-0.2.63", "default": true } ], - "store_path": "/nix/store/v36y1fr82wyk7mb295ipc62wr0xpfkjy-act-0.2.64" + "store_path": "/nix/store/86rnzcmj40xfd9akmfgv3421zpsxfvi6-act-0.2.63" }, "x86_64-linux": { "outputs": [ { "name": "out", - "path": "/nix/store/6964bamczx2ffxh3rswx3yxgyb71b80n-act-0.2.64", + "path": "/nix/store/qjy3wsbk0jwrn6ghmyz2cwk5nf9kaxw5-act-0.2.63", "default": true } ], - "store_path": "/nix/store/6964bamczx2ffxh3rswx3yxgyb71b80n-act-0.2.64" + "store_path": "/nix/store/qjy3wsbk0jwrn6ghmyz2cwk5nf9kaxw5-act-0.2.63" } } }, @@ -1177,6 +1177,54 @@ } } }, + "markdownlint-cli2@latest": { + "last_modified": "2024-08-14T11:41:26Z", + "resolved": "github:NixOS/nixpkgs/0cb2fd7c59fed0cd82ef858cbcbdb552b9a33465#markdownlint-cli2", + "source": "devbox-search", + "version": "0.13.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/j1qj9par93gh0v3l61nwqr1jwkgk6qlw-markdownlint-cli2-0.13.0", + "default": true + } + ], + "store_path": "/nix/store/j1qj9par93gh0v3l61nwqr1jwkgk6qlw-markdownlint-cli2-0.13.0" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/hz82753mm6virrr4adl1f6dwbg0z1qbh-markdownlint-cli2-0.13.0", + "default": true + } + ], + "store_path": "/nix/store/hz82753mm6virrr4adl1f6dwbg0z1qbh-markdownlint-cli2-0.13.0" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/w7qxcwmcaj34x58rda0zjxmblj0h1834-markdownlint-cli2-0.13.0", + "default": true + } + ], + "store_path": "/nix/store/w7qxcwmcaj34x58rda0zjxmblj0h1834-markdownlint-cli2-0.13.0" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/a0znzws3mmpdg2yi9mf375np3g21xrzp-markdownlint-cli2-0.13.0", + "default": true + } + ], + "store_path": "/nix/store/a0znzws3mmpdg2yi9mf375np3g21xrzp-markdownlint-cli2-0.13.0" + } + } + }, "maven@3.8.6": { "last_modified": "2023-06-18T07:20:12Z", "resolved": "github:NixOS/nixpkgs/4d887ae7666a6ffb79e1767d8fd417daf9e4220f#maven", @@ -1666,6 +1714,7 @@ }, "ruby@latest": { "last_modified": "2024-08-14T11:41:26Z", + "plugin_version": "0.0.2", "resolved": "github:NixOS/nixpkgs/0cb2fd7c59fed0cd82ef858cbcbdb552b9a33465#ruby_3_3", "source": "devbox-search", "version": "3.3.4",