Skip to content

Commit

Permalink
Update security-monitoring.yml for CodeQL (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyli authored Sep 10, 2024
1 parent 3659d55 commit f5c8034
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/security-monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ jobs:
core.setOutput('dependabot_alert_status', activeDependabotAlerts.length > 0 ? '1': '0');
}
await checkAlerts();
check-code-scanning-alerts:
runs-on: ubuntu-latest
outputs:
code_scanning_alert_status: ${{ steps.check-code-scanning-alerts.outputs.code_scanning_alert_status }}
steps:
- name: Check for security alerts
id: check-code-scanning-alerts
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ secrets.GH_PAT }}
script: |
async function checkAlerts() {
const owner = '${{ github.repository_owner }}';
const repo = '${{ github.event.repository.name }}';
const ref = 'refs/heads/main';
const codeScanningAlerts = await github.rest.codeScanning.listAlertsForRepo({
owner,
repo,
ref: ref
});
const activeCodeScanningAlerts = codeScanningAlerts.data.filter(alert => alert.state === 'open');
core.setOutput('code_scanning_alert_status', activeCodeScanningAlerts.length > 0 ? '1': '0');
}
await checkAlerts();
put-metric-data:
runs-on: ubuntu-latest
needs: [check-dependabot-alerts]
Expand All @@ -54,3 +81,10 @@ jobs:
else
aws cloudwatch put-metric-data --metric-name DependabotAlert --namespace SecurityMonitoringMetrics --value 0 --unit Count --dimensions ProjectName=sagemaker-hyperpod-cli
fi
- name: Put Code Scanning Alert Metric Data
run: |
if [ "${{ needs.check-code-scanning-alerts.outputs.code_scanning_alert_status }}" == "1" ]; then
aws cloudwatch put-metric-data --metric-name CodeScanningAlert --namespace SecurityMonitoringMetrics --value 1 --unit Count --dimensions ProjectName=sagemaker-hyperpod-cli
else
aws cloudwatch put-metric-data --metric-name CodeScanningAlert --namespace SecurityMonitoringMetrics --value 0 --unit Count --dimensions ProjectName=sagemaker-hyperpod-cli
fi

0 comments on commit f5c8034

Please sign in to comment.