@@ -3,8 +3,8 @@ name: CodeQL
33on :
44 workflow_dispatch :
55 schedule :
6- # Run at the end of every Monday
7- - cron : ' 0 0 * * 1'
6+ # Run at the end of every day from Monday to Friday
7+ - cron : ' 0 0 * * 1-5 '
88
99jobs :
1010 analyze :
6868 uses : github/codeql-action/analyze@60168efe1c415ce0f5521ea06d5c2062adbeed1b # v3
6969 with :
7070 category : ' /language:${{matrix.config.language}}'
71+ output : sarif-output-${{ matrix.config.language }}.sarif
72+ - name : Filter SARIF Results
73+ run : |
74+ REPO_URL="https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/"
75+ jq --arg baseUrl "$REPO_URL" '[.runs[].results[] |
76+ {
77+ ruleId: .ruleId,
78+ message: .message.text,
79+ url: "\($baseUrl)\(.locations[0].physicalLocation.artifactLocation.uri)#L\(.locations[0].physicalLocation.region.startLine)\(if .locations[0].physicalLocation.region.endLine != null then "-L\(.locations[0].physicalLocation.region.endLine)" else "" end)"
80+ }]' sarif-output-${{ matrix.config.language }}.sarif/${{ matrix.config.language }}.sarif > filtered-${{ matrix.config.language }}.json
81+ - name : Display Filtered Results
82+ run : cat filtered-${{ matrix.config.language }}.json
83+ - name : Send Slack Notification
84+ env :
85+ SEC_BOT_SLACK_WEBHOOK : ${{ secrets.SEC_BOT_SLACK_WEBHOOK }}
86+ CHANNEL : " #a-new-private-channel-in-this-slack-org-for-kyle-and-feroz-to-test-some-security"
87+ run : |
88+ jq -c '.[]' filtered-${{ matrix.config.language }}.json | while read -r item; do
89+ RULE_ID=$(echo "$item" | jq -r '.ruleId')
90+ MESSAGE=$(echo "$item" | jq -r '.message')
91+ URL=$(echo "$item" | jq -r '.url')
92+
93+ PAYLOAD=$(cat <<EOF
94+ {
95+ "channel": "$CHANNEL",
96+ "blocks": [
97+ {
98+ "type": "header",
99+ "text": {
100+ "type": "plain_text",
101+ "text": "🚨 CodeQL Alert for ${{ matrix.config.language }} 🚨",
102+ "emoji": true
103+ }
104+ },
105+ {
106+ "type": "section",
107+ "text": {
108+ "type": "mrkdwn",
109+ "text": "*Rule:* $RULE_ID"
110+ }
111+ },
112+ {
113+ "type": "section",
114+ "text": {
115+ "type": "mrkdwn",
116+ "text": "*Message:* $MESSAGE"
117+ }
118+ },
119+ {
120+ "type": "section",
121+ "text": {
122+ "type": "mrkdwn",
123+ "text": "*File:* $URL"
124+ }
125+ }
126+ ]
127+ }
128+ EOF
129+ )
130+
131+ curl -X POST -H "Authorization: Bearer $SEC_BOT_SLACK_WEBHOOK" \
132+ -H "Content-type: application/json" \
133+ --data-raw "$PAYLOAD" https://slack.com/api/chat.postMessage
134+ done
0 commit comments