Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .pre-commit-config.yaml
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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-yaml aren'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.

I am unable to reproduce the goimports changes btw

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bumping this

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$
2 changes: 1 addition & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ server {
proxy_set_header X-Real-IP $remote_addr;
}
# Automatically managed certbot stuff goes here
}
}
```

See [`USAGE.md`](https://github.com/5HT2B/heartbeat/blob/master/USAGE.md) for instructions to run the server, which you would be putting
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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:

  1. grab staged files w/ git diff --cached --name-only
  2. filter by extension (.go, .md, whatever)
  3. run your tools on those files as per the config file
  4. exit 1 if any fail

the tricky bit pre-commit handles is the stash dance - it stashes unstaged changes so you're ONLY checking what's actually being committed:

2 changes: 1 addition & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This requires `docker-compose` (1.29.2 or newer), `docker` and `git`.
git clone git@github.com:5HT2B/heartbeat.git
cd heartbeat
echo "HB_TOKEN=authenticationTokenMakeThisSecure" >> config/.env
# Add --build to build from your local files instead of using the pre-built image
# Add --build to build from your local files instead of using the pre-built image
docker-compose up
```

Expand Down
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"github.com/ferluci/fast-realip"
realip "github.com/ferluci/fast-realip"
"github.com/valyala/fasthttp"
)

Expand Down
2 changes: 1 addition & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"log"
"time"

"github.com/redis/go-redis/v9"
"github.com/nitishm/go-rejson/v4"
"github.com/redis/go-redis/v9"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"

"github.com/5HT2B/heartbeat/templates"
"github.com/ferluci/fast-realip"
realip "github.com/ferluci/fast-realip"
"github.com/valyala/fasthttp"
)

Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there breaking changes from v8 to v9 / have you tested the following steps basically

  1. running an existing build
  2. upgrading
  3. rebuilding
  4. running new redis client version

I can do it for you if not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested my deployment and lgtm

Copy link
Member Author

Choose a reason for hiding this comment

The 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"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I do actually need to test this on my end.
How does yours connect to DB?

github.com/valyala/fasthttp v1.55.0
github.com/valyala/quicktemplate v1.8.0
golang.org/x/text v0.16.0
Expand All @@ -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
)
176 changes: 2 additions & 174 deletions go.sum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait why are we deleting old version hashes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhh bumping this

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion www/style.large.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
display: flex;
justify-content: center;
}
}
}