Skip to content

Commit

Permalink
chore(linter): Run linters from devbox
Browse files Browse the repository at this point in the history
# Issue

Version skew between GitHub action, `go run` and binary from Nix makes
debugging linter issues impossible.

# Fix

Use Nix binary everywhere.
  • Loading branch information
silvestre committed Aug 30, 2024
1 parent 43cbf41 commit 9f0d6c5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 100 deletions.
84 changes: 9 additions & 75 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
21 changes: 10 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down
73 changes: 61 additions & 12 deletions devbox.lock
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
{
"lockfile_version": "1",
"packages": {
"[email protected].64": {
"last_modified": "2024-07-31T08:48:38Z",
"resolved": "github:NixOS/nixpkgs/c3392ad349a5227f4a3464dce87bcc5046692fce#act",
"[email protected].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"
}
}
},
Expand Down Expand Up @@ -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"
}
}
},
"[email protected]": {
"last_modified": "2023-06-18T07:20:12Z",
"resolved": "github:NixOS/nixpkgs/4d887ae7666a6ffb79e1767d8fd417daf9e4220f#maven",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 9f0d6c5

Please sign in to comment.