From 2762dd95979a776c164db60ab604828e10cd09cc Mon Sep 17 00:00:00 2001
From: Earl Warren <contact@earl-warren.org>
Date: Fri, 23 Feb 2024 14:01:02 +0100
Subject: [PATCH] [CI] name the test release after the latest v*-dev tag

Also ignore the *-test tags when figuring out the Forgejo version,
they exist in the integration repository and experimental repository
for daily releases.
---
 .forgejo/workflows/build-release-integration.yml | 2 +-
 .forgejo/workflows/build-release.yml             | 4 ++--
 Makefile                                         | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/.forgejo/workflows/build-release-integration.yml b/.forgejo/workflows/build-release-integration.yml
index ab2f2ebc1..e066f0af5 100644
--- a/.forgejo/workflows/build-release-integration.yml
+++ b/.forgejo/workflows/build-release-integration.yml
@@ -110,7 +110,7 @@ jobs:
           #
           # Push a commit to a branch that triggers the build of a test release
           #
-          version=0.0-test
+          version=1.2-test
           (
             git clone $url/root/forgejo /tmp/forgejo
             cd /tmp/forgejo
diff --git a/.forgejo/workflows/build-release.yml b/.forgejo/workflows/build-release.yml
index e619c4dd2..c012991b3 100644
--- a/.forgejo/workflows/build-release.yml
+++ b/.forgejo/workflows/build-release.yml
@@ -54,7 +54,7 @@ jobs:
           ref="${{ github.ref }}"
           if [[ $ref =~ ^refs/heads/ ]] ; then
             if test "$ref" = "refs/heads/forgejo" ; then
-              version=0.0-test
+              version=$(git tag -l --sort=version:refname --merged | grep -v -e '-test$' | tail -1 | sed -E -e 's/^(v[0-9]+\.[0-9]+).*/\1/')-test
             else
               version=${ref#refs/heads/}
               version=${version%/forgejo}-test
@@ -70,7 +70,7 @@ jobs:
             exit 1
           fi
           version=${version#v}
-          git describe --tags --always
+          git describe --exclude '*-test' --tags --always
           echo "sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
           echo "version=$version" >> "$GITHUB_OUTPUT"
           echo "override=$override" >> "$GITHUB_OUTPUT"
diff --git a/Makefile b/Makefile
index e12660e4a..194da59ef 100644
--- a/Makefile
+++ b/Makefile
@@ -90,7 +90,7 @@ STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
 ifneq ($(STORED_VERSION),)
   FORGEJO_VERSION ?= $(STORED_VERSION)
 else
-  FORGEJO_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
+  FORGEJO_VERSION ?= $(shell git describe --exclude '*-test' --tags --always | sed 's/-/+/' | sed 's/^v//')
 endif
 RELEASE_VERSION ?= ${FORGEJO_VERSION}
 VERSION ?= ${RELEASE_VERSION}