From 5e62c219d31ca129da70b0ea6fde1985993ea7eb Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 29 Jan 2025 08:36:24 +0100 Subject: [PATCH] feat(build): add RELEASE_VERSION argument to be able to pass release version via env --- .github/workflows/release-docker.yml | 19 +++++++------ Dockerfile | 3 +- magefile.go | 42 +++++++++++++++++++--------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index a693560c8..e9c5a5013 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -9,23 +9,24 @@ jobs: docker: runs-on: ubuntu-latest steps: - - - name: Login to GHCR + - name: Git describe + id: ghd + uses: proudust/gh-describe@v2 + - name: Login to GHCR uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up QEMU + - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Build and push + - name: Build and push uses: docker/build-push-action@v6 with: platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 push: true - tags: ghcr.io/go-vikunja/vikunja:unstable \ No newline at end of file + tags: ghcr.io/go-vikunja/vikunja:unstable + build-args: | + RELEASE_VERSION:${{ steps.ghd.outputs.describe }} diff --git a/Dockerfile b/Dockerfile index 3a84a6e62..625cc671f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,8 @@ WORKDIR /go/src/code.vikunja.io/api COPY . ./ COPY --from=frontendbuilder /build/dist ./frontend/dist -ARG TARGETOS TARGETARCH TARGETVARIANT +ARG TARGETOS TARGETARCH TARGETVARIANT RELEASE_VERSION +ENV RELEASE_VERSION=$RELEASE_VERSION ENV GOPROXY=https://goproxy.kolaente.de RUN export PATH=$PATH:$GOPATH/bin && \ diff --git a/magefile.go b/magefile.go index 2720ac439..cdd60fa82 100644 --- a/magefile.go +++ b/magefile.go @@ -37,7 +37,6 @@ import ( "time" "github.com/iancoleman/strcase" - "github.com/magefile/mage/mg" "golang.org/x/sync/errgroup" ) @@ -92,24 +91,41 @@ func runCmdWithOutput(name string, arg ...string) (output []byte, err error) { return output, nil } +func getRawVersionString() (version string, err error) { + versionEnv := os.Getenv("RELEASE_VERSION") + if versionEnv != "" { + return versionEnv, nil + } + + if os.Getenv("DRONE_TAG") != "" { + return os.Getenv("DRONE_TAG"), nil + } + + if os.Getenv("DRONE_BRANCH") != "" { + version = strings.Replace(os.Getenv("DRONE_BRANCH"), "release/v", "", 1) + } + + if version == "main" { + version = "unstable" + } + + if version != "" { + return + } + + versionBytes, err := runCmdWithOutput("git", "describe", "--tags", "--always", "--abbrev=10") + return string(versionBytes), err +} + func setVersion() { - version, err := runCmdWithOutput("git", "describe", "--tags", "--always", "--abbrev=10") + version, err := getRawVersionString() if err != nil { fmt.Printf("Error getting version: %s\n", err) os.Exit(1) } - VersionNumber = strings.Trim(string(version), "\n") + VersionNumber = strings.Trim(version, "\n") VersionNumber = strings.Replace(VersionNumber, "-g", "-", 1) - - if os.Getenv("DRONE_TAG") != "" { - Version = os.Getenv("DRONE_TAG") - } else if os.Getenv("DRONE_BRANCH") != "" { - Version = strings.Replace(os.Getenv("DRONE_BRANCH"), "release/v", "", 1) - } - - if Version == "main" { - Version = "unstable" - } + Version = version } func setBinLocation() {