From 6dedd55eb38139742ffac62f3323355f1feb5068 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.codeberg.org> Date: Tue, 14 Jun 2022 20:35:11 +0200 Subject: [PATCH] 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 --- .woodpecker.yml | 52 +++++++++++++++++++++++++++++++-------- Justfile | 9 +++++++ integration/main_test.go | 2 +- server/handler.go | 3 ++- server/version/version.go | 3 +++ 5 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 server/version/version.go diff --git a/.woodpecker.yml b/.woodpecker.yml index e7fa66a..081d131 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -9,6 +9,7 @@ pipeline: lint: image: golangci/golangci-lint:latest + group: compliant pull: true commands: - go version @@ -16,22 +17,53 @@ pipeline: - "[ $(gofumpt -extra -l . | wc -l) != 0 ] && { echo 'code not formated'; exit 1; }" - golangci-lint run --timeout 5m --build-tags integration - test: - image: golang:1.18 - commands: - - go test -race codeberg.org/codeberg/pages/server/... - build: - image: golang:1.18 + group: compliant + image: a6543/golang_just 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: - image: golang:1.18 + image: a6543/golang_just + group: test commands: - - go test -race -tags integration codeberg.org/codeberg/pages/integration/... + - just integration environment: - ACME_API=https://acme.mock.directory - PAGES_DOMAIN=localhost.mock.directory - RAW_DOMAIN=raw.localhost.mock.directory - - PORT=4430 \ No newline at end of file + - 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" ] diff --git a/Justfile b/Justfile index 720c0f1..a908e7a 100644 --- a/Justfile +++ b/Justfile @@ -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 @@ -31,5 +34,11 @@ tool-gofumpt: test: go test -race codeberg.org/codeberg/pages/server/... +test-run TEST: + go test -race -run "^{{TEST}}$" codeberg.org/codeberg/pages/server/... + 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/... \ No newline at end of file diff --git a/integration/main_test.go b/integration/main_test.go index 8104413..c8f524f 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -26,7 +26,7 @@ func TestMain(m *testing.M) { log.Printf("=== TestMain: Server STOPED ===\n") }() - time.Sleep(20 * time.Second) + time.Sleep(10 * time.Second) os.Exit(m.Run()) } diff --git a/server/handler.go b/server/handler.go index bda7bd0..3a2667d 100644 --- a/server/handler.go +++ b/server/handler.go @@ -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") diff --git a/server/version/version.go b/server/version/version.go new file mode 100644 index 0000000..aa2cbb5 --- /dev/null +++ b/server/version/version.go @@ -0,0 +1,3 @@ +package version + +var Version string = "dev"