-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: pre commit hooks for linting #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| repos: | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v5.0.0 | ||
| hooks: | ||
| - id: end-of-file-fixer | ||
| exclude: ^templates/.*\.qtpl\.go$ | ||
| - id: trailing-whitespace | ||
| exclude: ^templates/.*\.qtpl\.go$ | ||
| - id: check-added-large-files | ||
| - id: check-merge-conflict | ||
| - id: detect-private-key | ||
| - id: check-json | ||
| files: \.(json)$ | ||
| - id: check-yaml | ||
| files: \.(yaml|yml)$ | ||
| - id: mixed-line-ending | ||
| args: [--fix=lf] | ||
| - repo: local | ||
| hooks: | ||
| - id: go-fmt | ||
| name: go fmt | ||
| entry: gofmt -l -w . | ||
| language: system | ||
| types: [go] | ||
| exclude: ^templates/.*\.qtpl\.go$ | ||
| - id: go-imports | ||
| name: go imports | ||
| entry: bash -c 'if command -v goimports >/dev/null 2>&1; then goimports -l -w .; else echo "goimports not found, skipping import formatting"; fi' | ||
| language: system | ||
| types: [go] | ||
| exclude: ^templates/.*\.qtpl\.go$ | ||
| pass_filenames: false | ||
| - id: go-vet | ||
| name: go vet | ||
| entry: go vet ./... | ||
| language: system | ||
| types: [go] | ||
| pass_filenames: false | ||
| - id: go-test | ||
| name: go test | ||
| entry: go test ./... | ||
| language: system | ||
| types: [go] | ||
| pass_filenames: false | ||
| - id: go-mod-tidy | ||
| name: go mod tidy | ||
| entry: go mod tidy | ||
| language: system | ||
| files: go\.(mod|sum)$ | ||
| pass_filenames: false | ||
| - repo: https://github.com/igorshubovych/markdownlint-cli | ||
| rev: v0.45.0 | ||
| hooks: | ||
| - id: markdownlint | ||
| args: [--disable, MD013, MD002, MD041] | ||
| files: \.md$ | ||
| - repo: https://github.com/jumanjihouse/pre-commit-hooks | ||
| rev: 3.0.0 | ||
| hooks: | ||
| - id: shellcheck | ||
| files: \.sh$ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,12 @@ docker-build: | |
|
|
||
| docker-push: | ||
| @docker push ${NAME} | ||
|
|
||
| lint: | ||
| @echo "Running pre-commit hooks..." | ||
| @if command -v pre-commit >/dev/null 2>&1; then \ | ||
| pre-commit run --all-files; \ | ||
| else \ | ||
| echo "pre-commit not found. Install with: pip install pre-commit"; \ | ||
| exit 1; \ | ||
| fi | ||
|
Comment on lines
+35
to
+42
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not want Python dependencies, can we convert whatever the pre-commit hook is supposed to be doing into a POSIX SH / Bash script? I can write it, just let me know what it should be doing if not obvious.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah totally doable tbh. pre-commit basically just runs linters/formatters on staged files before commit. the main sauce is:
the tricky bit pre-commit handles is the stash dance - it stashes unstaged changes so you're ONLY checking what's actually being committed: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,9 @@ go 1.20 | |
|
|
||
| require ( | ||
| github.com/ferluci/fast-realip v1.0.1 | ||
| github.com/go-redis/redis/v8 v8.11.5 | ||
| github.com/joho/godotenv v1.5.1 | ||
| github.com/nitishm/go-rejson/v4 v4.2.0 | ||
| github.com/redis/go-redis/v9 v9.6.0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there breaking changes from
I can do it for you if not
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tested my deployment and lgtm
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I did however write my own containerfile using vendor deps instead of make deps) FROM golang:1.23-alpine AS builder
RUN mkdir -p /heartbeat/config
ADD . /heartbeat
WORKDIR /heartbeat
# Install make, git and other build dependencies
RUN apk add --no-cache make git
ENV PATH "${PATH}:${GOPATH}/bin"
RUN go mod tidy
RUN go mod download
RUN go build -ldflags "-X main.gitCommitHash=6034c5f" -o heartbeat .
FROM alpine:3.18
RUN apk add --no-cache ca-certificates
WORKDIR /app
# Copy the binary, config directory, and www assets
COPY --from=builder /heartbeat/heartbeat /app/heartbeat
COPY --from=builder /heartbeat/config /app/config
COPY --from=builder /heartbeat/www /app/www
EXPOSE 8080
CMD ["/app/heartbeat"]
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I do actually need to test this on my end. |
||
| github.com/valyala/fasthttp v1.55.0 | ||
| github.com/valyala/quicktemplate v1.8.0 | ||
| golang.org/x/text v0.16.0 | ||
|
|
@@ -18,8 +18,5 @@ require ( | |
| github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | ||
| github.com/gomodule/redigo v1.8.8 // indirect | ||
| github.com/klauspost/compress v1.17.9 // indirect | ||
| github.com/redis/go-redis/v9 v9.6.0 // indirect | ||
| github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
| golang.org/x/net v0.26.0 // indirect | ||
| golang.org/x/sys v0.21.0 // indirect | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait why are we deleting old version hashes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uhh bumping this |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,4 +30,4 @@ | |
| display: flex; | ||
| justify-content: center; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have this as a post-commit hook or a CI lint instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like having the option to lint code myself before committing, and then ci only does a simple pass/fail but doesn't actively lint itself. does this make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these seem kind of excessive like...
detect-private-key?Is this relevant to heartbeat or is that generic "oops the user committed a private key"?
And
check-json+check-yamlaren't applicable as we don't have either of those.Mixed LF is not strictly enforced but is going to be immediately noticable before committing (i.e., your diff is garbled).
Could we please cut this down to just the Go projects? Related, I haven't had formatter errors with qtpl templates I think we can just fmt them too.
goimportschanges btwThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumping this