From 0d8ee099a0f75b462f847bdf35feeb4f83d05692 Mon Sep 17 00:00:00 2001 From: CodingPhoenixx Date: Thu, 28 May 2026 13:56:52 +0200 Subject: [PATCH] Streamline test report packaging and uploading in test.yml: archive reports, handle missing directories, and upload to Gitea packages. --- .gitea/workflows/test.yml | 57 ++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index c09cb64..33ba161 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -30,15 +30,58 @@ jobs: cd "$GITHUB_WORKSPACE" ./gradlew test --no-daemon --stacktrace - - name: Upload test reports + - name: Package and upload test reports if: always() run: | cd "$GITHUB_WORKSPACE" - if [ -d "build/reports/tests/test" ]; then - echo "Test reports available in build/reports/tests/test" - ls -la build/reports/tests/test || true + + if [ ! -d "build/reports/tests/test" ] && [ ! -d "build/test-results/test" ]; then + echo "No test reports produced, skipping upload." + exit 0 fi - if [ -d "build/test-results/test" ]; then - echo "Test result XMLs:" - ls -la build/test-results/test || true + + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) + ARCHIVE="test-reports-${SHORT_SHA}.tar.gz" + + tar -czf "$ARCHIVE" \ + $( [ -d build/reports/tests/test ] && echo build/reports/tests/test ) \ + $( [ -d build/test-results/test ] && echo build/test-results/test ) + + echo "Archive size: $(du -h "$ARCHIVE" | cut -f1)" + + SERVER_URL="${{ github.server_url }}" + OWNER="${{ github.repository_owner }}" + PKG_NAME="nexusweb-test-reports" + VERSION="run-${{ github.run_number }}-${SHORT_SHA}" + + UPLOAD_URL="${SERVER_URL}/api/packages/${OWNER}/generic/${PKG_NAME}/${VERSION}/${ARCHIVE}" + echo "Uploading to: ${UPLOAD_URL}" + + # Delete any previous package with the same version (e.g. job re-run on same commit), + # ignore failures (404 if it does not exist yet). + curl -s -o /dev/null -w "Delete previous (if any): HTTP %{http_code}\n" \ + -X DELETE \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "${UPLOAD_URL}" || true + + HTTP_STATUS=$(curl -s -o /tmp/upload-response.txt -w "%{http_code}" \ + -X PUT \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + --data-binary @"${ARCHIVE}" \ + "${UPLOAD_URL}") + + if [ "$HTTP_STATUS" = "201" ] || [ "$HTTP_STATUS" = "200" ] || [ "$HTTP_STATUS" = "204" ]; then + echo "Upload successful (HTTP ${HTTP_STATUS})" + echo "" + echo "Test reports available at:" + echo " ${SERVER_URL}/${OWNER}/-/packages/generic/${PKG_NAME}/${VERSION}" + echo "" + echo "Or via API:" + echo " ${UPLOAD_URL}" + else + echo "Upload failed (HTTP ${HTTP_STATUS})" + cat /tmp/upload-response.txt || true + echo "" + echo "Test reports still present locally in build/reports/tests/test/index.html" + # Do not fail the workflow over the report upload. fi