add var to store version tag & adjust Justfile

This commit is contained in:
6543 2022-06-14 19:29:09 +02:00
parent a92088f8e8
commit 79c836ffe5
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
4 changed files with 9 additions and 2 deletions

View file

@ -22,7 +22,7 @@ pipeline:
image: a6543/golang_just
commands:
- go version
- just build
- just build-tag ${CI_COMMIT_TAG##v}
test:
image: a6543/golang_just

View file

@ -11,6 +11,9 @@ dev:
build:
CGO_ENABLED=0 go build -ldflags '-s -w' -v -o build/codeberg-pages-server ./
build-tag VERSION:
CGO_ENABLED=0 go build -ldflags '-s -w -X "codeberg.org/codeberg/pages/server/version.Version={{VERSION}}"' -v -o build/codeberg-pages-server ./
lint: tool-golangci tool-gofumpt
[ $(gofumpt -extra -l . | wc -l) != 0 ] && { echo 'code not formated'; exit 1; }; \
golangci-lint run --timeout 5m --build-tags integration

View file

@ -14,6 +14,7 @@ import (
"codeberg.org/codeberg/pages/server/gitea"
"codeberg.org/codeberg/pages/server/upstream"
"codeberg.org/codeberg/pages/server/utils"
"codeberg.org/codeberg/pages/server/version"
)
// Handler handles a single HTTP request to the web server.
@ -26,7 +27,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
return func(ctx *fasthttp.RequestCtx) {
log := log.With().Str("Handler", string(ctx.Request.Header.RequestURI())).Logger()
ctx.Response.Header.Set("Server", "Codeberg Pages")
ctx.Response.Header.Set("Server", "CodebergPages/"+version.Version)
// Force new default from specification (since November 2020) - see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy#strict-origin-when-cross-origin
ctx.Response.Header.Set("Referrer-Policy", "strict-origin-when-cross-origin")

View file

@ -0,0 +1,3 @@
package version
var Version string = "dev"