From 014e5332066ec1153f695586a3e1e539963570a6 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sat, 17 Feb 2024 13:08:54 +0100 Subject: [PATCH] [RELEASE] decouple the release name from the version number The release name, as provided by FORGEJO_RELEASE, is used to build OCI images and binary files. Although it can be the same as the Forgejo version, it is not a requirement. When the FORGEJO_RELEASE environment variable is set, use it as a default for naming the binary file instead of FORGEJO_VERSION. For instance, when building from the forgejo branch here is what is desired: FORGEJO_VERSION=7.0.0-g2343 GITEA_VERSION=1.22.0 VERSION=vforgejo-test The name of the release is also displayed with forgejo --version for sanity check purposes. Before: FORGEJO_VERSION is the computed version GITEA_VERSION is set manually VERSION defaults to FORGEJO_VERSION forgejo --help does not display VERSION After: FORGEJO_VERSION is the computed version GITEA_VERSION is set manually RELEASE_VERSION defaults to FORGEJO_VERSION VERSION defaults to RELEASE_VERSION forgejo --help displays VERSION --- .forgejo/workflows/build-release.yml | 2 +- Dockerfile | 4 ++-- Dockerfile.rootless | 4 ++-- Makefile | 5 +++-- main.go | 11 ++++++++++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.forgejo/workflows/build-release.yml b/.forgejo/workflows/build-release.yml index ddf5dfdebf..b2f3757980 100644 --- a/.forgejo/workflows/build-release.yml +++ b/.forgejo/workflows/build-release.yml @@ -190,4 +190,4 @@ jobs: destination-token: ${{ secrets.CASCADE_DESTINATION_TOKEN }} update: .forgejo/cascading-release-end-to-end env: - FORGEJO_BINARY: "${{ env.GITHUB_SERVER_URL }}/${{ github.repository }}/releases/download/v${{ steps.tag-version.outputs.value }}/forgejo-${{ steps.tag-version.outputs.value }}-linux-amd64" + FORGEJO_BINARY: "${{ env.GITHUB_SERVER_URL }}/${{ github.repository }}/releases/download/v${{ steps.release-info.outputs.version }}/forgejo-${{ steps.release-info.outputs.version }}-linux-amd64" diff --git a/Dockerfile b/Dockerfile index 98d1d707b5..81a34d5d23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.21-alpine3.19 as build ARG GOPROXY ENV GOPROXY ${GOPROXY:-direct} -ARG GITEA_VERSION +ARG RELEASE_VERSION ARG TAGS="sqlite sqlite_unlock_notify" ENV TAGS "bindata timetzdata $TAGS" ARG CGO_EXTRA_CFLAGS @@ -36,7 +36,7 @@ WORKDIR ${GOPATH}/src/code.gitea.io/gitea RUN make clean-all RUN make frontend RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini -RUN make go-check generate-backend static-executable && xx-verify gitea +RUN make RELEASE_VERSION=$RELEASE_VERSION go-check generate-backend static-executable && xx-verify gitea # Copy local files COPY docker/root /tmp/local diff --git a/Dockerfile.rootless b/Dockerfile.rootless index 0c09df61a9..83b19f4dcc 100644 --- a/Dockerfile.rootless +++ b/Dockerfile.rootless @@ -5,7 +5,7 @@ FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.21-alpine3.19 as build ARG GOPROXY ENV GOPROXY ${GOPROXY:-direct} -ARG GITEA_VERSION +ARG RELEASE_VERSION ARG TAGS="sqlite sqlite_unlock_notify" ENV TAGS "bindata timetzdata $TAGS" ARG CGO_EXTRA_CFLAGS @@ -36,7 +36,7 @@ WORKDIR ${GOPATH}/src/code.gitea.io/gitea RUN make clean-all RUN make frontend RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini -RUN make go-check generate-backend static-executable && xx-verify gitea +RUN make RELEASE_VERSION=$RELEASE_VERSION go-check generate-backend static-executable && xx-verify gitea # Copy local files COPY docker/rootless /tmp/local diff --git a/Makefile b/Makefile index 5b1ea0da40..6d75494390 100644 --- a/Makefile +++ b/Makefile @@ -92,11 +92,12 @@ ifneq ($(STORED_VERSION),) else FORGEJO_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//') endif -VERSION ?= ${FORGEJO_VERSION} +RELEASE_VERSION ?= ${FORGEJO_VERSION} +VERSION ?= ${RELEASE_VERSION} GITEA_VERSION ?= 1.22.0 -LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)" -X "main.ForgejoVersion=$(FORGEJO_VERSION)" +LDFLAGS := $(LDFLAGS) -X "main.ReleaseVersion=$(RELEASE_VERSION)" -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)" -X "main.ForgejoVersion=$(FORGEJO_VERSION)" LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64 diff --git a/main.go b/main.go index 56f97caf27..b8cc5668e1 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,8 @@ var ( Version = "development" // program version for this build Tags = "" // the Golang build tags MakeVersion = "" // "make" program version if built with make + + ReleaseVersion = "" ) var ForgejoVersion = "1.0.0" @@ -54,11 +56,18 @@ func main() { log.GetManager().Close() os.Exit(code) } - app := cmd.NewMainApp(Version, formatBuiltWith()) + app := cmd.NewMainApp(Version, formatReleaseVersion()+formatBuiltWith()) _ = cmd.RunMainApp(app, os.Args...) // all errors should have been handled by the RunMainApp log.GetManager().Close() } +func formatReleaseVersion() string { + if len(ReleaseVersion) > 0 { + return " (release name " + ReleaseVersion + ")" + } + return "" +} + func formatBuiltWith() string { version := runtime.Version() if len(MakeVersion) > 0 {