-
Notifications
You must be signed in to change notification settings - Fork 14
ci(ipa): automatic warning-level violation detection #905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
2941b14
0755b8f
3fc2a28
5afdba8
0adaa42
85158b2
31a11b5
b5bc24e
3442793
953977c
3406dbe
aaa2202
1697e77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/bin/bash | ||
set -eou pipefail | ||
|
||
WARNING_COUNT=$1 | ||
TEAM_ID=$2 | ||
JIRA_API_TOKEN=$3 | ||
SLACK_BEARER_TOKEN=$4 | ||
SLACK_CHANNEL_ID=$5 | ||
ONCALL_USER=$6 | ||
DRY_RUN=${7:-false} # Optional 7th parameter for dry run | ||
|
||
if [ "$WARNING_COUNT" -eq 0 ]; then | ||
echo "No warning violations found, skipping ticket creation" | ||
exit 0 | ||
fi | ||
|
||
# Read violation details if available | ||
VIOLATION_DETAILS="" | ||
if [ -f "tools/spectral/ipa/metrics/outputs/warning-violations.json" ]; then | ||
VIOLATION_DETAILS=$(jq -r ' | ||
group_by(.code) | | ||
map("• " + .[0].code + " (" + (length | tostring) + " violations)") | | ||
join("\n") | ||
' tools/spectral/ipa/metrics/outputs/warning-violations.json) | ||
fi | ||
|
||
if [ "$DRY_RUN" = "true" ]; then | ||
echo "=== DRY RUN MODE ===" | ||
echo "Would create Jira ticket with:" | ||
echo "Summary: Warning-level IPA violations found" | ||
echo "Description:" | ||
echo "Warning-level violations were found during IPA validation. Please review and add exceptions if valid, or address false positives. | ||
Violation Summary: | ||
$VIOLATION_DETAILS | ||
Total violations: $WARNING_COUNT" | ||
echo "" | ||
echo "Would send Slack message:" | ||
SLACK_SUMMARY=$(echo "$VIOLATION_DETAILS" | head -3) | ||
if [ "$(echo "$VIOLATION_DETAILS" | wc -l)" -gt 3 ]; then | ||
SLACK_SUMMARY="$SLACK_SUMMARY\n... and more" | ||
fi | ||
echo "Warning-level IPA violations found ($WARNING_COUNT violations) ($ONCALL_USER). | ||
Jira ticket: [DRY RUN - no ticket created]" | ||
exit 0 | ||
fi | ||
|
||
# Check if warning ticket already exists | ||
EXISTING_TICKET=$(curl -s -H "Authorization: Bearer $JIRA_API_TOKEN" \ | ||
"https://jira.mongodb.org/rest/api/2/search?jql=project=CLOUDP AND summary~'Warning-level IPA violations' AND status!=Done" \ | ||
| jq -r '.issues[0].key // empty') | ||
|
||
if [ -n "$EXISTING_TICKET" ]; then | ||
echo "Warning ticket already exists: $EXISTING_TICKET" | ||
exit 0 | ||
fi | ||
|
||
# Create detailed description | ||
DESCRIPTION="Warning-level violations were found during IPA validation. Please review and add exceptions if valid, or address false positives. | ||
Violation Summary: | ||
$VIOLATION_DETAILS | ||
Total violations: $WARNING_COUNT" | ||
|
||
# Create new Jira ticket | ||
TICKET_RESPONSE=$(curl -s -X POST -H "Authorization: Bearer $JIRA_API_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{ | ||
\"fields\": { | ||
\"project\": {\"key\": \"CLOUDP\"}, | ||
\"summary\": \"Warning-level IPA violations found\", | ||
\"description\": \"$DESCRIPTION\", | ||
\"issuetype\": {\"name\": \"Task\"}, | ||
\"assignee\": {\"id\": \"$TEAM_ID\"} | ||
} | ||
}" \ | ||
"https://jira.mongodb.org/rest/api/2/issue/") | ||
|
||
TICKET_KEY=$(echo "$TICKET_RESPONSE" | jq -r '.key') | ||
|
||
if [ "$TICKET_KEY" != "null" ]; then | ||
echo "Created Jira ticket: $TICKET_KEY" | ||
|
||
# Create summary for Slack | ||
SLACK_SUMMARY="" | ||
if [ -n "$VIOLATION_DETAILS" ]; then | ||
SLACK_SUMMARY=$(echo "$VIOLATION_DETAILS" | head -3) | ||
if [ "$(echo "$VIOLATION_DETAILS" | wc -l)" -gt 3 ]; then | ||
SLACK_SUMMARY="$SLACK_SUMMARY\n... and more" | ||
fi | ||
fi | ||
|
||
# Send Slack notification with violation summary | ||
SLACK_MESSAGE="Warning-level IPA violations found ($WARNING_COUNT violations) ($ONCALL_USER). | ||
Jira ticket: https://jira.mongodb.org/browse/$TICKET_KEY" | ||
|
||
curl -X POST -H "Authorization: Bearer $SLACK_BEARER_TOKEN" \ | ||
-H "Content-type: application/json" \ | ||
--data "{\"channel\":\"$SLACK_CHANNEL_ID\",\"text\":\"$SLACK_MESSAGE\"}" \ | ||
https://slack.com/api/chat.postMessage | ||
else | ||
echo "Failed to create Jira ticket" | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,16 @@ jobs: | |
working-directory: ${{ github.workspace }} | ||
|
||
- name: Run Metric Collection Job | ||
id: metric-collection | ||
working-directory: tools/spectral/ipa/metrics/scripts | ||
run: node runMetricCollection.js "${{ github.workspace }}/v2.json" | ||
run: | | ||
node runMetricCollection.js "${{ github.workspace }}/v2.json" | ||
if [ -f "../outputs/warning-count.txt" ]; then | ||
warning_count=$(cat "../outputs/warning-count.txt") | ||
echo "warning_count=${warning_count}" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "warning_count=0" >> "$GITHUB_OUTPUT" | ||
fi | ||
|
||
- name: aws configure | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
|
@@ -54,6 +62,19 @@ jobs: | |
working-directory: tools/spectral/ipa/metrics/scripts | ||
run: node dataDump.js | ||
|
||
- name: Handle Warning Violations | ||
if: ${{ steps.metric-collection.outputs.warning_count > 0 }} | ||
env: | ||
WARNING_COUNT: ${{ steps.metric-collection.outputs.warning_count }} | ||
TEAM_ID: ${{ vars.JIRA_TEAM_ID_APIX_PLATFORM }} | ||
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | ||
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }} | ||
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_PLATFORM_DEV }} | ||
SLACK_ONCALL_USER: ${{ secrets.SLACK_APIX_PLATFORM_ONCALL_USER }} | ||
run: | | ||
chmod +x .github/scripts/handle_warning_violations.sh | ||
.github/scripts/handle_warning_violations.sh "$WARNING_COUNT" "$TEAM_ID" "$JIRA_API_TOKEN" "$SLACK_BEARER_TOKEN" "$SLACK_CHANNEL_ID" "$SLACK_ONCALL_USER" | ||
|
||
|
||
failure-handler: | ||
name: Failure Handler | ||
needs: [ release-IPA-metrics ] | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can link to the IPA wiki with the rollout process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added! Let me know how it sounds