diff --git a/Dockerfile b/Dockerfile index 9df86ed..841f7b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN apk --no-cache add git RUN git clone https://codeberg.org/gothub/gothub . RUN go mod download -RUN GOOS=linux GOARCH=$TARGETARCH go build -ldflags "-X codeberg.org/gothub/gothub/pages.Version=$(git rev-parse --short HEAD)" -o /src/gothub +RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub FROM scratch as bin diff --git a/pages/index.go b/pages/index.go index df0bc08..2a04102 100644 --- a/pages/index.go +++ b/pages/index.go @@ -1,8 +1,22 @@ package pages -import "github.com/gofiber/fiber/v2" +import ( + "runtime/debug" -var Version = "unknown" + "github.com/gofiber/fiber/v2" +) + +// taken from https://git.vern.cc/pjals/bestofbot. +var Version = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value[:8] + } + } + } + return "AGPLVIOLATION" +}() func HandleIndex(c *fiber.Ctx) error { return c.Render("index", fiber.Map{