From 069735deb12529c8cfb4ad0fdccfe949eba25504 Mon Sep 17 00:00:00 2001
From: Earl Warren <contact@earl-warren.org>
Date: Sat, 2 Sep 2023 07:42:49 +0200
Subject: [PATCH 1/3] upgrade tests to 1.20

---
 .forgejo/workflows/integration.yml                     | 10 +++++-----
 .../nested-upload-download/.forgejo/workflows/test.yml |  7 ++++++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml
index 54b2ce8..ab0e4c7 100644
--- a/.forgejo/workflows/integration.yml
+++ b/.forgejo/workflows/integration.yml
@@ -10,23 +10,23 @@ jobs:
         with:
           user: testuser
           password: admin1234
-          image-version: 1.19
+          image-version: 1.20
 
-      - name: Make the forgejo-release action available for testing
+      - name: push self
         run: |
           forgejo-test-helper.sh push_self_action http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser forgejo-release vTest
 
-      - name: Actions tests from testdata/upload-download/.forgejo/workflows
+      - name: testdata/upload-download
         run: |
           export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
           forgejo-test-helper.sh run_workflow testdata/upload-download http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser upload-download forgejo-release "${{ steps.forgejo.outputs.token }}"
 
-      - name: Actions tests from testdata/nested-upload-download/.forgejo/workflows
+      - name: testdata/nested-upload-download
         run: |
           export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
           forgejo-test-helper.sh run_workflow testdata/nested-upload-download http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser nested-upload-download forgejo-release "${{ steps.forgejo.outputs.token }}"
 
-      - name: Integration tests of the supporting script forgejo-release.sh
+      - name: test forgejo-release.sh
         run: |
           set -ex
           export FORGEJO="${{ steps.forgejo.outputs.url }}"
diff --git a/testdata/nested-upload-download/.forgejo/workflows/test.yml b/testdata/nested-upload-download/.forgejo/workflows/test.yml
index 44b1107..bef2bd4 100644
--- a/testdata/nested-upload-download/.forgejo/workflows/test.yml
+++ b/testdata/nested-upload-download/.forgejo/workflows/test.yml
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: MIT
 
-name: Upload (and download) a release to (and from) a project found in a Forgejo instance that is different from the one running the workflow
+#
+# Upload (and download) a release to (and from) a project
+# found in a Forgejo instance that is different from the one running the workflow
+#
+name: two Forgejo
 on: [push]
 jobs:
   setup-forgejo:
@@ -13,6 +17,7 @@ jobs:
           user: testuser
           password: admin1234
           lxc-ip-prefix: 10.0.15
+          image-version: 1.20
       - id: testrepo
         run: |
           forgejo-test-helper.sh push testrepo http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser testrepo > /tmp/output

From 2d51a3fa48961f4db00367cf60f0aba2f4f0de51 Mon Sep 17 00:00:00 2001
From: Earl Warren <contact@earl-warren.org>
Date: Sat, 2 Sep 2023 08:57:24 +0200
Subject: [PATCH 2/3] workaround race condition in v1.20

Refs: https://codeberg.org/forgejo/forgejo/issues/1370
---
 forgejo-release.sh | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/forgejo-release.sh b/forgejo-release.sh
index 437e605..54736c7 100755
--- a/forgejo-release.sh
+++ b/forgejo-release.sh
@@ -44,7 +44,16 @@ upload_release() {
     test ${releasetype+false} || echo "Uploading as Stable"
     ensure_tag
     anchor=$(echo $TAG | sed -e 's/^v//' -e 's/[^a-zA-Z0-9]/-/g')
-    $BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title $TAG --draft ${releasetype}
+    if ! $BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title $TAG --draft ${releasetype} >& $TMP_DIR/tea.log ; then
+	if grep --quiet 'Unknown API Error: 500' $TMP_DIR/tea.log && grep --quiet services/release/release.go:194 $TMP_DIR/tea.log ; then
+	    echo "workaround v1.20 race condition https://codeberg.org/forgejo/forgejo/issues/1370"
+	    sleep 10
+	    $BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title $TAG --draft ${releasetype}
+	else
+	    cat $TMP_DIR/tea.log
+	    return 1
+	fi
+    fi
     release_draft false
 }
 

From 837e49d43231122dbfcd9d1a5fa0279c248b40b7 Mon Sep 17 00:00:00 2001
From: Earl Warren <contact@earl-warren.org>
Date: Sat, 2 Sep 2023 10:48:52 +0200
Subject: [PATCH 3/3] show forgejo logs on failure()

---
 .forgejo/workflows/integration.yml                          | 3 +++
 testdata/nested-upload-download/.forgejo/workflows/test.yml | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml
index ab0e4c7..e5863c0 100644
--- a/.forgejo/workflows/integration.yml
+++ b/.forgejo/workflows/integration.yml
@@ -33,3 +33,6 @@ jobs:
           export TOKEN="${{ steps.forgejo.outputs.token }}"
           export VERBOSE=true
           testdata/forgejo-release-test.sh test_run testuser otherrepo
+
+      - if: failure()
+        run: docker logs forgejo
diff --git a/testdata/nested-upload-download/.forgejo/workflows/test.yml b/testdata/nested-upload-download/.forgejo/workflows/test.yml
index bef2bd4..cd43827 100644
--- a/testdata/nested-upload-download/.forgejo/workflows/test.yml
+++ b/testdata/nested-upload-download/.forgejo/workflows/test.yml
@@ -46,3 +46,5 @@ jobs:
           verbose: true
       - run: |
           diff -u upload-dir download-dir
+      - if: failure()
+        run: docker logs forgejo