From ebf23cfe36d14e8a14988b6cf4ac84074555ff59 Mon Sep 17 00:00:00 2001 From: Odyssey Date: Sat, 17 Dec 2022 20:09:19 +0100 Subject: [PATCH] It's not necessary to build commit info to ldflags now. Signed-off-by: Odyssey --- Dockerfile | 2 +- pages/index.go | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) 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{