diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 217b51eb4..a5e140265 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -31,6 +31,7 @@ jobs: echo "Your code coverage test passed! Coverage precentage is: $CODE_COV" exit 0 fi + integration-tests: runs-on: ubuntu-latest steps: @@ -50,6 +51,7 @@ jobs: pip install pre-commit pre-commit install - name: Go Integration test + id: integration_test shell: bash env: CX_BASE_URI: ${{ secrets.CX_BASE_URI }} @@ -99,6 +101,91 @@ jobs: ./internal/commands/.scripts/integration_up.sh ./internal/commands/.scripts/integration_down.sh + - name: Extract failed tests + id: failed_tests + if: always() + shell: bash + run: | + if [ -f "failed_tests_summary.txt" ] && [ -s "failed_tests_summary.txt" ]; then + echo "has_failures=true" >> $GITHUB_OUTPUT + FAIL_COUNT=$(wc -l < failed_tests_summary.txt | tr -d ' ') + echo "fail_count=$FAIL_COUNT" >> $GITHUB_OUTPUT + # Format failed tests as bullet points for Teams + FAILED_LIST=$(awk '{print "• " $0}' failed_tests_summary.txt | tr '\n' ',' | sed 's/,$//' | sed 's/,/\\n/g') + echo "failed_list=$FAILED_LIST" >> $GITHUB_OUTPUT + else + echo "has_failures=false" >> $GITHUB_OUTPUT + echo "fail_count=0" >> $GITHUB_OUTPUT + echo "failed_list=" >> $GITHUB_OUTPUT + fi + + - name: Send failure notification to Teams + if: always() && steps.failed_tests.outputs.has_failures == 'true' + uses: Skitionek/notify-microsoft-teams@v1.0.8 + with: + webhook_url: ${{ secrets.MS_TEAMS_WEBHOOK_URL_INTEGRATION_TESTS }} + raw: > + { + "type": "message", + "attachments": [ + { + "contentType": "application/vnd.microsoft.card.adaptive", + "content": { + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "type": "AdaptiveCard", + "version": "1.4", + "msteams": { + "width": "Full" + }, + "body": [ + { + "type": "TextBlock", + "text": "Integration Tests Failed", + "weight": "Bolder", + "size": "Large", + "color": "Attention" + }, + { + "type": "FactSet", + "facts": [ + { "title": "Repository:", "value": "${{ github.repository }}" }, + { "title": "Author:", "value": "${{ github.actor }}" }, + { "title": "Branch:", "value": "${{ github.head_ref }}" }, + { "title": "PR:", "value": "#${{ github.event.pull_request.number }}" }, + { "title": "Failed Tests:", "value": "${{ steps.failed_tests.outputs.fail_count }}" } + ] + }, + { + "type": "TextBlock", + "text": "**Failed Test Cases:**", + "weight": "Bolder", + "spacing": "Medium" + }, + { + "type": "TextBlock", + "text": "${{ steps.failed_tests.outputs.failed_list }}", + "wrap": true, + "fontType": "Monospace", + "spacing": "Small" + } + ], + "actions": [ + { + "type": "Action.OpenUrl", + "title": "View Workflow", + "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + }, + { + "type": "Action.OpenUrl", + "title": "View PR", + "url": "${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.pull_request.number }}" + } + ] + } + } + ] + } + - name: Coverage report uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4 with: @@ -118,6 +205,7 @@ jobs: echo "Your code coverage test passed! Coverage precentage is: $CODE_COV" exit 0 fi + lint: name: lint runs-on: ubuntu-latest diff --git a/internal/commands/.scripts/integration_up.sh b/internal/commands/.scripts/integration_up.sh index 62708467b..d5389bdd8 100755 --- a/internal/commands/.scripts/integration_up.sh +++ b/internal/commands/.scripts/integration_up.sh @@ -14,6 +14,7 @@ rm -rf ScaResolver-linux64.tar.gz # Step 1: Check if the failedTests file exists FAILED_TESTS_FILE="failedTests" +rerun_status=0 # Step 2: Create the failedTests file echo "Creating $FAILED_TESTS_FILE..." @@ -83,7 +84,27 @@ fi echo "Running cleandata to clean up projects..." go test -v github.com/checkmarx/ast-cli/test/cleandata -# Step 8: Final cleanup and exit +# Step 8: Generate failed tests summary for CI/CD consumption +FINAL_FAILED_FILE="failed_tests_summary.txt" +if [ -s "$FAILED_TESTS_FILE" ] && [ $rerun_status -eq 1 ]; then + cp "$FAILED_TESTS_FILE" "$FINAL_FAILED_FILE" + + echo "" + echo "========================================================" + echo " FAILED INTEGRATION TESTS SUMMARY" + echo "========================================================" + echo "The following tests failed after retry:" + echo "--------------------------------------------------------" + while IFS= read -r testName; do + echo " - $testName" + done < "$FINAL_FAILED_FILE" + echo "--------------------------------------------------------" + echo "Total failed tests: $(wc -l < "$FINAL_FAILED_FILE" | tr -d ' ')" + echo "========================================================" + echo "" +fi + +# Step 9: Final cleanup and exit rm -f "$FAILED_TESTS_FILE" test_output.log if [ $status -ne 0 ] || [ $rerun_status -eq 1 ]; then