Release via CI (#94)

* release via CI
* general CI improvements

close #76, close #92

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/94
This commit is contained in:
6543 2022-06-14 20:35:11 +02:00
parent 4c6164ef05
commit 6dedd55eb3
5 changed files with 57 additions and 12 deletions

View file

@ -9,6 +9,7 @@ pipeline:
lint: lint:
image: golangci/golangci-lint:latest image: golangci/golangci-lint:latest
group: compliant
pull: true pull: true
commands: commands:
- go version - go version
@ -16,22 +17,53 @@ pipeline:
- "[ $(gofumpt -extra -l . | wc -l) != 0 ] && { echo 'code not formated'; exit 1; }" - "[ $(gofumpt -extra -l . | wc -l) != 0 ] && { echo 'code not formated'; exit 1; }"
- golangci-lint run --timeout 5m --build-tags integration - golangci-lint run --timeout 5m --build-tags integration
test:
image: golang:1.18
commands:
- go test -race codeberg.org/codeberg/pages/server/...
build: build:
image: golang:1.18 group: compliant
image: a6543/golang_just
commands: commands:
- go build - go version
- just build
when:
event: [ "pull_request", "push" ]
build-tag:
group: compliant
image: a6543/golang_just
commands:
- go version
- just build-tag ${CI_COMMIT_TAG##v}
when:
event: [ "tag" ]
test:
image: a6543/golang_just
group: test
commands:
- just test
integration-tests: integration-tests:
image: golang:1.18 image: a6543/golang_just
group: test
commands: commands:
- go test -race -tags integration codeberg.org/codeberg/pages/integration/... - just integration
environment: environment:
- ACME_API=https://acme.mock.directory - ACME_API=https://acme.mock.directory
- PAGES_DOMAIN=localhost.mock.directory - PAGES_DOMAIN=localhost.mock.directory
- RAW_DOMAIN=raw.localhost.mock.directory - RAW_DOMAIN=raw.localhost.mock.directory
- PORT=4430 - PORT=4430
release:
image: plugins/gitea-release
settings:
base_url: https://codeberg.org
file_exists: overwrite
files: build/codeberg-pages-server
api_key:
from_secret: bot_token
environment:
- DRONE_REPO_OWNER=${CI_REPO_OWNER}
- DRONE_REPO_NAME=${CI_REPO_NAME}
- DRONE_BUILD_EVENT=${CI_BUILD_EVENT}
- DRONE_COMMIT_REF=${CI_COMMIT_REF}
when:
event: [ "tag" ]

View file

@ -11,6 +11,9 @@ dev:
build: build:
CGO_ENABLED=0 go build -ldflags '-s -w' -v -o build/codeberg-pages-server ./ 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 lint: tool-golangci tool-gofumpt
[ $(gofumpt -extra -l . | wc -l) != 0 ] && { echo 'code not formated'; exit 1; }; \ [ $(gofumpt -extra -l . | wc -l) != 0 ] && { echo 'code not formated'; exit 1; }; \
golangci-lint run --timeout 5m --build-tags integration golangci-lint run --timeout 5m --build-tags integration
@ -31,5 +34,11 @@ tool-gofumpt:
test: test:
go test -race codeberg.org/codeberg/pages/server/... go test -race codeberg.org/codeberg/pages/server/...
test-run TEST:
go test -race -run "^{{TEST}}$" codeberg.org/codeberg/pages/server/...
integration: integration:
go test -race -tags integration codeberg.org/codeberg/pages/integration/... go test -race -tags integration codeberg.org/codeberg/pages/integration/...
integration-run TEST:
go test -race -tags integration -run "^{{TEST}}$" codeberg.org/codeberg/pages/integration/...

View file

@ -26,7 +26,7 @@ func TestMain(m *testing.M) {
log.Printf("=== TestMain: Server STOPED ===\n") log.Printf("=== TestMain: Server STOPED ===\n")
}() }()
time.Sleep(20 * time.Second) time.Sleep(10 * time.Second)
os.Exit(m.Run()) os.Exit(m.Run())
} }

View file

@ -14,6 +14,7 @@ import (
"codeberg.org/codeberg/pages/server/gitea" "codeberg.org/codeberg/pages/server/gitea"
"codeberg.org/codeberg/pages/server/upstream" "codeberg.org/codeberg/pages/server/upstream"
"codeberg.org/codeberg/pages/server/utils" "codeberg.org/codeberg/pages/server/utils"
"codeberg.org/codeberg/pages/server/version"
) )
// Handler handles a single HTTP request to the web server. // Handler handles a single HTTP request to the web server.
@ -26,7 +27,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
return func(ctx *fasthttp.RequestCtx) { return func(ctx *fasthttp.RequestCtx) {
log := log.With().Str("Handler", string(ctx.Request.Header.RequestURI())).Logger() 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 // 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") ctx.Response.Header.Set("Referrer-Policy", "strict-origin-when-cross-origin")

View file

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