name: Run Tests on Push and Pull Request on: push: branches: - master pull_request: jobs: run-tests: runs-on: java26 steps: - name: Checkout Code run: | SERVER_DOMAIN=$(echo "${{ github.server_url }}" | sed 's/https:\/\///') rm -rf "$GITHUB_WORKSPACE"/* git clone "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@${SERVER_DOMAIN}/${{ github.repository }}.git" "$GITHUB_WORKSPACE" cd "$GITHUB_WORKSPACE" git checkout ${{ github.sha }} - name: Make gradlew executable run: | cd "$GITHUB_WORKSPACE" chmod +x ./gradlew - name: Run JUnit tests id: run_tests run: | cd "$GITHUB_WORKSPACE" ./gradlew test --no-daemon --stacktrace - name: Package and upload test reports if: always() run: | cd "$GITHUB_WORKSPACE" if [ ! -d "build/reports/tests/test" ] && [ ! -d "build/test-results/test" ]; then echo "No test reports produced, skipping upload." exit 0 fi 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