Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
23 changes: 22 additions & 1 deletion internal/commands/.scripts/integration_up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down Expand Up @@ -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
Expand Down
Loading